Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 1 | #Topic Paint |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 2 | #Alias Paint_Reference ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame^] | 4 | #PhraseDef paint_font_metrics |
| 5 | Typeface, Paint_Text_Size, Paint_Text_Scale_X, |
| 6 | Paint_Text_Skew_X, Paint_Text_Align, Paint_Hinting, Anti_Alias, Paint_Fake_Bold, |
| 7 | Font_Embedded_Bitmaps, Full_Hinting_Spacing, LCD_Text, Linear_Text, |
| 8 | and Subpixel_Text |
| 9 | ## |
| 10 | |
Cary Clark | e4aa371 | 2017-09-15 02:56:12 -0400 | [diff] [blame] | 11 | #Class SkPaint |
| 12 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame^] | 13 | #Code |
| 14 | #Populate |
| 15 | ## |
| 16 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 17 | Paint controls options applied when drawing and measuring. Paint collects all |
| 18 | options outside of the Canvas_Clip and Canvas_Matrix. |
| 19 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 20 | Various options apply to text, strokes and fills, and images. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 21 | |
| 22 | Some options may not be implemented on all platforms; in these cases, setting |
| 23 | the option has no effect. Some options are conveniences that duplicate Canvas |
| 24 | functionality; for instance, text size is identical to matrix scale. |
| 25 | |
| 26 | Paint options are rarely exclusive; each option modifies a stage of the drawing |
| 27 | pipeline and multiple pipeline stages may be affected by a single Paint. |
| 28 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 29 | Paint collects effects and filters that describe single-pass and multiple-pass |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 30 | algorithms that alter the drawing geometry, color, and transparency. For instance, |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 31 | Paint does not directly implement dashing or blur, but contains the objects that do so. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 32 | |
| 33 | The objects contained by Paint are opaque, and cannot be edited outside of the Paint |
| 34 | to affect it. The implementation is free to defer computations associated with the |
| 35 | Paint, or ignore them altogether. For instance, some GPU implementations draw all |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 36 | Path geometries with Anti_Aliasing, regardless of how SkPaint::kAntiAlias_Flag |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 37 | is set in Paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 38 | |
| 39 | Paint describes a single color, a single font, a single image quality, and so on. |
| 40 | Multiple colors are drawn either by using multiple paints or with objects like |
| 41 | Shader attached to Paint. |
| 42 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 43 | #Subtopic Initializers |
| 44 | #Line # constructors and initialization ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 45 | |
| 46 | #Method SkPaint() |
| 47 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 48 | #In Initializers |
| 49 | #Line # constructs with default values ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 50 | Constructs Paint with default values. |
| 51 | |
| 52 | #Table |
| 53 | #Legend |
| 54 | # attribute # default value ## |
| 55 | #Legend ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 56 | # Anti_Alias # false ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 57 | # Blend_Mode # SkBlendMode::kSrcOver ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 58 | # Color # SK_ColorBLACK ## |
| 59 | # Color_Alpha # 255 ## |
| 60 | # Color_Filter # nullptr ## |
| 61 | # Dither # false ## |
| 62 | # Draw_Looper # nullptr ## |
| 63 | # Fake_Bold # false ## |
| 64 | # Filter_Quality # kNone_SkFilterQuality ## |
| 65 | # Font_Embedded_Bitmaps # false ## |
| 66 | # Automatic_Hinting # false ## |
| 67 | # Full_Hinting_Spacing # false ## |
| 68 | # Hinting # kNormal_Hinting ## |
| 69 | # Image_Filter # nullptr ## |
| 70 | # LCD_Text # false ## |
| 71 | # Linear_Text # false ## |
| 72 | # Miter_Limit # 4 ## |
| 73 | # Mask_Filter # nullptr ## |
| 74 | # Path_Effect # nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 75 | # Shader # nullptr ## |
| 76 | # Style # kFill_Style ## |
| 77 | # Text_Align # kLeft_Align ## |
| 78 | # Text_Encoding # kUTF8_TextEncoding ## |
| 79 | # Text_Scale_X # 1 ## |
| 80 | # Text_Size # 12 ## |
| 81 | # Text_Skew_X # 0 ## |
| 82 | # Typeface # nullptr ## |
| 83 | # Stroke_Cap # kButt_Cap ## |
| 84 | # Stroke_Join # kMiter_Join ## |
| 85 | # Stroke_Width # 0 ## |
| 86 | # Subpixel_Text # false ## |
| 87 | # Vertical_Text # false ## |
| 88 | #Table ## |
| 89 | |
| 90 | The flags, text size, hinting, and miter limit may be overridden at compile time by defining |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 91 | paint default values. The overrides may be included in "SkUserConfig.h" or predefined by the |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 92 | build system. |
| 93 | |
| 94 | #Return default initialized Paint ## |
| 95 | |
| 96 | #Example |
| 97 | #ToDo mark this as no output ## |
| 98 | #Height 1 |
| 99 | ###$ $ redefine markup character so preprocessor commands appear normally |
| 100 | #ifndef SkUserConfig_DEFINED |
| 101 | #define SkUserConfig_DEFINED |
| 102 | |
| 103 | #define SkPaintDefaults_Flags 0x01 // always enable antialiasing |
| 104 | #define SkPaintDefaults_TextSize 24.f // double default font size |
| 105 | #define SkPaintDefaults_Hinting 3 // use full hinting |
| 106 | #define SkPaintDefaults_MiterLimit 10.f // use HTML Canvas miter limit setting |
| 107 | |
| 108 | #endif |
| 109 | $$$# # restore original markup character |
| 110 | ## |
| 111 | |
| 112 | |
| 113 | ## |
| 114 | |
| 115 | #Method SkPaint(const SkPaint& paint) |
| 116 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 117 | #In Initializers |
| 118 | #Line # makes a shallow copy ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 119 | Makes a shallow copy of Paint. Typeface, Path_Effect, Shader, |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 120 | Mask_Filter, Color_Filter, Draw_Looper, and Image_Filter are shared |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 121 | between the original paint and the copy. Objects containing Reference_Count increment |
| 122 | their references by one. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 123 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 124 | The referenced objects Path_Effect, Shader, Mask_Filter, Color_Filter, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 125 | Draw_Looper, and Image_Filter cannot be modified after they are created. |
| 126 | This prevents objects with Reference_Count from being modified once Paint refers to them. |
| 127 | |
| 128 | #Param paint original to copy ## |
| 129 | |
| 130 | #Return shallow copy of paint ## |
| 131 | |
| 132 | #Example |
| 133 | #ToDo why is this double-spaced on Fiddle? ## |
| 134 | SkPaint paint1; |
| 135 | paint1.setColor(SK_ColorRED); |
| 136 | SkPaint paint2(paint1); |
| 137 | paint2.setColor(SK_ColorBLUE); |
| 138 | SkDebugf("SK_ColorRED %c= paint1.getColor()\n", SK_ColorRED == paint1.getColor() ? '=' : '!'); |
| 139 | SkDebugf("SK_ColorBLUE %c= paint2.getColor()\n", SK_ColorBLUE == paint2.getColor() ? '=' : '!'); |
| 140 | |
| 141 | #StdOut |
| 142 | SK_ColorRED == paint1.getColor() |
| 143 | SK_ColorBLUE == paint2.getColor() |
| 144 | ## |
| 145 | ## |
| 146 | |
| 147 | ## |
| 148 | |
| 149 | #Method SkPaint(SkPaint&& paint) |
| 150 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 151 | #In Initializers |
| 152 | #Line # moves paint without copying it ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 153 | Implements a move constructor to avoid increasing the reference counts |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 154 | of objects referenced by the paint. |
| 155 | |
| 156 | After the call, paint is undefined, and can be safely destructed. |
| 157 | |
| 158 | #Param paint original to move ## |
| 159 | |
| 160 | #Return content of paint ## |
| 161 | |
| 162 | #Example |
| 163 | SkPaint paint; |
| 164 | float intervals[] = { 5, 5 }; |
| 165 | paint.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 2.5f)); |
| 166 | SkPaint dashed(std::move(paint)); |
| 167 | SkDebugf("path effect unique: %s\n", dashed.getPathEffect()->unique() ? "true" : "false"); |
| 168 | |
| 169 | #StdOut |
| 170 | path effect unique: true |
| 171 | ## |
| 172 | ## |
| 173 | |
| 174 | ## |
| 175 | |
| 176 | # ------------------------------------------------------------------------------ |
| 177 | |
| 178 | #Method void reset() |
| 179 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 180 | #In Initializers |
| 181 | #Line # sets to default values ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 182 | Sets all Paint contents to their initial values. This is equivalent to replacing |
| 183 | Paint with the result of SkPaint(). |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 184 | |
| 185 | #Example |
| 186 | SkPaint paint1, paint2; |
| 187 | paint1.setColor(SK_ColorRED); |
| 188 | paint1.reset(); |
| 189 | SkDebugf("paint1 %c= paint2", paint1 == paint2 ? '=' : '!'); |
| 190 | |
| 191 | #StdOut |
| 192 | paint1 == paint2 |
| 193 | ## |
| 194 | ## |
| 195 | |
| 196 | ## |
| 197 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 198 | #Subtopic Initializers ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 199 | |
| 200 | # ------------------------------------------------------------------------------ |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 201 | |
| 202 | #Method ~SkPaint() |
| 203 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 204 | #Line # decreases Reference_Count of owned objects ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 205 | Decreases Paint Reference_Count of owned objects: Typeface, Path_Effect, Shader, |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 206 | Mask_Filter, Color_Filter, Draw_Looper, and Image_Filter. If the |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 207 | objects containing Reference_Count go to zero, they are deleted. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 208 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 209 | #NoExample |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 210 | ## |
| 211 | |
| 212 | ## |
| 213 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 214 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 215 | # ------------------------------------------------------------------------------ |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame^] | 216 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 217 | #Subtopic Management |
| 218 | #Line # paint copying, moving, comparing ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 219 | |
| 220 | #Method SkPaint& operator=(const SkPaint& paint) |
| 221 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 222 | #In Management |
| 223 | #Line # makes a shallow copy ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 224 | Makes a shallow copy of Paint. Typeface, Path_Effect, Shader, |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 225 | Mask_Filter, Color_Filter, Draw_Looper, and Image_Filter are shared |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 226 | between the original paint and the copy. Objects containing Reference_Count in the |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 227 | prior destination are decreased by one, and the referenced objects are deleted if the |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 228 | resulting count is zero. Objects containing Reference_Count in the parameter paint |
| 229 | are increased by one. paint is unmodified. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 230 | |
| 231 | #Param paint original to copy ## |
| 232 | |
| 233 | #Return content of paint ## |
| 234 | |
| 235 | #Example |
| 236 | SkPaint paint1, paint2; |
| 237 | paint1.setColor(SK_ColorRED); |
| 238 | paint2 = paint1; |
| 239 | SkDebugf("SK_ColorRED %c= paint1.getColor()\n", SK_ColorRED == paint1.getColor() ? '=' : '!'); |
| 240 | SkDebugf("SK_ColorRED %c= paint2.getColor()\n", SK_ColorRED == paint2.getColor() ? '=' : '!'); |
| 241 | |
| 242 | #StdOut |
| 243 | SK_ColorRED == paint1.getColor() |
| 244 | SK_ColorRED == paint2.getColor() |
| 245 | ## |
| 246 | ## |
| 247 | |
| 248 | ## |
| 249 | |
| 250 | # ------------------------------------------------------------------------------ |
| 251 | |
| 252 | #Method SkPaint& operator=(SkPaint&& paint) |
| 253 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 254 | #In Management |
| 255 | #Line # moves paint without copying it ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 256 | Moves the paint to avoid increasing the reference counts |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 257 | of objects referenced by the paint parameter. Objects containing Reference_Count in the |
| 258 | prior destination are decreased by one; those objects are deleted if the resulting count |
| 259 | is zero. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 260 | |
| 261 | After the call, paint is undefined, and can be safely destructed. |
| 262 | |
| 263 | #Param paint original to move ## |
| 264 | |
| 265 | #Return content of paint ## |
| 266 | |
| 267 | #Example |
| 268 | SkPaint paint1, paint2; |
| 269 | paint1.setColor(SK_ColorRED); |
| 270 | paint2 = std::move(paint1); |
| 271 | SkDebugf("SK_ColorRED == paint2.getColor()\n", SK_ColorRED == paint2.getColor() ? '=' : '!'); |
| 272 | |
| 273 | #StdOut |
| 274 | SK_ColorRED == paint2.getColor() |
| 275 | ## |
| 276 | ## |
| 277 | |
| 278 | ## |
| 279 | |
| 280 | # ------------------------------------------------------------------------------ |
| 281 | |
| 282 | #Method bool operator==(const SkPaint& a, const SkPaint& b) |
| 283 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 284 | #In Management |
| 285 | #Line # compares paints for equality ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 286 | Compares a and b, and returns true if a and b are equivalent. May return false |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 287 | if Typeface, Path_Effect, Shader, Mask_Filter, Color_Filter, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 288 | Draw_Looper, or Image_Filter have identical contents but different pointers. |
| 289 | |
| 290 | #Param a Paint to compare ## |
| 291 | #Param b Paint to compare ## |
| 292 | |
| 293 | #Return true if Paint pair are equivalent ## |
| 294 | |
| 295 | #Example |
| 296 | SkPaint paint1, paint2; |
| 297 | paint1.setColor(SK_ColorRED); |
| 298 | paint2.setColor(0xFFFF0000); |
| 299 | SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); |
| 300 | float intervals[] = { 5, 5 }; |
| 301 | paint1.setPathEffect(SkDashPathEffect::Make(intervals, 2, 2.5f)); |
| 302 | paint2.setPathEffect(SkDashPathEffect::Make(intervals, 2, 2.5f)); |
| 303 | SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); |
| 304 | |
| 305 | #StdOut |
| 306 | paint1 == paint2 |
| 307 | paint1 != paint2 |
| 308 | ## |
| 309 | ## |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 310 | #SeeAlso operator!=(const SkPaint& a, const SkPaint& b) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 311 | ## |
| 312 | |
| 313 | # ------------------------------------------------------------------------------ |
| 314 | |
| 315 | #Method bool operator!=(const SkPaint& a, const SkPaint& b) |
| 316 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 317 | #In Management |
| 318 | #Line # compares paints for inequality ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 319 | Compares a and b, and returns true if a and b are not equivalent. May return true |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 320 | if Typeface, Path_Effect, Shader, Mask_Filter, Color_Filter, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 321 | Draw_Looper, or Image_Filter have identical contents but different pointers. |
| 322 | |
| 323 | #Param a Paint to compare ## |
| 324 | #Param b Paint to compare ## |
| 325 | |
| 326 | #Return true if Paint pair are not equivalent ## |
| 327 | |
| 328 | #Example |
| 329 | SkPaint paint1, paint2; |
| 330 | paint1.setColor(SK_ColorRED); |
| 331 | paint2.setColor(0xFFFF0000); |
| 332 | SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); |
| 333 | SkDebugf("paint1 %c= paint2\n", paint1 != paint2 ? '!' : '='); |
| 334 | |
| 335 | #StdOut |
| 336 | paint1 == paint2 |
| 337 | paint1 == paint2 |
| 338 | ## |
| 339 | ## |
Cary Clark | 06c20f3 | 2018-03-20 15:53:27 -0400 | [diff] [blame] | 340 | #SeeAlso operator==(const SkPaint& a, const SkPaint& b) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 341 | ## |
| 342 | |
| 343 | # ------------------------------------------------------------------------------ |
| 344 | |
| 345 | #Method uint32_t getHash() const |
| 346 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 347 | #In Management |
| 348 | #Line # returns a shallow hash for equality checks ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 349 | Returns a hash generated from Paint values and pointers. |
| 350 | Identical hashes guarantee that the paints are |
| 351 | equivalent, but differing hashes do not guarantee that the paints have differing |
| 352 | contents. |
| 353 | |
| 354 | If operator==(const SkPaint& a, const SkPaint& b) returns true for two paints, |
| 355 | their hashes are also equal. |
| 356 | |
| 357 | The hash returned is platform and implementation specific. |
| 358 | |
| 359 | #Return a shallow hash ## |
| 360 | |
| 361 | #Example |
| 362 | SkPaint paint1, paint2; |
| 363 | paint1.setColor(SK_ColorRED); |
| 364 | paint2.setColor(0xFFFF0000); |
| 365 | SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); |
| 366 | SkDebugf("paint1.getHash() %c= paint2.getHash()\n", |
| 367 | paint1.getHash() == paint2.getHash() ? '=' : '!'); |
| 368 | |
| 369 | #StdOut |
| 370 | paint1 == paint2 |
| 371 | paint1.getHash() == paint2.getHash() |
| 372 | ## |
| 373 | ## |
| 374 | |
| 375 | ## |
| 376 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 377 | #Subtopic Management ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 378 | |
| 379 | # ------------------------------------------------------------------------------ |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame^] | 380 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 381 | #Subtopic Hinting |
| 382 | #Line # glyph outline adjustment ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 383 | |
| 384 | #Enum Hinting |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 385 | #Line # level of glyph outline adjustment ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 386 | |
| 387 | #Code |
| 388 | enum Hinting { |
| 389 | kNo_Hinting = 0, |
| 390 | kSlight_Hinting = 1, |
| 391 | kNormal_Hinting = 2, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 392 | kFull_Hinting = 3, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 393 | }; |
| 394 | ## |
| 395 | |
| 396 | Hinting adjusts the glyph outlines so that the shape provides a uniform |
| 397 | look at a given point size on font engines that support it. Hinting may have a |
| 398 | muted effect or no effect at all depending on the platform. |
| 399 | |
| 400 | The four levels roughly control corresponding features on platforms that use FreeType |
| 401 | as the Font_Engine. |
| 402 | |
| 403 | #Const kNo_Hinting 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 404 | #Line # glyph outlines unchanged ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 405 | Leaves glyph outlines unchanged from their native representation. |
| 406 | With FreeType, this is equivalent to the FT_LOAD_NO_HINTING |
| 407 | bit-field constant supplied to FT_Load_Glyph, which indicates that the vector |
| 408 | outline being loaded should not be fitted to the pixel grid but simply scaled |
| 409 | to 26.6 fractional pixels. |
| 410 | ## |
| 411 | #Const kSlight_Hinting 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 412 | #Line # minimal modification to improve constrast ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 413 | Modifies glyph outlines minimally to improve constrast. |
| 414 | With FreeType, this is equivalent in spirit to the |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 415 | FT_LOAD_TARGET_LIGHT value supplied to FT_Load_Glyph. It chooses a |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 416 | lighter hinting algorithm for non-monochrome modes. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 417 | Generated Glyphs may be fuzzy but better resemble their original shape. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 418 | ## |
| 419 | #Const kNormal_Hinting 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 420 | #Line # glyph outlines modified to improve constrast ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 421 | Modifies glyph outlines to improve constrast. This is the default. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 422 | With FreeType, this supplies FT_LOAD_TARGET_NORMAL to FT_Load_Glyph, |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 423 | choosing the default hinting algorithm, which is optimized for standard |
| 424 | gray-level rendering. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 425 | ## |
| 426 | #Const kFull_Hinting 3 |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 427 | #Line # modifies glyph outlines for maximum constrast ## |
| 428 | Modifies glyph outlines for maximum constrast. With FreeType, this selects |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 429 | FT_LOAD_TARGET_LCD or FT_LOAD_TARGET_LCD_V if kLCDRenderText_Flag is set. |
| 430 | FT_LOAD_TARGET_LCD is a variant of FT_LOAD_TARGET_NORMAL optimized for |
| 431 | horizontally decimated LCD displays; FT_LOAD_TARGET_LCD_V is a |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 432 | variant of FT_LOAD_TARGET_NORMAL optimized for vertically decimated LCD displays. |
| 433 | ## |
| 434 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 435 | #Bug 915 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 436 | On OS_X and iOS, hinting controls whether Core_Graphics dilates the font outlines |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 437 | to account for LCD text. No hinting uses Core_Text Grayscale output. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 438 | Normal hinting uses Core_Text LCD output. If kLCDRenderText_Flag is clear, |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 439 | the LCD output is reduced to a single Grayscale channel. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 440 | |
| 441 | On Windows with DirectWrite, Hinting has no effect. |
| 442 | |
| 443 | Hinting defaults to kNormal_Hinting. |
| 444 | Set SkPaintDefaults_Hinting at compile time to change the default setting. |
| 445 | |
| 446 | #ToDo add an illustration? linux running GM:typefacerendering is best for this |
| 447 | the hinting variations are every other character horizontally |
| 448 | #ToDo ## |
| 449 | |
| 450 | #Enum ## |
| 451 | |
| 452 | #Method Hinting getHinting() const |
| 453 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 454 | #In Hinting |
| 455 | #Line # returns Hinting, glyph outline adjustment level ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 456 | Returns level of glyph outline adjustment. |
| 457 | |
| 458 | #Return one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting ## |
| 459 | |
| 460 | #Example |
| 461 | SkPaint paint; |
| 462 | SkDebugf("SkPaint::kNormal_Hinting %c= paint.getHinting()\n", |
| 463 | SkPaint::kNormal_Hinting == paint.getHinting() ? '=' : ':'); |
| 464 | |
| 465 | #StdOut |
| 466 | SkPaint::kNormal_Hinting == paint.getHinting() |
| 467 | ## |
| 468 | ## |
| 469 | ## |
| 470 | |
| 471 | #Method void setHinting(Hinting hintingLevel) |
| 472 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 473 | #In Hinting |
| 474 | #Line # sets Hinting, glyph outline adjustment level ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 475 | Sets level of glyph outline adjustment. |
| 476 | Does not check for valid values of hintingLevel. |
| 477 | |
| 478 | #Table |
| 479 | #Legend |
| 480 | # Hinting # value # effect on generated glyph outlines ## |
| 481 | ## |
| 482 | # kNo_Hinting # 0 # leaves glyph outlines unchanged from their native representation ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 483 | # kSlight_Hinting # 1 # modifies glyph outlines minimally to improve contrast ## |
| 484 | # kNormal_Hinting # 2 # modifies glyph outlines to improve contrast ## |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 485 | # kFull_Hinting # 3 # modifies glyph outlines for maximum contrast ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 486 | ## |
| 487 | |
| 488 | #Param hintingLevel one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting ## |
| 489 | |
| 490 | #Example |
| 491 | SkPaint paint1, paint2; |
| 492 | paint2.setHinting(SkPaint::kNormal_Hinting); |
| 493 | SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : ':'); |
| 494 | |
| 495 | #StdOut |
| 496 | paint1 == paint2 |
| 497 | ## |
| 498 | ## |
| 499 | ## |
| 500 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 501 | #Subtopic Hinting ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 502 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 503 | #Subtopic Flags |
| 504 | #Line # attributes represented by single bits ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 505 | |
| 506 | #Enum Flags |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 507 | #Line # values described by bits and masks ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 508 | |
| 509 | #Code |
| 510 | enum Flags { |
| 511 | kAntiAlias_Flag = 0x01, |
| 512 | kDither_Flag = 0x04, |
| 513 | kFakeBoldText_Flag = 0x20, |
| 514 | kLinearText_Flag = 0x40, |
| 515 | kSubpixelText_Flag = 0x80, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 516 | kLCDRenderText_Flag = 0x200, |
| 517 | kEmbeddedBitmapText_Flag = 0x400, |
| 518 | kAutoHinting_Flag = 0x800, |
| 519 | kVerticalText_Flag = 0x1000, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 520 | |
| 521 | kAllFlags = 0xFFFF, |
| 522 | }; |
| 523 | |
| 524 | ## |
| 525 | |
| 526 | The bit values stored in Flags. |
| 527 | The default value for Flags, normally zero, can be changed at compile time |
| 528 | with a custom definition of SkPaintDefaults_Flags. |
| 529 | All flags can be read and written explicitly; Flags allows manipulating |
| 530 | multiple settings at once. |
| 531 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 532 | #Const kAntiAlias_Flag 0x0001 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 533 | #Line # mask for setting Anti_Alias ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 534 | ## |
| 535 | #Const kDither_Flag 0x0004 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 536 | #Line # mask for setting Dither ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 537 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 538 | #Const kFakeBoldText_Flag 0x0020 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 539 | #Line # mask for setting Fake_Bold ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 540 | ## |
| 541 | #Const kLinearText_Flag 0x0040 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 542 | #Line # mask for setting Linear_Text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 543 | ## |
| 544 | #Const kSubpixelText_Flag 0x0080 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 545 | #Line # mask for setting Subpixel_Text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 546 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 547 | #Const kLCDRenderText_Flag 0x0200 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 548 | #Line # mask for setting LCD_Text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 549 | ## |
| 550 | #Const kEmbeddedBitmapText_Flag 0x0400 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 551 | #Line # mask for setting Font_Embedded_Bitmaps ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 552 | ## |
| 553 | #Const kAutoHinting_Flag 0x0800 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 554 | #Line # mask for setting Automatic_Hinting ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 555 | ## |
| 556 | #Const kVerticalText_Flag 0x1000 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 557 | #Line # mask for setting Vertical_Text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 558 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 559 | #Const kAllFlags 0xFFFF |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 560 | #Line # mask of all Flags ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 561 | mask of all Flags, including private flags and flags reserved for future use |
| 562 | ## |
| 563 | |
| 564 | Flags default to all flags clear, disabling the associated feature. |
| 565 | |
| 566 | #Enum ## |
| 567 | |
| 568 | #Enum ReserveFlags |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 569 | #Deprecated soon |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 570 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 571 | Only valid for Android framework. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 572 | |
| 573 | #Code |
| 574 | enum ReserveFlags { |
| 575 | kUnderlineText_ReserveFlag = 0x08, |
| 576 | kStrikeThruText_ReserveFlag = 0x10, |
| 577 | }; |
| 578 | ## |
| 579 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 580 | #Const kUnderlineText_ReserveFlag 0x0008 |
| 581 | #Deprecated soon |
| 582 | ## |
| 583 | #Const kStrikeThruText_ReserveFlag 0x0010 |
| 584 | #Deprecated soon |
| 585 | ## |
| 586 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 587 | |
| 588 | #Method uint32_t getFlags() const |
| 589 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 590 | #In Flags |
| 591 | #Line # returns Flags stored in a bit field ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 592 | Returns paint settings described by Flags. Each setting uses one |
| 593 | bit, and can be tested with Flags members. |
| 594 | |
| 595 | #Return zero, one, or more bits described by Flags ## |
| 596 | |
| 597 | #Example |
| 598 | SkPaint paint; |
| 599 | paint.setAntiAlias(true); |
| 600 | SkDebugf("(SkPaint::kAntiAlias_Flag & paint.getFlags()) %c= 0\n", |
| 601 | SkPaint::kAntiAlias_Flag & paint.getFlags() ? '!' : '='); |
| 602 | |
| 603 | #StdOut |
| 604 | (SkPaint::kAntiAlias_Flag & paint.getFlags()) != 0 |
| 605 | ## |
| 606 | ## |
| 607 | |
| 608 | ## |
| 609 | |
| 610 | #Method void setFlags(uint32_t flags) |
| 611 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 612 | #In Flags |
| 613 | #Line # sets multiple Flags in a bit field ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 614 | Replaces Flags with flags, the union of the Flags members. |
| 615 | All Flags members may be cleared, or one or more may be set. |
| 616 | |
| 617 | #Param flags union of Flags for Paint ## |
| 618 | |
| 619 | #Example |
| 620 | SkPaint paint; |
| 621 | paint.setFlags((uint32_t) (SkPaint::kAntiAlias_Flag | SkPaint::kDither_Flag)); |
| 622 | SkDebugf("paint.isAntiAlias()\n", paint.isAntiAlias() ? '!' : '='); |
| 623 | SkDebugf("paint.isDither()\n", paint.isDither() ? '!' : '='); |
| 624 | |
| 625 | #StdOut |
| 626 | paint.isAntiAlias() |
| 627 | paint.isDither() |
| 628 | ## |
| 629 | ## |
| 630 | |
| 631 | ## |
| 632 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 633 | #Subtopic Flags ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 634 | # ------------------------------------------------------------------------------ |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 635 | #Subtopic Anti_Alias |
| 636 | #Alias Anti_Alias |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 637 | #Substitute anti-alias |
| 638 | ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 639 | #Alias Anti_Aliased |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 640 | #Substitute anti-aliased |
| 641 | ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 642 | #Alias Anti_Aliasing |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 643 | #Substitute anti-aliasing |
| 644 | ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 645 | #In Related_Function |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 646 | #Line # approximating coverage with transparency ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 647 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 648 | Anti_Alias drawing approximates partial pixel coverage with transparency. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 649 | If kAntiAlias_Flag is clear, pixel centers contained by the shape edge are drawn opaque. |
| 650 | If kAntiAlias_Flag is set, pixels are drawn with Color_Alpha equal to their coverage. |
| 651 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 652 | The rule for Aliased pixels is inconsistent across platforms. A shape edge |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 653 | passing through the pixel center may, but is not required to, draw the pixel. |
| 654 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 655 | Raster_Engine draws Aliased pixels whose centers are on or to the right of the start of an |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 656 | active Path edge, and whose center is to the left of the end of the active Path edge. |
| 657 | |
| 658 | #ToDo add illustration of raster pixels ## |
| 659 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 660 | A platform may only support Anti_Aliased drawing. Some GPU-backed platforms use |
| 661 | Supersampling to Anti_Alias all drawing, and have no mechanism to selectively |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 662 | Alias. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 663 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 664 | The amount of coverage computed for Anti_Aliased pixels also varies across platforms. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 665 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 666 | Anti_Alias is disabled by default. |
| 667 | Anti_Alias can be enabled by default by setting SkPaintDefaults_Flags to kAntiAlias_Flag |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 668 | at compile time. |
| 669 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 670 | #Example |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 671 | #Width 512 |
| 672 | #Description |
| 673 | A red line is drawn with transparency on the edges to make it look smoother. |
| 674 | A blue line draws only where the pixel centers are contained. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 675 | The lines are drawn into Bitmap, then drawn magnified to make the |
| 676 | Aliasing easier to see. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 677 | ## |
| 678 | |
| 679 | void draw(SkCanvas* canvas) { |
| 680 | SkBitmap bitmap; |
| 681 | bitmap.allocN32Pixels(50, 50); |
| 682 | SkCanvas offscreen(bitmap); |
| 683 | SkPaint paint; |
| 684 | paint.setStyle(SkPaint::kStroke_Style); |
| 685 | paint.setStrokeWidth(10); |
| 686 | for (bool antialias : { false, true }) { |
| 687 | paint.setColor(antialias ? SK_ColorRED : SK_ColorBLUE); |
| 688 | paint.setAntiAlias(antialias); |
| 689 | bitmap.eraseColor(0); |
| 690 | offscreen.drawLine(5, 5, 15, 30, paint); |
| 691 | canvas->drawLine(5, 5, 15, 30, paint); |
| 692 | canvas->save(); |
| 693 | canvas->scale(10, 10); |
| 694 | canvas->drawBitmap(bitmap, antialias ? 12 : 0, 0); |
| 695 | canvas->restore(); |
| 696 | canvas->translate(15, 0); |
| 697 | } |
| 698 | } |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 699 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 700 | |
| 701 | #Method bool isAntiAlias() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 702 | #In Anti_alias |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 703 | #Line # returns true if Anti_Alias is set ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 704 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 705 | Returns true if pixels on the active edges of Path may be drawn with partial transparency. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 706 | |
| 707 | Equivalent to getFlags masked with kAntiAlias_Flag. |
| 708 | |
| 709 | #Return kAntiAlias_Flag state ## |
| 710 | |
| 711 | #Example |
| 712 | SkPaint paint; |
| 713 | SkDebugf("paint.isAntiAlias() %c= !!(paint.getFlags() & SkPaint::kAntiAlias_Flag)\n", |
| 714 | paint.isAntiAlias() == !!(paint.getFlags() & SkPaint::kAntiAlias_Flag) ? '=' : '!'); |
| 715 | paint.setAntiAlias(true); |
| 716 | SkDebugf("paint.isAntiAlias() %c= !!(paint.getFlags() & SkPaint::kAntiAlias_Flag)\n", |
| 717 | paint.isAntiAlias() == !!(paint.getFlags() & SkPaint::kAntiAlias_Flag) ? '=' : '!'); |
| 718 | |
| 719 | #StdOut |
| 720 | paint.isAntiAlias() == !!(paint.getFlags() & SkPaint::kAntiAlias_Flag) |
| 721 | paint.isAntiAlias() == !!(paint.getFlags() & SkPaint::kAntiAlias_Flag) |
| 722 | ## |
| 723 | ## |
| 724 | ## |
| 725 | |
| 726 | #Method void setAntiAlias(bool aa) |
| 727 | |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 728 | #In Anti_alias |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 729 | #Line # sets or clears Anti_Alias ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 730 | Requests, but does not require, that Path edge pixels draw opaque or with |
| 731 | partial transparency. |
| 732 | |
| 733 | Sets kAntiAlias_Flag if aa is true. |
| 734 | Clears kAntiAlias_Flag if aa is false. |
| 735 | |
| 736 | #Param aa setting for kAntiAlias_Flag ## |
| 737 | |
| 738 | #Example |
| 739 | SkPaint paint1, paint2; |
| 740 | paint1.setAntiAlias(true); |
| 741 | paint2.setFlags(paint2.getFlags() | SkPaint::kAntiAlias_Flag); |
| 742 | SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); |
| 743 | |
| 744 | #StdOut |
| 745 | paint1 == paint2 |
| 746 | ## |
| 747 | ## |
| 748 | |
| 749 | ## |
| 750 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 751 | #Subtopic Anti_Alias ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 752 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 753 | #Subtopic Dither |
| 754 | #Line # distributing color error ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 755 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 756 | Dither increases fidelity by adjusting the color of adjacent pixels. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 757 | This can help to smooth color transitions and reducing banding in gradients. |
| 758 | Dithering lessens visible banding from kRGB_565_SkColorType |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 759 | and kRGBA_8888_SkColorType gradients, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 760 | and improves rendering into a kRGB_565_SkColorType Surface. |
| 761 | |
| 762 | Dithering is always enabled for linear gradients drawing into |
| 763 | kRGB_565_SkColorType Surface and kRGBA_8888_SkColorType Surface. |
| 764 | Dither cannot be enabled for kAlpha_8_SkColorType Surface and |
| 765 | kRGBA_F16_SkColorType Surface. |
| 766 | |
| 767 | Dither is disabled by default. |
| 768 | Dither can be enabled by default by setting SkPaintDefaults_Flags to kDither_Flag |
| 769 | at compile time. |
| 770 | |
Cary Clark | 2be81cf | 2018-09-13 12:04:30 -0400 | [diff] [blame] | 771 | Some platform implementations may ignore dithering. Set #Formula # SK_IGNORE_GPU_DITHER ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 772 | to ignore Dither on GPU_Surface. |
| 773 | |
| 774 | #Example |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 775 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 776 | Dithering in the bottom half more closely approximates the requested color by |
| 777 | alternating nearby colors from pixel to pixel. |
| 778 | ## |
| 779 | void draw(SkCanvas* canvas) { |
| 780 | SkBitmap bm16; |
| 781 | bm16.allocPixels(SkImageInfo::Make(32, 32, kRGB_565_SkColorType, kOpaque_SkAlphaType)); |
| 782 | SkCanvas c16(bm16); |
| 783 | SkPaint colorPaint; |
| 784 | for (auto dither : { false, true } ) { |
| 785 | colorPaint.setDither(dither); |
| 786 | for (auto colors : { 0xFF333333, 0xFF666666, 0xFF999999, 0xFFCCCCCC } ) { |
| 787 | for (auto mask : { 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFFFFFF } ) { |
| 788 | colorPaint.setColor(colors & mask); |
| 789 | c16.drawRect({0, 0, 8, 4}, colorPaint); |
| 790 | c16.translate(8, 0); |
| 791 | } |
| 792 | c16.translate(-32, 4); |
| 793 | } |
| 794 | } |
| 795 | canvas->scale(8, 8); |
| 796 | canvas->drawBitmap(bm16, 0, 0); |
| 797 | } |
| 798 | ## |
| 799 | |
| 800 | #Example |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 801 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 802 | Dithering introduces subtle adjustments to color to smooth gradients. |
| 803 | Drawing the gradient repeatedly with SkBlendMode::kPlus exaggerates the |
| 804 | dither, making it easier to see. |
| 805 | ## |
| 806 | void draw(SkCanvas* canvas) { |
| 807 | canvas->clear(0); |
| 808 | SkBitmap bm32; |
| 809 | bm32.allocPixels(SkImageInfo::Make(20, 10, kN32_SkColorType, kPremul_SkAlphaType)); |
| 810 | SkCanvas c32(bm32); |
| 811 | SkPoint points[] = {{0, 0}, {20, 0}}; |
| 812 | SkColor colors[] = {0xFF334455, 0xFF662211 }; |
| 813 | SkPaint paint; |
| 814 | paint.setShader(SkGradientShader::MakeLinear( |
| 815 | points, colors, nullptr, SK_ARRAY_COUNT(colors), |
| 816 | SkShader::kClamp_TileMode, 0, nullptr)); |
| 817 | paint.setDither(true); |
| 818 | c32.drawPaint(paint); |
| 819 | canvas->scale(12, 12); |
| 820 | canvas->drawBitmap(bm32, 0, 0); |
| 821 | paint.setBlendMode(SkBlendMode::kPlus); |
| 822 | canvas->drawBitmap(bm32, 0, 11, &paint); |
| 823 | canvas->drawBitmap(bm32, 0, 11, &paint); |
| 824 | canvas->drawBitmap(bm32, 0, 11, &paint); |
| 825 | } |
| 826 | ## |
| 827 | |
| 828 | #Method bool isDither() const |
| 829 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 830 | #In Dither |
| 831 | #Line # returns true if Dither is set ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 832 | Returns true if color error may be distributed to smooth color transition. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 833 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 834 | Equivalent to getFlags masked with kDither_Flag. |
| 835 | |
| 836 | #Return kDither_Flag state ## |
| 837 | |
| 838 | #Example |
| 839 | SkPaint paint; |
| 840 | SkDebugf("paint.isDither() %c= !!(paint.getFlags() & SkPaint::kDither_Flag)\n", |
| 841 | paint.isDither() == !!(paint.getFlags() & SkPaint::kDither_Flag) ? '=' : '!'); |
| 842 | paint.setDither(true); |
| 843 | SkDebugf("paint.isDither() %c= !!(paint.getFlags() & SkPaint::kDither_Flag)\n", |
| 844 | paint.isDither() == !!(paint.getFlags() & SkPaint::kDither_Flag) ? '=' : '!'); |
| 845 | |
| 846 | #StdOut |
| 847 | paint.isDither() == !!(paint.getFlags() & SkPaint::kDither_Flag) |
| 848 | paint.isDither() == !!(paint.getFlags() & SkPaint::kDither_Flag) |
| 849 | ## |
| 850 | ## |
| 851 | |
| 852 | ## |
| 853 | |
| 854 | #Method void setDither(bool dither) |
| 855 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 856 | #In Dither |
| 857 | #Line # sets or clears Dither ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 858 | Requests, but does not require, to distribute color error. |
| 859 | |
| 860 | Sets kDither_Flag if dither is true. |
| 861 | Clears kDither_Flag if dither is false. |
| 862 | |
| 863 | #Param dither setting for kDither_Flag ## |
| 864 | |
| 865 | #Example |
| 866 | SkPaint paint1, paint2; |
| 867 | paint1.setDither(true); |
| 868 | paint2.setFlags(paint2.getFlags() | SkPaint::kDither_Flag); |
| 869 | SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); |
| 870 | |
| 871 | #StdOut |
| 872 | paint1 == paint2 |
| 873 | ## |
| 874 | ## |
| 875 | |
| 876 | #SeeAlso kRGB_565_SkColorType |
| 877 | |
| 878 | ## |
| 879 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 880 | #SeeAlso Gradient kRGB_565_SkColorType |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 881 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 882 | #Subtopic Dither ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 883 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 884 | #Subtopic Device_Text |
| 885 | #Line # increase precision of glyph position ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 886 | |
| 887 | LCD_Text and Subpixel_Text increase the precision of glyph position. |
| 888 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 889 | When set, Flags kLCDRenderText_Flag takes advantage of the organization of RGB stripes that |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 890 | create a color, and relies |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 891 | on the small size of the stripe and visual perception to make the color fringing imperceptible. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 892 | LCD_Text can be enabled on devices that orient stripes horizontally or vertically, and that order |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 893 | the color components as RGB or BGR. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 894 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 895 | Flags kSubpixelText_Flag uses the pixel transparency to represent a fractional offset. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 896 | As the opaqueness |
| 897 | of the color increases, the edge of the glyph appears to move towards the outside of the pixel. |
| 898 | |
| 899 | Either or both techniques can be enabled. |
| 900 | kLCDRenderText_Flag and kSubpixelText_Flag are clear by default. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 901 | LCD_Text or Subpixel_Text can be enabled by default by setting SkPaintDefaults_Flags to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 902 | kLCDRenderText_Flag or kSubpixelText_Flag (or both) at compile time. |
| 903 | |
| 904 | #Example |
| 905 | #Description |
| 906 | Four commas are drawn normally and with combinations of LCD_Text and Subpixel_Text. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 907 | When Subpixel_Text is disabled, the comma Glyphs are identical, but not evenly spaced. |
| 908 | When Subpixel_Text is enabled, the comma Glyphs are unique, but appear evenly spaced. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 909 | ## |
| 910 | |
| 911 | SkBitmap bitmap; |
| 912 | bitmap.allocN32Pixels(24, 33); |
| 913 | SkCanvas offscreen(bitmap); |
| 914 | offscreen.clear(SK_ColorWHITE); |
| 915 | SkPaint paint; |
| 916 | paint.setAntiAlias(true); |
| 917 | paint.setTextSize(20); |
| 918 | for (bool lcd : { false, true }) { |
| 919 | paint.setLCDRenderText(lcd); |
| 920 | for (bool subpixel : { false, true }) { |
| 921 | paint.setSubpixelText(subpixel); |
| 922 | offscreen.drawString(",,,,", 0, 4, paint); |
| 923 | offscreen.translate(0, 7); |
| 924 | } |
| 925 | } |
| 926 | canvas->drawBitmap(bitmap, 4, 12); |
| 927 | canvas->scale(9, 9); |
| 928 | canvas->drawBitmap(bitmap, 4, -1); |
| 929 | ## |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 930 | #Subtopic Device_Text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 931 | |
| 932 | #Subtopic Linear_Text |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 933 | #Alias Linear_Text ## |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 934 | #Line # selects text rendering as Glyph or Path ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 935 | |
| 936 | Linear_Text selects whether text is rendered as a Glyph or as a Path. |
| 937 | If kLinearText_Flag is set, it has the same effect as setting Hinting to kNormal_Hinting. |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 938 | If kLinearText_Flag is clear, it is the same as setting Hinting to kNo_Hinting. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 939 | |
| 940 | #Method bool isLinearText() const |
| 941 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 942 | #Line # returns true if text is converted to Path ## |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 943 | #In Linear_Text |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 944 | Returns true if text is converted to Path before drawing and measuring. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 945 | |
| 946 | Equivalent to getFlags masked with kLinearText_Flag. |
| 947 | |
| 948 | #Return kLinearText_Flag state ## |
| 949 | |
| 950 | #Example |
| 951 | #Height 128 |
| 952 | void draw(SkCanvas* canvas) { |
| 953 | SkPaint paint; |
| 954 | paint.setAntiAlias(true); |
| 955 | const char testStr[] = "xxxx xxxx"; |
| 956 | for (auto linearText : { false, true } ) { |
| 957 | paint.setLinearText(linearText); |
| 958 | paint.setTextSize(24); |
| 959 | canvas->drawString(paint.isLinearText() ? "linear" : "hinted", 128, 30, paint); |
| 960 | for (SkScalar textSize = 8; textSize < 30; textSize *= 1.22f) { |
| 961 | paint.setTextSize(textSize); |
| 962 | canvas->translate(0, textSize); |
| 963 | canvas->drawString(testStr, 10, 0, paint); |
| 964 | } |
| 965 | } |
| 966 | } |
| 967 | ## |
| 968 | |
| 969 | #SeeAlso setLinearText Hinting |
| 970 | ## |
| 971 | |
| 972 | #Method void setLinearText(bool linearText) |
| 973 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 974 | #Line # converts to Path before draw or measure ## |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 975 | #In Linear_Text |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 976 | Returns true if text is converted to Path before drawing and measuring. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 977 | By default, kLinearText_Flag is clear. |
| 978 | |
| 979 | Sets kLinearText_Flag if linearText is true. |
| 980 | Clears kLinearText_Flag if linearText is false. |
| 981 | |
| 982 | #Param linearText setting for kLinearText_Flag ## |
| 983 | |
| 984 | #Example |
| 985 | #Height 128 |
| 986 | void draw(SkCanvas* canvas) { |
| 987 | SkPaint paint; |
| 988 | paint.setAntiAlias(true); |
| 989 | const char testStr[] = "abcd efgh"; |
| 990 | for (int textSize : { 12, 24 } ) { |
| 991 | paint.setTextSize(textSize); |
| 992 | for (auto linearText : { false, true } ) { |
| 993 | paint.setLinearText(linearText); |
| 994 | SkString width; |
| 995 | width.appendScalar(paint.measureText(testStr, SK_ARRAY_COUNT(testStr), nullptr)); |
| 996 | canvas->translate(0, textSize + 4); |
| 997 | canvas->drawString(testStr, 10, 0, paint); |
| 998 | canvas->drawString(width, 128, 0, paint); |
| 999 | } |
| 1000 | } |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1001 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1002 | ## |
| 1003 | |
| 1004 | #SeeAlso isLinearText Hinting |
| 1005 | ## |
| 1006 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1007 | #Subtopic Linear_Text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1008 | |
| 1009 | #Subtopic Subpixel_Text |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1010 | #Alias Subpixel_Text ## |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1011 | #Line # uses pixel transparency to represent fractional offset ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1012 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1013 | Flags kSubpixelText_Flag uses the pixel transparency to represent a fractional offset. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1014 | As the opaqueness |
| 1015 | of the color increases, the edge of the glyph appears to move towards the outside of the pixel. |
| 1016 | |
| 1017 | #Method bool isSubpixelText() const |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1018 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1019 | #In Subpixel_Text |
| 1020 | #Line # returns true if Subpixel_Text is set ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1021 | Returns true if Glyphs at different sub-pixel positions may differ on pixel edge coverage. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1022 | |
| 1023 | Equivalent to getFlags masked with kSubpixelText_Flag. |
| 1024 | |
| 1025 | #Return kSubpixelText_Flag state ## |
| 1026 | |
| 1027 | #Example |
| 1028 | SkPaint paint; |
| 1029 | SkDebugf("paint.isSubpixelText() %c= !!(paint.getFlags() & SkPaint::kSubpixelText_Flag)\n", |
| 1030 | paint.isSubpixelText() == !!(paint.getFlags() & SkPaint::kSubpixelText_Flag) ? '=' : '!'); |
| 1031 | paint.setSubpixelText(true); |
| 1032 | SkDebugf("paint.isSubpixelText() %c= !!(paint.getFlags() & SkPaint::kSubpixelText_Flag)\n", |
| 1033 | paint.isSubpixelText() == !!(paint.getFlags() & SkPaint::kSubpixelText_Flag) ? '=' : '!'); |
| 1034 | |
| 1035 | #StdOut |
| 1036 | paint.isSubpixelText() == !!(paint.getFlags() & SkPaint::kSubpixelText_Flag) |
| 1037 | paint.isSubpixelText() == !!(paint.getFlags() & SkPaint::kSubpixelText_Flag) |
| 1038 | ## |
| 1039 | ## |
| 1040 | |
| 1041 | ## |
| 1042 | |
| 1043 | #Method void setSubpixelText(bool subpixelText) |
| 1044 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1045 | #In Subpixel_Text |
| 1046 | #Line # sets or clears Subpixel_Text ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1047 | Requests, but does not require, that Glyphs respect sub-pixel positioning. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1048 | |
| 1049 | Sets kSubpixelText_Flag if subpixelText is true. |
| 1050 | Clears kSubpixelText_Flag if subpixelText is false. |
| 1051 | |
| 1052 | #Param subpixelText setting for kSubpixelText_Flag ## |
| 1053 | |
| 1054 | #Example |
| 1055 | SkPaint paint1, paint2; |
| 1056 | paint1.setSubpixelText(true); |
| 1057 | paint2.setFlags(paint2.getFlags() | SkPaint::kSubpixelText_Flag); |
| 1058 | SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); |
| 1059 | |
| 1060 | #StdOut |
| 1061 | paint1 == paint2 |
| 1062 | ## |
| 1063 | ## |
| 1064 | |
| 1065 | ## |
| 1066 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1067 | #Subtopic Subpixel_Text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1068 | |
| 1069 | #Subtopic LCD_Text |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1070 | #Line # text relying on the order of RGB stripes ## |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1071 | |
| 1072 | # make this a top level name, since it is under subtopic Device_Text |
| 1073 | #Alias LCD_Text |
| 1074 | #Substitute LCD text |
| 1075 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1076 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1077 | When set, Flags kLCDRenderText_Flag takes advantage of the organization of RGB stripes that |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1078 | create a color, and relies |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1079 | on the small size of the stripe and visual perception to make the color fringing imperceptible. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1080 | LCD_Text can be enabled on devices that orient stripes horizontally or vertically, and that order |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1081 | the color components as RGB or BGR. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1082 | |
| 1083 | #Method bool isLCDRenderText() const |
| 1084 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1085 | #In LCD_Text |
| 1086 | #Line # returns true if LCD_Text is set ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1087 | Returns true if Glyphs may use LCD striping to improve glyph edges. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1088 | |
| 1089 | Returns true if Flags kLCDRenderText_Flag is set. |
| 1090 | |
| 1091 | #Return kLCDRenderText_Flag state ## |
| 1092 | |
| 1093 | #Example |
| 1094 | SkPaint paint; |
| 1095 | SkDebugf("paint.isLCDRenderText() %c= !!(paint.getFlags() & SkPaint::kLCDRenderText_Flag)\n", |
| 1096 | paint.isLCDRenderText() == !!(paint.getFlags() & SkPaint::kLCDRenderText_Flag) ? '=' : '!'); |
| 1097 | paint.setLCDRenderText(true); |
| 1098 | SkDebugf("paint.isLCDRenderText() %c= !!(paint.getFlags() & SkPaint::kLCDRenderText_Flag)\n", |
| 1099 | paint.isLCDRenderText() == !!(paint.getFlags() & SkPaint::kLCDRenderText_Flag) ? '=' : '!'); |
| 1100 | |
| 1101 | #StdOut |
| 1102 | paint.isLCDRenderText() == !!(paint.getFlags() & SkPaint::kLCDRenderText_Flag) |
| 1103 | paint.isLCDRenderText() == !!(paint.getFlags() & SkPaint::kLCDRenderText_Flag) |
| 1104 | ## |
| 1105 | ## |
| 1106 | |
| 1107 | ## |
| 1108 | |
| 1109 | #Method void setLCDRenderText(bool lcdText) |
| 1110 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1111 | #In LCD_Text |
| 1112 | #Line # sets or clears LCD_Text ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1113 | Requests, but does not require, that Glyphs use LCD striping for glyph edges. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1114 | |
| 1115 | Sets kLCDRenderText_Flag if lcdText is true. |
| 1116 | Clears kLCDRenderText_Flag if lcdText is false. |
| 1117 | |
| 1118 | #Param lcdText setting for kLCDRenderText_Flag ## |
| 1119 | |
| 1120 | #Example |
| 1121 | SkPaint paint1, paint2; |
| 1122 | paint1.setLCDRenderText(true); |
| 1123 | paint2.setFlags(paint2.getFlags() | SkPaint::kLCDRenderText_Flag); |
| 1124 | SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); |
| 1125 | |
| 1126 | #StdOut |
| 1127 | paint1 == paint2 |
| 1128 | ## |
| 1129 | ## |
| 1130 | |
| 1131 | |
| 1132 | ## |
| 1133 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1134 | #Subtopic LCD_Text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1135 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1136 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1137 | #Subtopic Font_Embedded_Bitmaps |
| 1138 | #Line # custom sized bitmap Glyphs ## |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1139 | #Alias Font_Embedded_Bitmaps ## # long-winded enough, alias so I don't type Paint_Font_... |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1140 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1141 | Font_Embedded_Bitmaps allows selecting custom sized bitmap Glyphs. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1142 | Flags kEmbeddedBitmapText_Flag when set chooses an embedded bitmap glyph over an outline contained |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1143 | in a font if the platform supports this option. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1144 | |
| 1145 | FreeType selects the bitmap glyph if available when kEmbeddedBitmapText_Flag is set, and selects |
| 1146 | the outline glyph if kEmbeddedBitmapText_Flag is clear. |
| 1147 | Windows may select the bitmap glyph but is not required to do so. |
| 1148 | OS_X and iOS do not support this option. |
| 1149 | |
| 1150 | Font_Embedded_Bitmaps is disabled by default. |
| 1151 | Font_Embedded_Bitmaps can be enabled by default by setting SkPaintDefaults_Flags to |
| 1152 | kEmbeddedBitmapText_Flag at compile time. |
| 1153 | |
| 1154 | #Example |
| 1155 | #ToDo image will only output on Ubuntu ... how to handle that in fiddle? ## |
| 1156 | #Platform !fiddle |
| 1157 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1158 | The "hintgasp" TrueType font in the Skia resources/fonts directory |
| 1159 | includes an embedded bitmap Glyph at odd font sizes. This example works |
| 1160 | on platforms that use FreeType as their Font_Engine. |
| 1161 | Windows may, but is not required to, return a bitmap glyph if |
| 1162 | kEmbeddedBitmapText_Flag is set. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1163 | ## |
| 1164 | #Image embeddedbitmap.png |
| 1165 | |
| 1166 | SkBitmap bitmap; |
| 1167 | bitmap.allocN32Pixels(30, 15); |
| 1168 | bitmap.eraseColor(0); |
| 1169 | SkCanvas offscreen(bitmap); |
| 1170 | SkPaint paint; |
| 1171 | paint.setAntiAlias(true); |
| 1172 | paint.setTextSize(13); |
Hal Canary | 53e5e7d | 2017-12-08 14:25:14 -0500 | [diff] [blame] | 1173 | paint.setTypeface(MakeResourceAsTypeface("fonts/hintgasp.ttf")); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1174 | for (bool embedded : { false, true}) { |
| 1175 | paint.setEmbeddedBitmapText(embedded); |
| 1176 | offscreen.drawString("A", embedded ? 5 : 15, 15, paint); |
| 1177 | } |
| 1178 | canvas->drawBitmap(bitmap, 0, 0); |
| 1179 | canvas->scale(10, 10); |
| 1180 | canvas->drawBitmap(bitmap, -2, 1); |
| 1181 | ## |
| 1182 | |
| 1183 | #Method bool isEmbeddedBitmapText() const |
| 1184 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1185 | #In Font_Embedded_Bitmaps |
| 1186 | #Line # returns true if Font_Embedded_Bitmaps is set ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1187 | Returns true if Font_Engine may return Glyphs from font bitmaps instead of from outlines. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1188 | |
| 1189 | Equivalent to getFlags masked with kEmbeddedBitmapText_Flag. |
| 1190 | |
| 1191 | #Return kEmbeddedBitmapText_Flag state ## |
| 1192 | |
| 1193 | #Example |
| 1194 | SkPaint paint; |
| 1195 | SkDebugf("paint.isEmbeddedBitmapText() %c=" |
| 1196 | " !!(paint.getFlags() & SkPaint::kEmbeddedBitmapText_Flag)\n", |
| 1197 | paint.isEmbeddedBitmapText() == |
| 1198 | !!(paint.getFlags() & SkPaint::kEmbeddedBitmapText_Flag) ? '=' : '!'); |
| 1199 | paint.setEmbeddedBitmapText(true); |
| 1200 | SkDebugf("paint.isEmbeddedBitmapText() %c=" |
| 1201 | " !!(paint.getFlags() & SkPaint::kEmbeddedBitmapText_Flag)\n", |
| 1202 | paint.isEmbeddedBitmapText() == |
| 1203 | !!(paint.getFlags() & SkPaint::kEmbeddedBitmapText_Flag) ? '=' : '!'); |
| 1204 | |
| 1205 | #StdOut |
| 1206 | paint.isEmbeddedBitmapText() == !!(paint.getFlags() & SkPaint::kEmbeddedBitmapText_Flag) |
| 1207 | paint.isEmbeddedBitmapText() == !!(paint.getFlags() & SkPaint::kEmbeddedBitmapText_Flag) |
| 1208 | ## |
| 1209 | ## |
| 1210 | |
| 1211 | ## |
| 1212 | |
| 1213 | #Method void setEmbeddedBitmapText(bool useEmbeddedBitmapText) |
| 1214 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1215 | #In Font_Embedded_Bitmaps |
| 1216 | #Line # sets or clears Font_Embedded_Bitmaps ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1217 | Requests, but does not require, to use bitmaps in fonts instead of outlines. |
| 1218 | |
| 1219 | Sets kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is true. |
| 1220 | Clears kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is false. |
| 1221 | |
| 1222 | #Param useEmbeddedBitmapText setting for kEmbeddedBitmapText_Flag ## |
| 1223 | |
| 1224 | #Example |
| 1225 | SkPaint paint1, paint2; |
| 1226 | paint1.setEmbeddedBitmapText(true); |
| 1227 | paint2.setFlags(paint2.getFlags() | SkPaint::kEmbeddedBitmapText_Flag); |
| 1228 | SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); |
| 1229 | |
| 1230 | #StdOut |
| 1231 | paint1 == paint2 |
| 1232 | ## |
| 1233 | ## |
| 1234 | |
| 1235 | ## |
| 1236 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1237 | #Subtopic Font_Embedded_Bitmaps ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1238 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1239 | #Subtopic Automatic_Hinting |
| 1240 | #Line # always adjust glyph paths ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1241 | #Substitute auto-hinting |
| 1242 | |
| 1243 | If Hinting is set to kNormal_Hinting or kFull_Hinting, Automatic_Hinting |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1244 | instructs the Font_Manager to always hint Glyphs. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1245 | Automatic_Hinting has no effect if Hinting is set to kNo_Hinting or |
| 1246 | kSlight_Hinting. |
| 1247 | |
| 1248 | Automatic_Hinting only affects platforms that use FreeType as the Font_Manager. |
| 1249 | |
| 1250 | #Method bool isAutohinted() const |
| 1251 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1252 | #In Automatic_Hinting |
| 1253 | #Line # returns true if Glyphs are always hinted ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1254 | Returns true if Hinting is set to kNormal_Hinting or kFull_Hinting, and if |
| 1255 | platform uses FreeType as the Font_Manager. If true, instructs |
| 1256 | the Font_Manager to always hint Glyphs. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1257 | |
| 1258 | Equivalent to getFlags masked with kAutoHinting_Flag. |
| 1259 | |
| 1260 | #Return kAutoHinting_Flag state ## |
| 1261 | |
| 1262 | #Example |
| 1263 | SkPaint paint; |
| 1264 | for (auto forceAutoHinting : { false, true} ) { |
| 1265 | paint.setAutohinted(forceAutoHinting); |
| 1266 | SkDebugf("paint.isAutohinted() %c=" |
| 1267 | " !!(paint.getFlags() & SkPaint::kAutoHinting_Flag)\n", |
| 1268 | paint.isAutohinted() == |
| 1269 | !!(paint.getFlags() & SkPaint::kAutoHinting_Flag) ? '=' : '!'); |
| 1270 | } |
| 1271 | #StdOut |
| 1272 | paint.isAutohinted() == !!(paint.getFlags() & SkPaint::kAutoHinting_Flag) |
| 1273 | paint.isAutohinted() == !!(paint.getFlags() & SkPaint::kAutoHinting_Flag) |
| 1274 | ## |
| 1275 | ## |
| 1276 | |
| 1277 | #SeeAlso setAutohinted Hinting |
| 1278 | |
| 1279 | ## |
| 1280 | |
| 1281 | #Method void setAutohinted(bool useAutohinter) |
| 1282 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1283 | #In Automatic_Hinting |
| 1284 | #Line # sets Glyphs to always be hinted ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1285 | Sets whether to always hint Glyphs. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1286 | If Hinting is set to kNormal_Hinting or kFull_Hinting and useAutohinter is set, |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1287 | instructs the Font_Manager to always hint Glyphs. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1288 | Automatic_Hinting has no effect if Hinting is set to kNo_Hinting or |
| 1289 | kSlight_Hinting. |
| 1290 | |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 1291 | Only affects platforms that use FreeType as the Font_Manager. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1292 | |
| 1293 | Sets kAutoHinting_Flag if useAutohinter is true. |
| 1294 | Clears kAutoHinting_Flag if useAutohinter is false. |
| 1295 | |
| 1296 | #Param useAutohinter setting for kAutoHinting_Flag ## |
| 1297 | |
| 1298 | #Example |
| 1299 | void draw(SkCanvas* canvas) { |
| 1300 | SkPaint paint; |
| 1301 | paint.setAntiAlias(true); |
| 1302 | const char testStr[] = "xxxx xxxx"; |
| 1303 | for (auto forceAutoHinting : { false, true} ) { |
| 1304 | paint.setAutohinted(forceAutoHinting); |
| 1305 | paint.setTextSize(24); |
| 1306 | canvas->drawString(paint.isAutohinted() ? "auto-hinted" : "default", 108, 30, paint); |
| 1307 | for (SkScalar textSize = 8; textSize < 30; textSize *= 1.22f) { |
| 1308 | paint.setTextSize(textSize); |
| 1309 | canvas->translate(0, textSize); |
| 1310 | canvas->drawString(testStr, 10, 0, paint); |
| 1311 | } |
| 1312 | } |
| 1313 | } |
| 1314 | ## |
| 1315 | |
| 1316 | #SeeAlso isAutohinted Hinting |
| 1317 | |
| 1318 | ## |
| 1319 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1320 | #Subtopic Automatic_Hinting ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1321 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1322 | #Subtopic Vertical_Text |
| 1323 | #Line # orient text from top to bottom ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1324 | |
| 1325 | Text may be drawn by positioning each glyph, or by positioning the first glyph and |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1326 | using Font_Advance to position subsequent Glyphs. By default, each successive glyph |
| 1327 | is positioned to the right of the preceding glyph. Vertical_Text sets successive |
| 1328 | Glyphs to position below the preceding glyph. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1329 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1330 | Skia can translate text character codes as a series of Glyphs, but does not implement |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1331 | font substitution, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1332 | textual substitution, line layout, or contextual spacing like Kerning pairs. Use |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1333 | a text shaping engine like |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1334 | #A HarfBuzz # https://harfbuzz.org/ ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1335 | to translate text runs |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1336 | into glyph series. |
| 1337 | |
| 1338 | Vertical_Text is clear if text is drawn left to right or set if drawn from top to bottom. |
| 1339 | |
| 1340 | Flags kVerticalText_Flag if clear draws text left to right. |
| 1341 | Flags kVerticalText_Flag if set draws text top to bottom. |
| 1342 | |
| 1343 | Vertical_Text is clear by default. |
| 1344 | Vertical_Text can be set by default by setting SkPaintDefaults_Flags to |
| 1345 | kVerticalText_Flag at compile time. |
| 1346 | |
| 1347 | #Example |
| 1348 | |
| 1349 | void draw(SkCanvas* canvas) { |
| 1350 | SkPaint paint; |
| 1351 | paint.setAntiAlias(true); |
| 1352 | paint.setTextSize(50); |
| 1353 | for (bool vertical : { false, true } ) { |
| 1354 | paint.setVerticalText(vertical); |
| 1355 | canvas->drawString("aAlL", 25, 50, paint); |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | ## |
| 1360 | |
| 1361 | #Method bool isVerticalText() const |
| 1362 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1363 | #In Vertical_Text |
| 1364 | #Line # returns true if Vertical_Text is set ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1365 | Returns true if Glyphs are drawn top to bottom instead of left to right. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1366 | |
| 1367 | Equivalent to getFlags masked with kVerticalText_Flag. |
| 1368 | |
| 1369 | #Return kVerticalText_Flag state ## |
| 1370 | |
| 1371 | #Example |
| 1372 | SkPaint paint; |
| 1373 | SkDebugf("paint.isVerticalText() %c= !!(paint.getFlags() & SkPaint::kVerticalText_Flag)\n", |
| 1374 | paint.isVerticalText() == !!(paint.getFlags() & SkPaint::kVerticalText_Flag) ? '=' : '!'); |
| 1375 | paint.setVerticalText(true); |
| 1376 | SkDebugf("paint.isVerticalText() %c= !!(paint.getFlags() & SkPaint::kVerticalText_Flag)\n", |
| 1377 | paint.isVerticalText() == !!(paint.getFlags() & SkPaint::kVerticalText_Flag) ? '=' : '!'); |
| 1378 | |
| 1379 | #StdOut |
| 1380 | paint.isVerticalText() == !!(paint.getFlags() & SkPaint::kVerticalText_Flag) |
| 1381 | paint.isVerticalText() == !!(paint.getFlags() & SkPaint::kVerticalText_Flag) |
| 1382 | ## |
| 1383 | ## |
| 1384 | |
| 1385 | ## |
| 1386 | |
| 1387 | #Method void setVerticalText(bool verticalText) |
| 1388 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1389 | #In Vertical_Text |
| 1390 | #Line # sets or clears Vertical_Text ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1391 | Returns true if text advance positions the next glyph below the previous glyph instead of to the |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1392 | right of previous glyph. |
| 1393 | |
| 1394 | Sets kVerticalText_Flag if vertical is true. |
| 1395 | Clears kVerticalText_Flag if vertical is false. |
| 1396 | |
| 1397 | #Param verticalText setting for kVerticalText_Flag ## |
| 1398 | |
| 1399 | #Example |
| 1400 | SkPaint paint1, paint2; |
| 1401 | paint1.setVerticalText(true); |
| 1402 | paint2.setFlags(paint2.getFlags() | SkPaint::kVerticalText_Flag); |
| 1403 | SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); |
| 1404 | |
| 1405 | #StdOut |
| 1406 | paint1 == paint2 |
| 1407 | ## |
| 1408 | ## |
| 1409 | |
| 1410 | ## |
| 1411 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1412 | #Subtopic Vertical_Text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1413 | # ------------------------------------------------------------------------------ |
| 1414 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1415 | #Subtopic Fake_Bold |
| 1416 | #Line # approximate font styles ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1417 | |
| 1418 | Fake_Bold approximates the bold font style accompanying a normal font when a bold font face |
| 1419 | is not available. Skia does not provide font substitution; it is up to the client to find the |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1420 | bold font face using the platform Font_Manager. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1421 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1422 | Use Text_Skew_X to approximate an italic font style when the italic font face |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1423 | is not available. |
| 1424 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1425 | A FreeType based port may define SK_USE_FREETYPE_EMBOLDEN at compile time to direct |
| 1426 | the font engine to create the bold Glyphs. Otherwise, the extra bold is computed |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1427 | by increasing the stroke width and setting the Style to kStrokeAndFill_Style as needed. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1428 | |
| 1429 | Fake_Bold is disabled by default. |
| 1430 | |
| 1431 | #Example |
| 1432 | #Height 128 |
| 1433 | void draw(SkCanvas* canvas) { |
| 1434 | SkPaint paint; |
| 1435 | paint.setAntiAlias(true); |
| 1436 | paint.setTextSize(40); |
| 1437 | canvas->drawString("OjYy_-", 10, 35, paint); |
| 1438 | paint.setFakeBoldText(true); |
| 1439 | canvas->drawString("OjYy_-", 10, 75, paint); |
| 1440 | // create a custom fake bold by varying the stroke width |
| 1441 | paint.setFakeBoldText(false); |
| 1442 | paint.setStyle(SkPaint::kStrokeAndFill_Style); |
| 1443 | paint.setStrokeWidth(40.f / 48); |
| 1444 | canvas->drawString("OjYy_-", 10, 115, paint); |
| 1445 | } |
| 1446 | ## |
| 1447 | |
| 1448 | #Method bool isFakeBoldText() const |
| 1449 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1450 | #In Fake_Bold |
| 1451 | #Line # returns true if Fake_Bold is set ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1452 | Returns true if approximate bold by increasing the stroke width when creating glyph bitmaps |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1453 | from outlines. |
| 1454 | |
| 1455 | Equivalent to getFlags masked with kFakeBoldText_Flag. |
| 1456 | |
| 1457 | #Return kFakeBoldText_Flag state ## |
| 1458 | |
| 1459 | #Example |
| 1460 | SkPaint paint; |
| 1461 | SkDebugf("paint.isFakeBoldText() %c= !!(paint.getFlags() & SkPaint::kFakeBoldText_Flag)\n", |
| 1462 | paint.isFakeBoldText() == !!(paint.getFlags() & SkPaint::kFakeBoldText_Flag) ? '=' : '!'); |
| 1463 | paint.setFakeBoldText(true); |
| 1464 | SkDebugf("paint.isFakeBoldText() %c= !!(paint.getFlags() & SkPaint::kFakeBoldText_Flag)\n", |
| 1465 | paint.isFakeBoldText() == !!(paint.getFlags() & SkPaint::kFakeBoldText_Flag) ? '=' : '!'); |
| 1466 | |
| 1467 | #StdOut |
| 1468 | paint.isFakeBoldText() == !!(paint.getFlags() & SkPaint::kFakeBoldText_Flag) |
| 1469 | paint.isFakeBoldText() == !!(paint.getFlags() & SkPaint::kFakeBoldText_Flag) |
| 1470 | ## |
| 1471 | ## |
| 1472 | |
| 1473 | ## |
| 1474 | |
| 1475 | #Method void setFakeBoldText(bool fakeBoldText) |
| 1476 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1477 | #In Fake_Bold |
| 1478 | #Line # sets or clears Fake_Bold ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1479 | Increases stroke width when creating glyph bitmaps to approximate a bold typeface. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1480 | |
| 1481 | Sets kFakeBoldText_Flag if fakeBoldText is true. |
| 1482 | Clears kFakeBoldText_Flag if fakeBoldText is false. |
| 1483 | |
| 1484 | #Param fakeBoldText setting for kFakeBoldText_Flag ## |
| 1485 | |
| 1486 | #Example |
| 1487 | SkPaint paint1, paint2; |
| 1488 | paint1.setFakeBoldText(true); |
| 1489 | paint2.setFlags(paint2.getFlags() | SkPaint::kFakeBoldText_Flag); |
| 1490 | SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); |
| 1491 | |
| 1492 | #StdOut |
| 1493 | paint1 == paint2 |
| 1494 | ## |
| 1495 | ## |
| 1496 | |
| 1497 | ## |
| 1498 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1499 | #Subtopic Fake_Bold ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1500 | |
| 1501 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1502 | #Subtopic Full_Hinting_Spacing |
| 1503 | #Line # glyph spacing affected by hinting ## |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1504 | #Alias Full_Hinting_Spacing ## # long winded enough -- maybe things with two underscores auto-aliased? |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1505 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1506 | if Hinting is set to kFull_Hinting, Full_Hinting_Spacing adjusts the character |
| 1507 | spacing by the difference of the hinted and Unhinted Left_Side_Bearing and |
| 1508 | Right_Side_Bearing. Full_Hinting_Spacing only applies to platforms that use |
| 1509 | FreeType as their Font_Engine. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1510 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1511 | Full_Hinting_Spacing is not related to text Kerning, where the space between |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1512 | a specific pair of characters is adjusted using data in the font Kerning tables. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1513 | |
| 1514 | #Method bool isDevKernText() const |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1515 | #Deprecated |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1516 | ## |
| 1517 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1518 | #Method void setDevKernText(bool) |
| 1519 | #Deprecated |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1520 | ## |
| 1521 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1522 | #Subtopic Full_Hinting_Spacing ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1523 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1524 | #Subtopic Filter_Quality_Methods |
| 1525 | #Line # get and set Filter_Quality ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1526 | |
| 1527 | Filter_Quality trades speed for image filtering when the image is scaled. |
| 1528 | A lower Filter_Quality draws faster, but has less fidelity. |
| 1529 | A higher Filter_Quality draws slower, but looks better. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1530 | If the image is drawn without scaling, the Filter_Quality choice will not result |
| 1531 | in a noticeable difference. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1532 | |
| 1533 | Filter_Quality is used in Paint passed as a parameter to |
| 1534 | #List |
| 1535 | # SkCanvas::drawBitmap ## |
| 1536 | # SkCanvas::drawBitmapRect ## |
| 1537 | # SkCanvas::drawImage ## |
| 1538 | # SkCanvas::drawImageRect ## |
| 1539 | #ToDo probably more... ## |
| 1540 | #List ## |
| 1541 | and when Paint has a Shader specialization that uses Image or Bitmap. |
| 1542 | |
| 1543 | Filter_Quality is kNone_SkFilterQuality by default. |
| 1544 | |
| 1545 | #Example |
| 1546 | #Image 3 |
| 1547 | void draw(SkCanvas* canvas) { |
| 1548 | SkPaint paint; |
| 1549 | canvas->scale(.2f, .2f); |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1550 | for (SkFilterQuality q : { kNone_SkFilterQuality, kLow_SkFilterQuality, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1551 | kMedium_SkFilterQuality, kHigh_SkFilterQuality } ) { |
| 1552 | paint.setFilterQuality(q); |
| 1553 | canvas->drawImage(image.get(), 0, 0, &paint); |
| 1554 | canvas->translate(550, 0); |
| 1555 | if (kLow_SkFilterQuality == q) canvas->translate(-1100, 550); |
| 1556 | } |
| 1557 | } |
| 1558 | ## |
| 1559 | |
| 1560 | #Method SkFilterQuality getFilterQuality() const |
| 1561 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1562 | #In Filter_Quality_Methods |
| 1563 | #Line # returns Filter_Quality, image filtering level ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1564 | Returns Filter_Quality, the image filtering level. A lower setting |
| 1565 | draws faster; a higher setting looks better when the image is scaled. |
| 1566 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1567 | #Return one of: kNone_SkFilterQuality, kLow_SkFilterQuality, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1568 | kMedium_SkFilterQuality, kHigh_SkFilterQuality |
| 1569 | #Return ## |
| 1570 | |
| 1571 | #Example |
| 1572 | SkPaint paint; |
| 1573 | SkDebugf("kNone_SkFilterQuality %c= paint.getFilterQuality()\n", |
| 1574 | kNone_SkFilterQuality == paint.getFilterQuality() ? '=' : '!'); |
| 1575 | |
| 1576 | #StdOut |
| 1577 | kNone_SkFilterQuality == paint.getFilterQuality() |
| 1578 | ## |
| 1579 | ## |
| 1580 | |
| 1581 | ## |
| 1582 | |
| 1583 | |
| 1584 | #Method void setFilterQuality(SkFilterQuality quality) |
| 1585 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1586 | #In Filter_Quality_Methods |
| 1587 | #Line # sets Filter_Quality, the image filtering level ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1588 | Sets Filter_Quality, the image filtering level. A lower setting |
| 1589 | draws faster; a higher setting looks better when the image is scaled. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1590 | Does not check to see if quality is valid. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1591 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1592 | #Param quality one of: kNone_SkFilterQuality, kLow_SkFilterQuality, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1593 | kMedium_SkFilterQuality, kHigh_SkFilterQuality |
| 1594 | ## |
| 1595 | |
| 1596 | #Example |
| 1597 | SkPaint paint; |
| 1598 | paint.setFilterQuality(kHigh_SkFilterQuality); |
| 1599 | SkDebugf("kHigh_SkFilterQuality %c= paint.getFilterQuality()\n", |
| 1600 | kHigh_SkFilterQuality == paint.getFilterQuality() ? '=' : '!'); |
| 1601 | |
| 1602 | #StdOut |
| 1603 | kHigh_SkFilterQuality == paint.getFilterQuality() |
| 1604 | ## |
| 1605 | ## |
| 1606 | |
| 1607 | #SeeAlso SkFilterQuality Image_Scaling |
| 1608 | |
| 1609 | ## |
| 1610 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1611 | #Subtopic Filter_Quality_Methods ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1612 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1613 | #Subtopic Color_Methods |
| 1614 | #Line # get and set Color ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1615 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1616 | #Table |
| 1617 | #Legend |
| 1618 | # name # description ## |
| 1619 | #Legend ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1620 | # getColor # returns Color_Alpha and RGB, one drawing color ## |
| 1621 | # setColor # sets Color_Alpha and RGB, one drawing color ## |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1622 | #Table ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1623 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1624 | Color specifies the red, blue, green, and Color_Alpha |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1625 | values used to draw a filled or stroked shape in a 32-bit value. Each component |
| 1626 | occupies 8-bits, ranging from zero: no contribution; to 255: full intensity. |
| 1627 | All values in any combination are valid. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1628 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1629 | Color is not Premultiplied; Color_Alpha sets the transparency independent of |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1630 | RGB: red, blue, and green. |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1631 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1632 | The bit positions of Color_Alpha and RGB are independent of the bit |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1633 | positions on the output device, which may have more or fewer bits, and may have |
| 1634 | a different arrangement. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1635 | |
| 1636 | #Table |
| 1637 | #Legend |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1638 | # bit positions # Color_Alpha # red # blue # green ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1639 | #Legend ## |
| 1640 | # # 31 - 24 # 23 - 16 # 15 - 8 # 7 - 0 ## |
| 1641 | #Table ## |
| 1642 | |
| 1643 | #Example |
| 1644 | #Height 128 |
| 1645 | void draw(SkCanvas* canvas) { |
| 1646 | SkPaint paint; |
| 1647 | paint.setColor(0x8000FF00); // transparent green |
| 1648 | canvas->drawCircle(50, 50, 40, paint); |
| 1649 | paint.setARGB(128, 255, 0, 0); // transparent red |
| 1650 | canvas->drawCircle(80, 50, 40, paint); |
| 1651 | paint.setColor(SK_ColorBLUE); |
| 1652 | paint.setAlpha(0x80); |
| 1653 | canvas->drawCircle(65, 65, 40, paint); |
| 1654 | } |
| 1655 | ## |
| 1656 | |
| 1657 | #Method SkColor getColor() const |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1658 | #In Color_Methods |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1659 | #Line # returns Color_Alpha and RGB, one drawing color ## |
| 1660 | Retrieves Alpha and RGB, Unpremultiplied, packed into 32 bits. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1661 | Use helpers SkColorGetA, SkColorGetR, SkColorGetG, and SkColorGetB to extract |
| 1662 | a color component. |
| 1663 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1664 | #Return Unpremultiplied ARGB ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1665 | |
| 1666 | #Example |
| 1667 | SkPaint paint; |
| 1668 | paint.setColor(SK_ColorYELLOW); |
| 1669 | SkColor y = paint.getColor(); |
| 1670 | SkDebugf("Yellow is %d%% red, %d%% green, and %d%% blue.\n", (int) (SkColorGetR(y) / 2.55f), |
| 1671 | (int) (SkColorGetG(y) / 2.55f), (int) (SkColorGetB(y) / 2.55f)); |
| 1672 | |
| 1673 | #StdOut |
| 1674 | Yellow is 100% red, 100% green, and 0% blue. |
| 1675 | ## |
| 1676 | ## |
| 1677 | |
Cary Clark | bbe8ff9 | 2018-09-05 11:39:01 -0400 | [diff] [blame] | 1678 | #SeeAlso getColor4f SkColor |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1679 | |
| 1680 | ## |
| 1681 | |
Cary Clark | bbe8ff9 | 2018-09-05 11:39:01 -0400 | [diff] [blame] | 1682 | #Method SkColor4f getColor4f() const |
| 1683 | #In Color_Methods |
| 1684 | #Line # returns Color_Alpha and RGB, one drawing color ## |
| 1685 | Retrieves alpha and RGB, unpmreultiplied, as four floating point values. RGB are |
| 1686 | are extended sRGB values (sRGB gamut, and encoded with the sRGB transfer function). |
Brian Osman | 3f70d17 | 2018-09-04 19:50:28 +0000 | [diff] [blame] | 1687 | |
Cary Clark | bbe8ff9 | 2018-09-05 11:39:01 -0400 | [diff] [blame] | 1688 | #Return Unpremultiplied RGBA ## |
| 1689 | |
| 1690 | #ToDo enable and correct example once fiddle picks up getColor4f ## |
| 1691 | #Example |
| 1692 | SkPaint paint; |
| 1693 | paint.setColor(SK_ColorYELLOW); |
| 1694 | SkColor4f y = paint.getColor4f(); |
| 1695 | SkDebugf("Yellow is %d%% red, %d%% green, and %d%% blue.\n", (int) (y.fR * 100), |
| 1696 | (int) (y.fG * 100), (int) (y.fB * 100)); |
| 1697 | |
| 1698 | #StdOut |
| 1699 | Yellow is 100% red, 100% green, and 0% blue. |
| 1700 | ## |
| 1701 | ## |
| 1702 | |
| 1703 | #SeeAlso getColor SkColor |
| 1704 | ## |
| 1705 | |
| 1706 | |
| 1707 | #Method void setColor(SkColor color) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1708 | #In Color_Methods |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1709 | #Line # sets Color_Alpha and RGB, one drawing color ## |
| 1710 | Sets Alpha and RGB used when stroking and filling. The color is a 32-bit value, |
| 1711 | Unpremultiplied, packing 8-bit components for Alpha, red, blue, and green. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1712 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1713 | #Param color Unpremultiplied ARGB ## |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1714 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 1715 | #Example |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1716 | SkPaint green1, green2; |
| 1717 | unsigned a = 255; |
| 1718 | unsigned r = 0; |
| 1719 | unsigned g = 255; |
| 1720 | unsigned b = 0; |
| 1721 | green1.setColor((a << 24) + (r << 16) + (g << 8) + (b << 0)); |
| 1722 | green2.setColor(0xFF00FF00); |
| 1723 | SkDebugf("green1 %c= green2\n", green1 == green2 ? '=' : '!'); |
| 1724 | |
| 1725 | #StdOut |
| 1726 | green1 == green2 |
| 1727 | ## |
| 1728 | ## |
| 1729 | |
Cary Clark | bbe8ff9 | 2018-09-05 11:39:01 -0400 | [diff] [blame] | 1730 | #SeeAlso SkColor setColor4f setARGB SkColorSetARGB |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1731 | |
| 1732 | ## |
Cary Clark | bbe8ff9 | 2018-09-05 11:39:01 -0400 | [diff] [blame] | 1733 | |
| 1734 | #Method void setColor4f(const SkColor4f& color, SkColorSpace* colorSpace) |
| 1735 | #In Color_Methods |
| 1736 | #Line # sets Color_Alpha and RGB, one drawing color ## |
| 1737 | Sets alpha and RGB used when stroking and filling. The color is four floating |
| 1738 | point values, unpremultiplied. The color values are interpreted as being in |
| 1739 | the colorSpace. If colorSpace is nullptr, then color is assumed to be in the |
| 1740 | sRGB color space. |
| 1741 | |
| 1742 | #Param color Unpremultiplied RGBA ## |
| 1743 | #Param colorSpace Color_Space describing the encoding of color ## |
| 1744 | |
| 1745 | #ToDo enable and correct example once fiddle picks up setColor4f ## |
| 1746 | #Example |
| 1747 | SkPaint green1, green2; |
| 1748 | green1.setColor4f({0, 1, 0, 1}, nullptr); // R=0 G=1 B=0 A=1 |
| 1749 | green2.setColor(0xFF00FF00); // A=255 R=0 G=255 B=0 |
| 1750 | SkDebugf("green1 %c= green2\n", green1 == green2 ? '=' : '!'); |
| 1751 | |
| 1752 | #StdOut |
| 1753 | green1 == green2 |
| 1754 | ## |
| 1755 | ## |
| 1756 | |
| 1757 | #SeeAlso SkColor setColor setARGB SkColorSetARGB |
| 1758 | |
| 1759 | ## |
| 1760 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1761 | #Subtopic Color_Methods ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1762 | |
| 1763 | #Subtopic Alpha_Methods |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1764 | #Line # get and set Alpha ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1765 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1766 | Color_Alpha sets the transparency independent of RGB: red, blue, and green. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1767 | |
| 1768 | #Method uint8_t getAlpha() const |
| 1769 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1770 | #In Alpha_Methods |
| 1771 | #Line # returns Color_Alpha, color opacity ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1772 | Retrieves Alpha from the Color used when stroking and filling. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1773 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1774 | #Return Alpha ranging from zero, fully transparent, to 255, fully opaque ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1775 | |
| 1776 | #Example |
| 1777 | SkPaint paint; |
| 1778 | SkDebugf("255 %c= paint.getAlpha()\n", 255 == paint.getAlpha() ? '=' : '!'); |
| 1779 | |
| 1780 | #StdOut |
| 1781 | 255 == paint.getAlpha() |
| 1782 | ## |
| 1783 | ## |
| 1784 | |
| 1785 | ## |
| 1786 | |
| 1787 | #Method void setAlpha(U8CPU a) |
| 1788 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1789 | #In Alpha_Methods |
| 1790 | #Line # sets Color_Alpha, color opacity ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1791 | Replaces Alpha, leaving RGB |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1792 | unchanged. An out of range value triggers an assert in the debug |
| 1793 | build. a is a value from zero to 255. |
| 1794 | a set to zero makes Color fully transparent; a set to 255 makes Color |
| 1795 | fully opaque. |
| 1796 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1797 | #Param a Alpha component of Color ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1798 | |
| 1799 | #Example |
| 1800 | SkPaint paint; |
| 1801 | paint.setColor(0x00112233); |
| 1802 | paint.setAlpha(0x44); |
| 1803 | SkDebugf("0x44112233 %c= paint.getColor()\n", 0x44112233 == paint.getColor() ? '=' : '!'); |
| 1804 | |
| 1805 | #StdOut |
| 1806 | 0x44112233 == paint.getColor() |
| 1807 | ## |
| 1808 | ## |
| 1809 | |
| 1810 | ## |
| 1811 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1812 | #Subtopic Alpha_Methods ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1813 | |
| 1814 | #Method void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) |
| 1815 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1816 | #In Color_Methods |
| 1817 | #Line # sets color by component ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1818 | Sets Color used when drawing solid fills. The color components range from 0 to 255. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1819 | The color is Unpremultiplied; Alpha sets the transparency independent of RGB. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1820 | |
| 1821 | #Param a amount of Color_Alpha, from fully transparent (0) to fully opaque (255) ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1822 | #Param r amount of red, from no red (0) to full red (255) ## |
| 1823 | #Param g amount of green, from no green (0) to full green (255) ## |
| 1824 | #Param b amount of blue, from no blue (0) to full blue (255) ## |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1825 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1826 | #Example |
| 1827 | SkPaint transRed1, transRed2; |
| 1828 | transRed1.setARGB(255 / 2, 255, 0, 0); |
| 1829 | transRed2.setColor(SkColorSetARGB(255 / 2, 255, 0, 0)); |
| 1830 | SkDebugf("transRed1 %c= transRed2", transRed1 == transRed2 ? '=' : '!'); |
| 1831 | |
| 1832 | #StdOut |
| 1833 | transRed1 == transRed2 |
| 1834 | ## |
| 1835 | ## |
| 1836 | |
| 1837 | #SeeAlso setColor SkColorSetARGB |
| 1838 | |
| 1839 | ## |
| 1840 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1841 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1842 | #Subtopic Style |
| 1843 | #Line # geometry filling, stroking ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1844 | |
| 1845 | Style specifies if the geometry is filled, stroked, or both filled and stroked. |
| 1846 | Some shapes ignore Style and are always drawn filled or stroked. |
| 1847 | |
| 1848 | Set Style to kFill_Style to fill the shape. |
| 1849 | The fill covers the area inside the geometry for most shapes. |
| 1850 | |
| 1851 | Set Style to kStroke_Style to stroke the shape. |
| 1852 | |
| 1853 | # ------------------------------------------------------------------------------ |
| 1854 | #Subtopic Fill |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1855 | #Line # fill and stroke ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1856 | #ToDo write up whatever generalities make sense to describe filling ## |
| 1857 | |
| 1858 | #SeeAlso Path_Fill_Type |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1859 | #Subtopic Fill ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1860 | |
| 1861 | #Subtopic Stroke |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1862 | #Line # lines and curves with width ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1863 | The stroke covers the area described by following the shape edge with a pen or brush of |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1864 | Stroke_Width. The area covered where the shape starts and stops is described by Stroke_Cap. |
| 1865 | The area covered where the shape turns a corner is described by Stroke_Join. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1866 | The stroke is centered on the shape; it extends equally on either side of the shape edge. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1867 | |
| 1868 | As Stroke_Width gets smaller, the drawn path frame is thinner. Stroke_Width less than one |
| 1869 | may have gaps, and if kAntiAlias_Flag is set, Color_Alpha will increase to visually decrease coverage. |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1870 | #Subtopic Stroke ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1871 | |
| 1872 | #Subtopic Hairline |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1873 | #Line # lines and curves with minimal width ## |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1874 | #Alias Hairline ## # maybe should be Stroke_Hairline ? |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1875 | |
| 1876 | Stroke_Width of zero has a special meaning and switches drawing to use Hairline. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1877 | Hairline draws the thinnest continuous frame. If kAntiAlias_Flag is clear, adjacent pixels |
| 1878 | flow horizontally, vertically,or diagonally. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1879 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1880 | #ToDo what is the description of Anti_Aliased hairlines? ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1881 | |
| 1882 | Path drawing with Hairline may hit the same pixel more than once. For instance, Path containing |
| 1883 | two lines in one Path_Contour will draw the corner point once, but may both lines may draw the adjacent |
| 1884 | pixel. If kAntiAlias_Flag is set, transparency is applied twice, resulting in a darker pixel. Some |
| 1885 | GPU-backed implementations apply transparency at a later drawing stage, avoiding double hit pixels |
| 1886 | while stroking. |
| 1887 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1888 | #Subtopic Hairline ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1889 | |
| 1890 | #Enum Style |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1891 | #Line # stroke, fill, or both ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1892 | |
| 1893 | #Code |
| 1894 | enum Style { |
| 1895 | kFill_Style, |
| 1896 | kStroke_Style, |
| 1897 | kStrokeAndFill_Style, |
| 1898 | }; |
Cary Clark | d98f78c | 2018-04-26 08:32:37 -0400 | [diff] [blame] | 1899 | |
| 1900 | static constexpr int kStyleCount = kStrokeAndFill_Style + 1; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1901 | ## |
| 1902 | |
| 1903 | Set Style to fill, stroke, or both fill and stroke geometry. |
| 1904 | The stroke and fill |
| 1905 | share all paint attributes; for instance, they are drawn with the same color. |
| 1906 | |
| 1907 | Use kStrokeAndFill_Style to avoid hitting the same pixels twice with a stroke draw and |
| 1908 | a fill draw. |
| 1909 | |
| 1910 | #Const kFill_Style 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1911 | #Line # set to fill geometry ## |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1912 | Applies to Rect, Region, Round_Rect, Circles, Ovals, Path, and Text. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1913 | Bitmap, Image, Patches, Region, Sprites, and Vertices are painted as if |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1914 | kFill_Style is set, and ignore the set Style. |
| 1915 | The Path_Fill_Type specifies additional rules to fill the area outside the path edge, |
| 1916 | and to create an unfilled hole inside the shape. |
| 1917 | Style is set to kFill_Style by default. |
| 1918 | ## |
| 1919 | |
| 1920 | #Const kStroke_Style 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1921 | #Line # set to stroke geometry ## |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1922 | Applies to Rect, Region, Round_Rect, Arcs, Circles, Ovals, Path, and Text. |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1923 | Arcs, Lines, and points, are always drawn as if kStroke_Style is set, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1924 | and ignore the set Style. |
| 1925 | The stroke construction is unaffected by the Path_Fill_Type. |
| 1926 | ## |
| 1927 | |
| 1928 | #Const kStrokeAndFill_Style 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1929 | #Line # sets to stroke and fill geometry ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1930 | Applies to Rect, Region, Round_Rect, Circles, Ovals, Path, and Text. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1931 | Path is treated as if it is set to SkPath::kWinding_FillType, |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 1932 | and the set Path_Fill_Type is ignored. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1933 | ## |
| 1934 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1935 | #Const kStyleCount 3 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1936 | #Line # number of different Style values defined ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1937 | May be used to verify that Style is a legal value. |
| 1938 | ## |
| 1939 | |
Cary Clark | d98f78c | 2018-04-26 08:32:37 -0400 | [diff] [blame] | 1940 | #Enum Style ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1941 | |
| 1942 | #Method Style getStyle() const |
| 1943 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1944 | #In Style |
| 1945 | #Line # returns Style: stroke, fill, or both ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1946 | Returns whether the geometry is filled, stroked, or filled and stroked. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1947 | |
| 1948 | #Return one of:kFill_Style, kStroke_Style, kStrokeAndFill_Style ## |
| 1949 | |
| 1950 | #Example |
| 1951 | SkPaint paint; |
| 1952 | SkDebugf("SkPaint::kFill_Style %c= paint.getStyle()\n", |
| 1953 | SkPaint::kFill_Style == paint.getStyle() ? '=' : '!'); |
| 1954 | |
| 1955 | #StdOut |
| 1956 | SkPaint::kFill_Style == paint.getStyle() |
| 1957 | ## |
| 1958 | ## |
| 1959 | |
| 1960 | #SeeAlso Style setStyle |
| 1961 | ## |
| 1962 | |
| 1963 | #Method void setStyle(Style style) |
| 1964 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1965 | #In Style |
| 1966 | #Line # sets Style: stroke, fill, or both ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1967 | Sets whether the geometry is filled, stroked, or filled and stroked. |
| 1968 | Has no effect if style is not a legal Style value. |
| 1969 | |
| 1970 | #Param style one of: kFill_Style, kStroke_Style, kStrokeAndFill_Style |
| 1971 | ## |
| 1972 | |
| 1973 | #Example |
| 1974 | void draw(SkCanvas* canvas) { |
| 1975 | SkPaint paint; |
| 1976 | paint.setStrokeWidth(5); |
| 1977 | SkRegion region; |
| 1978 | region.op(140, 10, 160, 30, SkRegion::kUnion_Op); |
| 1979 | region.op(170, 40, 190, 60, SkRegion::kUnion_Op); |
| 1980 | SkBitmap bitmap; |
| 1981 | bitmap.setInfo(SkImageInfo::MakeA8(50, 50), 50); |
| 1982 | uint8_t pixels[50][50]; |
| 1983 | for (int x = 0; x < 50; ++x) { |
| 1984 | for (int y = 0; y < 50; ++y) { |
| 1985 | pixels[y][x] = (x + y) % 5 ? 0xFF : 0x00; |
| 1986 | } |
| 1987 | } |
| 1988 | bitmap.setPixels(pixels); |
| 1989 | for (auto style : { SkPaint::kFill_Style, |
| 1990 | SkPaint::kStroke_Style, |
| 1991 | SkPaint::kStrokeAndFill_Style }) { |
| 1992 | paint.setStyle(style); |
| 1993 | canvas->drawLine(10, 10, 60, 60, paint); |
| 1994 | canvas->drawRect({80, 10, 130, 60}, paint); |
| 1995 | canvas->drawRegion(region, paint); |
| 1996 | canvas->drawBitmap(bitmap, 200, 10, &paint); |
| 1997 | canvas->translate(0, 80); |
| 1998 | } |
| 1999 | } |
| 2000 | ## |
| 2001 | |
| 2002 | #SeeAlso Style getStyle |
| 2003 | ## |
| 2004 | |
| 2005 | #SeeAlso Path_Fill_Type Path_Effect Style_Fill Style_Stroke |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2006 | #Subtopic Style ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2007 | |
| 2008 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2009 | #Subtopic Stroke_Width |
| 2010 | #Line # thickness perpendicular to geometry ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2011 | |
| 2012 | Stroke_Width sets the width for stroking. The width is the thickness |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2013 | of the stroke perpendicular to the path direction when the paint style is |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2014 | set to kStroke_Style or kStrokeAndFill_Style. |
| 2015 | |
| 2016 | When width is greater than zero, the stroke encompasses as many pixels partially |
| 2017 | or fully as needed. When the width equals zero, the paint enables hairlines; |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2018 | the stroke is always one pixel wide. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2019 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2020 | The stroke dimensions are scaled by the canvas matrix, but Hairline stroke |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2021 | remains one pixel wide regardless of scaling. |
| 2022 | |
| 2023 | The default width for the paint is zero. |
| 2024 | |
| 2025 | #Example |
| 2026 | #Height 170 |
| 2027 | #Platform raster gpu |
| 2028 | #Description |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2029 | The pixels hit to represent thin lines vary with the angle of the |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2030 | line and the platform implementation. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2031 | ## |
| 2032 | void draw(SkCanvas* canvas) { |
| 2033 | SkPaint paint; |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2034 | for (bool antialias : { false, true }) { |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2035 | paint.setAntiAlias(antialias); |
| 2036 | for (int width = 0; width <= 4; ++width) { |
| 2037 | SkScalar offset = antialias * 100 + width * 20; |
| 2038 | paint.setStrokeWidth(width * 0.25f); |
| 2039 | canvas->drawLine(10 + offset, 10, 20 + offset, 60, paint); |
| 2040 | canvas->drawLine(10 + offset, 110, 60 + offset, 160, paint); |
| 2041 | } |
| 2042 | } |
| 2043 | } |
| 2044 | ## |
| 2045 | |
| 2046 | #Method SkScalar getStrokeWidth() const |
| 2047 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2048 | #In Stroke_Width |
| 2049 | #Line # returns thickness of the stroke ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2050 | Returns the thickness of the pen used by Paint to |
| 2051 | outline the shape. |
| 2052 | |
| 2053 | #Return zero for Hairline, greater than zero for pen thickness ## |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2054 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2055 | #Example |
| 2056 | SkPaint paint; |
| 2057 | SkDebugf("0 %c= paint.getStrokeWidth()\n", 0 == paint.getStrokeWidth() ? '=' : '!'); |
| 2058 | |
| 2059 | #StdOut |
| 2060 | 0 == paint.getStrokeWidth() |
| 2061 | ## |
| 2062 | ## |
| 2063 | |
| 2064 | ## |
| 2065 | |
| 2066 | #Method void setStrokeWidth(SkScalar width) |
| 2067 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2068 | #In Stroke_Width |
| 2069 | #Line # sets thickness of the stroke ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2070 | Sets the thickness of the pen used by the paint to |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2071 | outline the shape. |
| 2072 | Has no effect if width is less than zero. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2073 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2074 | #Param width zero thickness for Hairline; greater than zero for pen thickness |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2075 | ## |
| 2076 | |
| 2077 | #Example |
| 2078 | SkPaint paint; |
| 2079 | paint.setStrokeWidth(5); |
| 2080 | paint.setStrokeWidth(-1); |
| 2081 | SkDebugf("5 %c= paint.getStrokeWidth()\n", 5 == paint.getStrokeWidth() ? '=' : '!'); |
| 2082 | |
| 2083 | #StdOut |
| 2084 | 5 == paint.getStrokeWidth() |
| 2085 | ## |
| 2086 | ## |
| 2087 | |
| 2088 | ## |
| 2089 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2090 | #Subtopic Stroke_Width ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2091 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2092 | #Subtopic Miter_Limit |
| 2093 | #Line # maximum length of stroked corners ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2094 | |
| 2095 | Miter_Limit specifies the maximum miter length, |
| 2096 | relative to the stroke width. |
| 2097 | |
| 2098 | Miter_Limit is used when the Stroke_Join |
| 2099 | is set to kMiter_Join, and the Style is either kStroke_Style |
| 2100 | or kStrokeAndFill_Style. |
| 2101 | |
| 2102 | If the miter at a corner exceeds this limit, kMiter_Join |
| 2103 | is replaced with kBevel_Join. |
| 2104 | |
Cary Clark | 2be81cf | 2018-09-13 12:04:30 -0400 | [diff] [blame] | 2105 | Miter_Limit can be computed from the corner angle using: |
| 2106 | #Formula # miter limit = 1 / sin ( angle / 2 ) ##. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2107 | |
| 2108 | Miter_Limit default value is 4. |
| 2109 | The default may be changed at compile time by setting SkPaintDefaults_MiterLimit |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2110 | in "SkUserConfig.h" or as a define supplied by the build environment. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2111 | |
| 2112 | Here are some miter limits and the angles that triggers them. |
| 2113 | #Table |
| 2114 | #Legend |
| 2115 | # miter limit # angle in degrees ## |
| 2116 | #Legend ## |
| 2117 | # 10 # 11.48 ## |
| 2118 | # 9 # 12.76 ## |
| 2119 | # 8 # 14.36 ## |
| 2120 | # 7 # 16.43 ## |
| 2121 | # 6 # 19.19 ## |
| 2122 | # 5 # 23.07 ## |
| 2123 | # 4 # 28.96 ## |
| 2124 | # 3 # 38.94 ## |
| 2125 | # 2 # 60 ## |
| 2126 | # 1 # 180 ## |
| 2127 | #Table ## |
| 2128 | |
| 2129 | #Example |
| 2130 | #Height 170 |
| 2131 | #Width 384 |
| 2132 | #Description |
| 2133 | This example draws a stroked corner and the miter length beneath. |
| 2134 | When the miter limit is decreased slightly, the miter join is replaced |
| 2135 | by a bevel join. |
| 2136 | ## |
| 2137 | void draw(SkCanvas* canvas) { |
| 2138 | SkPoint pts[] = {{ 10, 50 }, { 110, 80 }, { 10, 110 }}; |
| 2139 | SkVector v[] = { pts[0] - pts[1], pts[2] - pts[1] }; |
| 2140 | SkScalar angle1 = SkScalarATan2(v[0].fY, v[0].fX); |
| 2141 | SkScalar angle2 = SkScalarATan2(v[1].fY, v[1].fX); |
| 2142 | const SkScalar strokeWidth = 20; |
| 2143 | SkScalar miterLimit = 1 / SkScalarSin((angle2 - angle1) / 2); |
| 2144 | SkScalar miterLength = strokeWidth * miterLimit; |
| 2145 | SkPath path; |
| 2146 | path.moveTo(pts[0]); |
| 2147 | path.lineTo(pts[1]); |
| 2148 | path.lineTo(pts[2]); |
| 2149 | SkPaint paint; // set to default kMiter_Join |
| 2150 | paint.setAntiAlias(true); |
| 2151 | paint.setStyle(SkPaint::kStroke_Style); |
| 2152 | paint.setStrokeMiter(miterLimit); |
| 2153 | paint.setStrokeWidth(strokeWidth); |
| 2154 | canvas->drawPath(path, paint); |
| 2155 | paint.setStrokeWidth(1); |
| 2156 | canvas->drawLine(pts[1].fX - miterLength / 2, pts[1].fY + 50, |
| 2157 | pts[1].fX + miterLength / 2, pts[1].fY + 50, paint); |
| 2158 | canvas->translate(200, 0); |
| 2159 | miterLimit *= 0.99f; |
| 2160 | paint.setStrokeMiter(miterLimit); |
| 2161 | paint.setStrokeWidth(strokeWidth); |
| 2162 | canvas->drawPath(path, paint); |
| 2163 | paint.setStrokeWidth(1); |
| 2164 | canvas->drawLine(pts[1].fX - miterLength / 2, pts[1].fY + 50, |
| 2165 | pts[1].fX + miterLength / 2, pts[1].fY + 50, paint); |
| 2166 | } |
| 2167 | ## |
| 2168 | |
| 2169 | #Method SkScalar getStrokeMiter() const |
| 2170 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2171 | #In Miter_Limit |
| 2172 | #Line # returns Miter_Limit, angles with sharp corners ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2173 | Returns the limit at which a sharp corner is drawn beveled. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2174 | |
| 2175 | #Return zero and greater Miter_Limit ## |
| 2176 | |
| 2177 | #Example |
| 2178 | SkPaint paint; |
| 2179 | SkDebugf("default miter limit == %g\n", paint.getStrokeMiter()); |
| 2180 | |
| 2181 | #StdOut |
| 2182 | default miter limit == 4 |
| 2183 | ## |
| 2184 | ## |
| 2185 | |
| 2186 | #SeeAlso Miter_Limit setStrokeMiter Join |
| 2187 | |
| 2188 | ## |
| 2189 | |
| 2190 | #Method void setStrokeMiter(SkScalar miter) |
| 2191 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2192 | #In Miter_Limit |
| 2193 | #Line # sets Miter_Limit, angles with sharp corners ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2194 | Sets the limit at which a sharp corner is drawn beveled. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2195 | Valid values are zero and greater. |
| 2196 | Has no effect if miter is less than zero. |
| 2197 | |
| 2198 | #Param miter zero and greater Miter_Limit |
| 2199 | ## |
| 2200 | |
| 2201 | #Example |
| 2202 | SkPaint paint; |
| 2203 | paint.setStrokeMiter(8); |
| 2204 | paint.setStrokeMiter(-1); |
| 2205 | SkDebugf("default miter limit == %g\n", paint.getStrokeMiter()); |
| 2206 | |
| 2207 | #StdOut |
| 2208 | default miter limit == 8 |
| 2209 | ## |
| 2210 | ## |
| 2211 | |
| 2212 | #SeeAlso Miter_Limit getStrokeMiter Join |
| 2213 | |
| 2214 | ## |
| 2215 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2216 | #Subtopic Miter_Limit ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2217 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2218 | #Subtopic Stroke_Cap |
| 2219 | #Line # decorations at ends of open strokes ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2220 | |
| 2221 | #Enum Cap |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2222 | #Line # start and end geometry on stroked shapes ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2223 | |
| 2224 | #Code |
| 2225 | enum Cap { |
| 2226 | kButt_Cap, |
| 2227 | kRound_Cap, |
| 2228 | kSquare_Cap, |
| 2229 | |
| 2230 | kLast_Cap = kSquare_Cap, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2231 | kDefault_Cap = kButt_Cap, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2232 | }; |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 2233 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2234 | static constexpr int kCapCount = kLast_Cap + 1; |
| 2235 | ## |
| 2236 | |
| 2237 | Stroke_Cap draws at the beginning and end of an open Path_Contour. |
| 2238 | |
| 2239 | #Const kButt_Cap 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2240 | #Line # no stroke extension ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2241 | Does not extend the stroke past the beginning or the end. |
| 2242 | ## |
| 2243 | #Const kRound_Cap 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2244 | #Line # adds circle ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2245 | Adds a circle with a diameter equal to Stroke_Width at the beginning |
| 2246 | and end. |
| 2247 | ## |
| 2248 | #Const kSquare_Cap 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2249 | #Line # adds square ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2250 | Adds a square with sides equal to Stroke_Width at the beginning |
| 2251 | and end. The square sides are parallel to the initial and final direction |
| 2252 | of the stroke. |
| 2253 | ## |
| 2254 | #Const kLast_Cap 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2255 | #Line # largest Stroke_Cap value ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2256 | Equivalent to the largest value for Stroke_Cap. |
| 2257 | ## |
| 2258 | #Const kDefault_Cap 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2259 | #Line # equivalent to kButt_Cap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2260 | Stroke_Cap is set to kButt_Cap by default. |
| 2261 | ## |
| 2262 | |
| 2263 | #Const kCapCount 3 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2264 | #Line # number of different Stroke_Cap values defined ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2265 | May be used to verify that Stroke_Cap is a legal value. |
| 2266 | ## |
| 2267 | #Enum ## |
| 2268 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2269 | Stroke describes the area covered by a pen of Stroke_Width as it |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2270 | follows the Path_Contour, moving parallel to the contour direction. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2271 | |
| 2272 | If the Path_Contour is not terminated by SkPath::kClose_Verb, the contour has a |
| 2273 | visible beginning and end. |
| 2274 | |
| 2275 | Path_Contour may start and end at the same point; defining Zero_Length_Contour. |
| 2276 | |
| 2277 | kButt_Cap and Zero_Length_Contour is not drawn. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2278 | kRound_Cap and Zero_Length_Contour draws a circle of diameter Stroke_Width |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2279 | at the contour point. |
| 2280 | kSquare_Cap and Zero_Length_Contour draws an upright square with a side of |
| 2281 | Stroke_Width at the contour point. |
| 2282 | |
| 2283 | Stroke_Cap is kButt_Cap by default. |
| 2284 | |
| 2285 | #Example |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2286 | #Height 200 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2287 | SkPaint paint; |
| 2288 | paint.setStyle(SkPaint::kStroke_Style); |
| 2289 | paint.setStrokeWidth(20); |
| 2290 | SkPath path; |
| 2291 | path.moveTo(30, 30); |
| 2292 | path.lineTo(30, 30); |
| 2293 | path.moveTo(70, 30); |
| 2294 | path.lineTo(90, 40); |
| 2295 | for (SkPaint::Cap c : { SkPaint::kButt_Cap, SkPaint::kRound_Cap, SkPaint::kSquare_Cap } ) { |
| 2296 | paint.setStrokeCap(c); |
| 2297 | canvas->drawPath(path, paint); |
| 2298 | canvas->translate(0, 70); |
| 2299 | } |
| 2300 | ## |
| 2301 | |
| 2302 | #Method Cap getStrokeCap() const |
| 2303 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2304 | #In Stroke_Cap |
| 2305 | #Line # returns Cap, the area drawn at path ends ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2306 | Returns the geometry drawn at the beginning and end of strokes. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2307 | |
| 2308 | #Return one of: kButt_Cap, kRound_Cap, kSquare_Cap ## |
| 2309 | |
| 2310 | #Example |
| 2311 | SkPaint paint; |
| 2312 | SkDebugf("kButt_Cap %c= default stroke cap\n", |
| 2313 | SkPaint::kButt_Cap == paint.getStrokeCap() ? '=' : '!'); |
| 2314 | |
| 2315 | #StdOut |
| 2316 | kButt_Cap == default stroke cap |
| 2317 | ## |
| 2318 | ## |
| 2319 | |
| 2320 | #SeeAlso Stroke_Cap setStrokeCap |
| 2321 | ## |
| 2322 | |
| 2323 | #Method void setStrokeCap(Cap cap) |
| 2324 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2325 | #In Stroke_Cap |
| 2326 | #Line # sets Cap, the area drawn at path ends ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2327 | Sets the geometry drawn at the beginning and end of strokes. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2328 | |
| 2329 | #Param cap one of: kButt_Cap, kRound_Cap, kSquare_Cap; |
| 2330 | has no effect if cap is not valid |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2331 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2332 | |
| 2333 | #Example |
| 2334 | SkPaint paint; |
| 2335 | paint.setStrokeCap(SkPaint::kRound_Cap); |
| 2336 | paint.setStrokeCap((SkPaint::Cap) SkPaint::kCapCount); |
| 2337 | SkDebugf("kRound_Cap %c= paint.getStrokeCap()\n", |
| 2338 | SkPaint::kRound_Cap == paint.getStrokeCap() ? '=' : '!'); |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2339 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2340 | #StdOut |
| 2341 | kRound_Cap == paint.getStrokeCap() |
| 2342 | ## |
| 2343 | ## |
| 2344 | |
| 2345 | #SeeAlso Stroke_Cap getStrokeCap |
| 2346 | ## |
| 2347 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2348 | #Subtopic Stroke_Cap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2349 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2350 | #Subtopic Stroke_Join |
| 2351 | #Line # decoration at corners of strokes ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2352 | |
| 2353 | Stroke_Join draws at the sharp corners of an open or closed Path_Contour. |
| 2354 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2355 | Stroke describes the area covered by a pen of Stroke_Width as it |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2356 | follows the Path_Contour, moving parallel to the contour direction. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2357 | |
| 2358 | If the contour direction changes abruptly, because the tangent direction leading |
| 2359 | to the end of a curve within the contour does not match the tangent direction of |
| 2360 | the following curve, the pair of curves meet at Stroke_Join. |
| 2361 | |
| 2362 | #Example |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2363 | #Height 200 |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2364 | SkPaint paint; |
| 2365 | paint.setStyle(SkPaint::kStroke_Style); |
| 2366 | paint.setStrokeWidth(20); |
| 2367 | SkPath path; |
| 2368 | path.moveTo(30, 20); |
| 2369 | path.lineTo(40, 40); |
| 2370 | path.conicTo(70, 20, 100, 20, .707f); |
| 2371 | for (SkPaint::Join j : { SkPaint::kMiter_Join, SkPaint::kRound_Join, SkPaint::kBevel_Join } ) { |
| 2372 | paint.setStrokeJoin(j); |
| 2373 | canvas->drawPath(path, paint); |
| 2374 | canvas->translate(0, 70); |
| 2375 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2376 | ## |
| 2377 | |
| 2378 | #Enum Join |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2379 | #Line # corner geometry on stroked shapes ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2380 | #Code |
| 2381 | enum Join { |
| 2382 | kMiter_Join, |
| 2383 | kRound_Join, |
| 2384 | kBevel_Join, |
| 2385 | |
| 2386 | kLast_Join = kBevel_Join, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2387 | kDefault_Join = kMiter_Join, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2388 | }; |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 2389 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2390 | static constexpr int kJoinCount = kLast_Join + 1; |
| 2391 | ## |
| 2392 | |
Cary Clark | 1eace2d | 2017-07-31 07:52:43 -0400 | [diff] [blame] | 2393 | Join specifies how corners are drawn when a shape is stroked. Join |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2394 | affects the four corners of a stroked rectangle, and the connected segments in a |
| 2395 | stroked path. |
| 2396 | |
| 2397 | Choose miter join to draw sharp corners. Choose round join to draw a circle with a |
| 2398 | radius equal to the stroke width on top of the corner. Choose bevel join to minimally |
| 2399 | connect the thick strokes. |
| 2400 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2401 | The fill path constructed to describe the stroked path respects the join setting but may |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2402 | not contain the actual join. For instance, a fill path constructed with round joins does |
| 2403 | not necessarily include circles at each connected segment. |
| 2404 | |
| 2405 | #Const kMiter_Join 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2406 | #Line # extends to Miter_Limit ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2407 | Extends the outside corner to the extent allowed by Miter_Limit. |
| 2408 | If the extension exceeds Miter_Limit, kBevel_Join is used instead. |
| 2409 | ## |
| 2410 | |
| 2411 | #Const kRound_Join 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2412 | #Line # adds circle ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2413 | Adds a circle with a diameter of Stroke_Width at the sharp corner. |
| 2414 | ## |
| 2415 | |
| 2416 | #Const kBevel_Join 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2417 | #Line # connects outside edges ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2418 | Connects the outside edges of the sharp corner. |
| 2419 | ## |
| 2420 | |
| 2421 | #Const kLast_Join 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2422 | #Line # equivalent to the largest value for Stroke_Join ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2423 | ## |
| 2424 | |
| 2425 | #Const kDefault_Join 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2426 | #Line # equivalent to kMiter_Join ## |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2427 | Stroke_Join is set to kMiter_Join by default. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2428 | ## |
| 2429 | |
| 2430 | #Const kJoinCount 3 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2431 | #Line # number of different Stroke_Join values defined ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2432 | May be used to verify that Stroke_Join is a legal value. |
| 2433 | ## |
| 2434 | |
| 2435 | #Example |
| 2436 | #Width 462 |
| 2437 | void draw(SkCanvas* canvas) { |
| 2438 | SkPath path; |
| 2439 | path.moveTo(10, 50); |
| 2440 | path.quadTo(35, 110, 60, 210); |
| 2441 | path.quadTo(105, 110, 130, 10); |
| 2442 | SkPaint paint; // set to default kMiter_Join |
| 2443 | paint.setAntiAlias(true); |
| 2444 | paint.setStyle(SkPaint::kStroke_Style); |
| 2445 | paint.setStrokeWidth(20); |
| 2446 | canvas->drawPath(path, paint); |
| 2447 | canvas->translate(150, 0); |
| 2448 | paint.setStrokeJoin(SkPaint::kBevel_Join); |
| 2449 | canvas->drawPath(path, paint); |
| 2450 | canvas->translate(150, 0); |
| 2451 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 2452 | canvas->drawPath(path, paint); |
| 2453 | } |
| 2454 | ## |
| 2455 | |
| 2456 | #SeeAlso setStrokeJoin getStrokeJoin setStrokeMiter getStrokeMiter |
| 2457 | |
| 2458 | #Enum ## |
| 2459 | |
| 2460 | #Method Join getStrokeJoin() const |
| 2461 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2462 | #In Stroke_Join |
| 2463 | #Line # returns Join, geometry on path corners ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2464 | Returns the geometry drawn at the corners of strokes. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2465 | |
| 2466 | #Return one of: kMiter_Join, kRound_Join, kBevel_Join ## |
| 2467 | |
| 2468 | #Example |
| 2469 | SkPaint paint; |
| 2470 | SkDebugf("kMiter_Join %c= default stroke join\n", |
| 2471 | SkPaint::kMiter_Join == paint.getStrokeJoin() ? '=' : '!'); |
| 2472 | |
| 2473 | #StdOut |
| 2474 | kMiter_Join == default stroke join |
| 2475 | ## |
| 2476 | ## |
| 2477 | |
| 2478 | #SeeAlso Stroke_Join setStrokeJoin |
| 2479 | ## |
| 2480 | |
| 2481 | #Method void setStrokeJoin(Join join) |
| 2482 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2483 | #In Stroke_Join |
| 2484 | #Line # sets Join, geometry on path corners ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2485 | Sets the geometry drawn at the corners of strokes. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2486 | |
| 2487 | #Param join one of: kMiter_Join, kRound_Join, kBevel_Join; |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2488 | otherwise, has no effect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2489 | ## |
| 2490 | |
| 2491 | #Example |
| 2492 | SkPaint paint; |
| 2493 | paint.setStrokeJoin(SkPaint::kMiter_Join); |
| 2494 | paint.setStrokeJoin((SkPaint::Join) SkPaint::kJoinCount); |
| 2495 | SkDebugf("kMiter_Join %c= paint.getStrokeJoin()\n", |
| 2496 | SkPaint::kMiter_Join == paint.getStrokeJoin() ? '=' : '!'); |
| 2497 | |
| 2498 | #StdOut |
| 2499 | kMiter_Join == paint.getStrokeJoin() |
| 2500 | ## |
| 2501 | ## |
| 2502 | |
| 2503 | #SeeAlso Stroke_Join getStrokeJoin |
| 2504 | ## |
| 2505 | |
| 2506 | #SeeAlso Miter_Limit |
| 2507 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2508 | #Subtopic Stroke_Join ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2509 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2510 | #Subtopic Fill_Path |
| 2511 | #Line # make Path from Path_Effect, stroking ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2512 | |
| 2513 | Fill_Path creates a Path by applying the Path_Effect, followed by the Style_Stroke. |
| 2514 | |
| 2515 | If Paint contains Path_Effect, Path_Effect operates on the source Path; the result |
| 2516 | replaces the destination Path. Otherwise, the source Path is replaces the |
| 2517 | destination Path. |
| 2518 | |
| 2519 | Fill Path can request the Path_Effect to restrict to a culling rectangle, but |
| 2520 | the Path_Effect is not required to do so. |
| 2521 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2522 | If Style is kStroke_Style or kStrokeAndFill_Style, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2523 | and Stroke_Width is greater than zero, the Stroke_Width, Stroke_Cap, Stroke_Join, |
| 2524 | and Miter_Limit operate on the destination Path, replacing it. |
| 2525 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2526 | Fill Path can specify the precision used by Stroke_Width to approximate the stroke geometry. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2527 | |
| 2528 | If the Style is kStroke_Style and the Stroke_Width is zero, getFillPath |
| 2529 | returns false since Hairline has no filled equivalent. |
| 2530 | |
| 2531 | #Method bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect, |
| 2532 | SkScalar resScale = 1) const |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2533 | #In Fill_Path |
| 2534 | #Line # returns fill path equivalent to stroke ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2535 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2536 | Returns the filled equivalent of the stroked path. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2537 | |
| 2538 | #Param src Path read to create a filled version ## |
| 2539 | #Param dst resulting Path; may be the same as src, but may not be nullptr ## |
| 2540 | #Param cullRect optional limit passed to Path_Effect ## |
| 2541 | #Param resScale if > 1, increase precision, else if (0 < res < 1) reduce precision |
| 2542 | to favor speed and size |
| 2543 | ## |
| 2544 | #Return true if the path represents Style_Fill, or false if it represents Hairline ## |
| 2545 | |
| 2546 | #Example |
| 2547 | #Height 192 |
| 2548 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2549 | A very small Quad stroke is turned into a filled path with increasing levels of precision. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2550 | At the lowest precision, the Quad stroke is approximated by a rectangle. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2551 | At the highest precision, the filled path has high fidelity compared to the original stroke. |
| 2552 | ## |
| 2553 | void draw(SkCanvas* canvas) { |
| 2554 | SkPaint strokePaint; |
| 2555 | strokePaint.setAntiAlias(true); |
| 2556 | strokePaint.setStyle(SkPaint::kStroke_Style); |
| 2557 | strokePaint.setStrokeWidth(.1f); |
| 2558 | SkPath strokePath; |
| 2559 | strokePath.moveTo(.08f, .08f); |
| 2560 | strokePath.quadTo(.09f, .08f, .17f, .17f); |
| 2561 | SkPath fillPath; |
| 2562 | SkPaint outlinePaint(strokePaint); |
| 2563 | outlinePaint.setStrokeWidth(2); |
| 2564 | SkMatrix scale = SkMatrix::MakeScale(300, 300); |
| 2565 | for (SkScalar precision : { 0.01f, .1f, 1.f, 10.f, 100.f } ) { |
| 2566 | strokePaint.getFillPath(strokePath, &fillPath, nullptr, precision); |
| 2567 | fillPath.transform(scale); |
| 2568 | canvas->drawPath(fillPath, outlinePaint); |
| 2569 | canvas->translate(60, 0); |
| 2570 | if (1.f == precision) canvas->translate(-180, 100); |
| 2571 | } |
| 2572 | strokePath.transform(scale); |
| 2573 | strokePaint.setStrokeWidth(30); |
| 2574 | canvas->drawPath(strokePath, strokePaint); |
| 2575 | } |
| 2576 | ## |
| 2577 | |
| 2578 | ## |
| 2579 | |
| 2580 | #Method bool getFillPath(const SkPath& src, SkPath* dst) const |
| 2581 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2582 | #In Fill_Path |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2583 | Returns the filled equivalent of the stroked path. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2584 | |
| 2585 | Replaces dst with the src path modified by Path_Effect and Style_Stroke. |
| 2586 | Path_Effect, if any, is not culled. Stroke_Width is created with default precision. |
| 2587 | |
| 2588 | #Param src Path read to create a filled version ## |
| 2589 | #Param dst resulting Path dst may be the same as src, but may not be nullptr ## |
| 2590 | #Return true if the path represents Style_Fill, or false if it represents Hairline ## |
| 2591 | |
| 2592 | #Example |
| 2593 | #Height 128 |
| 2594 | void draw(SkCanvas* canvas) { |
| 2595 | SkPaint paint; |
| 2596 | paint.setStyle(SkPaint::kStroke_Style); |
| 2597 | paint.setStrokeWidth(10); |
| 2598 | SkPath strokePath; |
| 2599 | strokePath.moveTo(20, 20); |
| 2600 | strokePath.lineTo(100, 100); |
| 2601 | canvas->drawPath(strokePath, paint); |
| 2602 | SkPath fillPath; |
| 2603 | paint.getFillPath(strokePath, &fillPath); |
| 2604 | paint.setStrokeWidth(2); |
| 2605 | canvas->translate(40, 0); |
| 2606 | canvas->drawPath(fillPath, paint); |
| 2607 | } |
| 2608 | ## |
| 2609 | |
| 2610 | ## |
| 2611 | |
| 2612 | #SeeAlso Style_Stroke Stroke_Width Path_Effect |
| 2613 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2614 | #Subtopic Fill_Path ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2615 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2616 | #Subtopic Shader_Methods |
| 2617 | #Line # get and set Shader ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2618 | |
| 2619 | Shader defines the colors used when drawing a shape. |
| 2620 | Shader may be an image, a gradient, or a computed fill. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2621 | If Paint has no Shader, then Color fills the shape. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2622 | |
| 2623 | Shader is modulated by Color_Alpha component of Color. |
| 2624 | If Shader object defines only Color_Alpha, then Color modulated by Color_Alpha describes |
| 2625 | the fill. |
| 2626 | |
| 2627 | The drawn transparency can be modified without altering Shader, by changing Color_Alpha. |
| 2628 | |
| 2629 | #Example |
| 2630 | void draw(SkCanvas* canvas) { |
| 2631 | SkPaint paint; |
| 2632 | SkPoint center = { 50, 50 }; |
| 2633 | SkScalar radius = 50; |
| 2634 | const SkColor colors[] = { 0xFFFFFFFF, 0xFF000000 }; |
| 2635 | paint.setShader(SkGradientShader::MakeRadial(center, radius, colors, |
| 2636 | nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode)); |
| 2637 | for (SkScalar a : { 0.3f, 0.6f, 1.0f } ) { |
| 2638 | paint.setAlpha((int) (a * 255)); |
| 2639 | canvas->drawCircle(center.fX, center.fY, radius, paint); |
| 2640 | canvas->translate(70, 70); |
| 2641 | } |
| 2642 | } |
| 2643 | ## |
| 2644 | |
| 2645 | If Shader generates only Color_Alpha then all components of Color modulate the output. |
| 2646 | |
| 2647 | #Example |
| 2648 | void draw(SkCanvas* canvas) { |
| 2649 | SkPaint paint; |
| 2650 | SkBitmap bitmap; |
| 2651 | bitmap.setInfo(SkImageInfo::MakeA8(5, 1), 5); // bitmap only contains alpha |
| 2652 | uint8_t pixels[5] = { 0x22, 0x55, 0x88, 0xBB, 0xFF }; |
| 2653 | bitmap.setPixels(pixels); |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2654 | paint.setShader(SkShader::MakeBitmapShader(bitmap, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2655 | SkShader::kMirror_TileMode, SkShader::kMirror_TileMode)); |
| 2656 | for (SkColor c : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 2657 | paint.setColor(c); // all components in color affect shader |
| 2658 | canvas->drawCircle(50, 50, 50, paint); |
| 2659 | canvas->translate(70, 70); |
| 2660 | } |
| 2661 | } |
| 2662 | ## |
| 2663 | |
| 2664 | #Method SkShader* getShader() const |
| 2665 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2666 | #In Shader_Methods |
| 2667 | #Line # returns Shader, multiple drawing colors; gradients ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2668 | Returns optional colors used when filling a path, such as a gradient. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2669 | |
| 2670 | Does not alter Shader Reference_Count. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2671 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2672 | #Return Shader if previously set, nullptr otherwise ## |
| 2673 | |
| 2674 | #Example |
| 2675 | void draw(SkCanvas* canvas) { |
| 2676 | SkPaint paint; |
| 2677 | SkDebugf("nullptr %c= shader\n", paint.getShader() ? '!' : '='); |
| 2678 | paint.setShader(SkShader::MakeEmptyShader()); |
| 2679 | SkDebugf("nullptr %c= shader\n", paint.getShader() ? '!' : '='); |
| 2680 | } |
| 2681 | |
| 2682 | #StdOut |
| 2683 | nullptr == shader |
| 2684 | nullptr != shader |
| 2685 | ## |
| 2686 | ## |
| 2687 | |
| 2688 | ## |
| 2689 | |
| 2690 | #Method sk_sp<SkShader> refShader() const |
| 2691 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2692 | #In Shader_Methods |
| 2693 | #Line # references Shader, multiple drawing colors; gradients ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2694 | Returns optional colors used when filling a path, such as a gradient. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2695 | |
| 2696 | Increases Shader Reference_Count by one. |
| 2697 | |
| 2698 | #Return Shader if previously set, nullptr otherwise ## |
| 2699 | |
| 2700 | #Example |
| 2701 | void draw(SkCanvas* canvas) { |
| 2702 | SkPaint paint1, paint2; |
| 2703 | paint1.setShader(SkShader::MakeEmptyShader()); |
| 2704 | SkDebugf("shader unique: %s\n", paint1.getShader()->unique() ? "true" : "false"); |
| 2705 | paint2.setShader(paint1.refShader()); |
| 2706 | SkDebugf("shader unique: %s\n", paint1.getShader()->unique() ? "true" : "false"); |
| 2707 | } |
| 2708 | |
| 2709 | #StdOut |
| 2710 | shader unique: true |
| 2711 | shader unique: false |
| 2712 | ## |
| 2713 | ## |
| 2714 | |
| 2715 | ## |
| 2716 | |
| 2717 | #Method void setShader(sk_sp<SkShader> shader) |
| 2718 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2719 | #In Shader_Methods |
| 2720 | #Line # sets Shader, multiple drawing colors; gradients ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2721 | Sets optional colors used when filling a path, such as a gradient. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2722 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 2723 | Sets Shader to shader, decreasing Reference_Count of the previous Shader. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 2724 | Increments shader Reference_Count by one. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2725 | |
| 2726 | #Param shader how geometry is filled with color; if nullptr, Color is used instead ## |
| 2727 | |
| 2728 | #Example |
| 2729 | #Height 64 |
| 2730 | void draw(SkCanvas* canvas) { |
| 2731 | SkPaint paint; |
| 2732 | paint.setColor(SK_ColorBLUE); |
| 2733 | paint.setShader(SkShader::MakeColorShader(SK_ColorRED)); |
| 2734 | canvas->drawRect(SkRect::MakeWH(40, 40), paint); |
| 2735 | paint.setShader(nullptr); |
| 2736 | canvas->translate(50, 0); |
| 2737 | canvas->drawRect(SkRect::MakeWH(40, 40), paint); |
| 2738 | } |
| 2739 | ## |
| 2740 | |
| 2741 | ## |
| 2742 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2743 | #Subtopic Shader_Methods ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2744 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2745 | #Subtopic Color_Filter_Methods |
| 2746 | #Line # get and set Color_Filter ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2747 | |
| 2748 | Color_Filter alters the color used when drawing a shape. |
| 2749 | Color_Filter may apply Blend_Mode, transform the color through a matrix, or composite multiple filters. |
| 2750 | If Paint has no Color_Filter, the color is unaltered. |
| 2751 | |
| 2752 | The drawn transparency can be modified without altering Color_Filter, by changing Color_Alpha. |
| 2753 | |
| 2754 | #Example |
| 2755 | #Height 128 |
| 2756 | void draw(SkCanvas* canvas) { |
| 2757 | SkPaint paint; |
| 2758 | paint.setColorFilter(SkColorMatrixFilter::MakeLightingFilter(0xFFFFFF, 0xFF0000)); |
| 2759 | for (SkColor c : { SK_ColorBLACK, SK_ColorGREEN } ) { |
| 2760 | paint.setColor(c); |
| 2761 | canvas->drawRect(SkRect::MakeXYWH(10, 10, 50, 50), paint); |
| 2762 | paint.setAlpha(0x80); |
| 2763 | canvas->drawRect(SkRect::MakeXYWH(60, 60, 50, 50), paint); |
| 2764 | canvas->translate(100, 0); |
| 2765 | } |
| 2766 | } |
| 2767 | ## |
| 2768 | |
| 2769 | #Method SkColorFilter* getColorFilter() const |
| 2770 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2771 | #In Color_Filter_Methods |
| 2772 | #Line # returns Color_Filter, how colors are altered ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2773 | Returns Color_Filter if set, or nullptr. |
| 2774 | Does not alter Color_Filter Reference_Count. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2775 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2776 | #Return Color_Filter if previously set, nullptr otherwise ## |
| 2777 | |
| 2778 | #Example |
| 2779 | void draw(SkCanvas* canvas) { |
| 2780 | SkPaint paint; |
| 2781 | SkDebugf("nullptr %c= color filter\n", paint.getColorFilter() ? '!' : '='); |
| 2782 | paint.setColorFilter(SkColorFilter::MakeModeFilter(SK_ColorLTGRAY, SkBlendMode::kSrcIn)); |
| 2783 | SkDebugf("nullptr %c= color filter\n", paint.getColorFilter() ? '!' : '='); |
| 2784 | } |
| 2785 | |
| 2786 | #StdOut |
| 2787 | nullptr == color filter |
| 2788 | nullptr != color filter |
| 2789 | ## |
| 2790 | ## |
| 2791 | ## |
| 2792 | |
| 2793 | #Method sk_sp<SkColorFilter> refColorFilter() const |
| 2794 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2795 | #In Color_Filter_Methods |
| 2796 | #Line # references Color_Filter, how colors are altered ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2797 | Returns Color_Filter if set, or nullptr. |
| 2798 | Increases Color_Filter Reference_Count by one. |
| 2799 | |
| 2800 | #Return Color_Filter if set, or nullptr ## |
| 2801 | |
| 2802 | #Example |
| 2803 | void draw(SkCanvas* canvas) { |
| 2804 | SkPaint paint1, paint2; |
| 2805 | paint1.setColorFilter(SkColorFilter::MakeModeFilter(0xFFFF0000, SkBlendMode::kSrcATop)); |
| 2806 | SkDebugf("color filter unique: %s\n", paint1.getColorFilter()->unique() ? "true" : "false"); |
| 2807 | paint2.setColorFilter(paint1.refColorFilter()); |
| 2808 | SkDebugf("color filter unique: %s\n", paint1.getColorFilter()->unique() ? "true" : "false"); |
| 2809 | } |
| 2810 | |
| 2811 | #StdOut |
| 2812 | color filter unique: true |
| 2813 | color filter unique: false |
| 2814 | ## |
| 2815 | ## |
| 2816 | ## |
| 2817 | |
| 2818 | #Method void setColorFilter(sk_sp<SkColorFilter> colorFilter) |
| 2819 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2820 | #In Color_Filter_Methods |
| 2821 | #Line # sets Color_Filter, alters color ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 2822 | Sets Color_Filter to filter, decreasing Reference_Count of the previous |
| 2823 | Color_Filter. Pass nullptr to clear Color_Filter. |
| 2824 | |
| 2825 | Increments filter Reference_Count by one. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2826 | |
| 2827 | #Param colorFilter Color_Filter to apply to subsequent draw ## |
| 2828 | |
| 2829 | #Example |
| 2830 | #Height 64 |
| 2831 | void draw(SkCanvas* canvas) { |
| 2832 | SkPaint paint; |
| 2833 | paint.setColorFilter(SkColorFilter::MakeModeFilter(SK_ColorLTGRAY, SkBlendMode::kSrcIn)); |
| 2834 | canvas->drawRect(SkRect::MakeWH(50, 50), paint); |
| 2835 | paint.setColorFilter(nullptr); |
| 2836 | canvas->translate(70, 0); |
| 2837 | canvas->drawRect(SkRect::MakeWH(50, 50), paint); |
| 2838 | } |
| 2839 | ## |
| 2840 | |
| 2841 | ## |
| 2842 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2843 | #Subtopic Color_Filter_Methods ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2844 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2845 | #Subtopic Blend_Mode_Methods |
| 2846 | #Line # get and set Blend_Mode ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2847 | |
| 2848 | Blend_Mode describes how Color combines with the destination color. |
| 2849 | The default setting, SkBlendMode::kSrcOver, draws the source color |
| 2850 | over the destination color. |
| 2851 | |
| 2852 | #Example |
| 2853 | void draw(SkCanvas* canvas) { |
| 2854 | SkPaint normal, blender; |
| 2855 | normal.setColor(0xFF58a889); |
| 2856 | blender.setColor(0xFF8958a8); |
| 2857 | canvas->clear(0); |
| 2858 | for (SkBlendMode m : { SkBlendMode::kSrcOver, SkBlendMode::kSrcIn, SkBlendMode::kSrcOut } ) { |
| 2859 | normal.setBlendMode(SkBlendMode::kSrcOver); |
| 2860 | canvas->drawOval(SkRect::MakeXYWH(30, 30, 30, 80), normal); |
| 2861 | blender.setBlendMode(m); |
| 2862 | canvas->drawOval(SkRect::MakeXYWH(10, 50, 80, 30), blender); |
| 2863 | canvas->translate(70, 70); |
| 2864 | } |
| 2865 | } |
| 2866 | ## |
| 2867 | |
| 2868 | #SeeAlso Blend_Mode |
| 2869 | |
| 2870 | #Method SkBlendMode getBlendMode() const |
| 2871 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2872 | #In Blend_Mode_Methods |
| 2873 | #Line # returns Blend_Mode, how colors combine with Device ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2874 | Returns Blend_Mode. |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 2875 | By default, returns SkBlendMode::kSrcOver. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2876 | |
| 2877 | #Return mode used to combine source color with destination color ## |
| 2878 | |
| 2879 | #Example |
| 2880 | void draw(SkCanvas* canvas) { |
| 2881 | SkPaint paint; |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2882 | SkDebugf("kSrcOver %c= getBlendMode\n", |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2883 | SkBlendMode::kSrcOver == paint.getBlendMode() ? '=' : '!'); |
| 2884 | paint.setBlendMode(SkBlendMode::kSrc); |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2885 | SkDebugf("kSrcOver %c= getBlendMode\n", |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2886 | SkBlendMode::kSrcOver == paint.getBlendMode() ? '=' : '!'); |
| 2887 | } |
| 2888 | |
| 2889 | #StdOut |
| 2890 | kSrcOver == getBlendMode |
| 2891 | kSrcOver != getBlendMode |
| 2892 | ## |
| 2893 | ## |
| 2894 | |
| 2895 | ## |
| 2896 | |
| 2897 | #Method bool isSrcOver() const |
| 2898 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2899 | #In Blend_Mode_Methods |
| 2900 | #Line # returns true if Blend_Mode is SkBlendMode::kSrcOver ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2901 | Returns true if Blend_Mode is SkBlendMode::kSrcOver, the default. |
| 2902 | |
| 2903 | #Return true if Blend_Mode is SkBlendMode::kSrcOver ## |
| 2904 | |
| 2905 | #Example |
| 2906 | void draw(SkCanvas* canvas) { |
| 2907 | SkPaint paint; |
| 2908 | SkDebugf("isSrcOver %c= true\n", paint.isSrcOver() ? '=' : '!'); |
| 2909 | paint.setBlendMode(SkBlendMode::kSrc); |
| 2910 | SkDebugf("isSrcOver %c= true\n", paint.isSrcOver() ? '=' : '!'); |
| 2911 | } |
| 2912 | |
| 2913 | #StdOut |
| 2914 | isSrcOver == true |
| 2915 | isSrcOver != true |
| 2916 | ## |
| 2917 | ## |
| 2918 | |
| 2919 | ## |
| 2920 | |
| 2921 | #Method void setBlendMode(SkBlendMode mode) |
| 2922 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2923 | #In Blend_Mode_Methods |
| 2924 | #Line # sets Blend_Mode, how colors combine with destination ## |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2925 | Sets Blend_Mode to mode. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2926 | Does not check for valid input. |
| 2927 | |
| 2928 | #Param mode SkBlendMode used to combine source color and destination ## |
| 2929 | |
| 2930 | #Example |
| 2931 | void draw(SkCanvas* canvas) { |
| 2932 | SkPaint paint; |
| 2933 | SkDebugf("isSrcOver %c= true\n", paint.isSrcOver() ? '=' : '!'); |
| 2934 | paint.setBlendMode(SkBlendMode::kSrc); |
| 2935 | SkDebugf("isSrcOver %c= true\n", paint.isSrcOver() ? '=' : '!'); |
| 2936 | } |
| 2937 | |
| 2938 | #StdOut |
| 2939 | isSrcOver == true |
| 2940 | isSrcOver != true |
| 2941 | ## |
| 2942 | ## |
| 2943 | |
| 2944 | ## |
| 2945 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2946 | #Subtopic Blend_Mode_Methods ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2947 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2948 | #Subtopic Path_Effect_Methods |
| 2949 | #Line # get and set Path_Effect ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2950 | |
| 2951 | Path_Effect modifies the path geometry before drawing it. |
| 2952 | Path_Effect may implement dashing, custom fill effects and custom stroke effects. |
| 2953 | If Paint has no Path_Effect, the path geometry is unaltered when filled or stroked. |
| 2954 | |
| 2955 | #Example |
| 2956 | #Height 160 |
| 2957 | void draw(SkCanvas* canvas) { |
| 2958 | SkPaint paint; |
| 2959 | paint.setStyle(SkPaint::kStroke_Style); |
| 2960 | paint.setStrokeWidth(16); |
| 2961 | SkScalar intervals[] = {30, 10}; |
| 2962 | paint.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 1)); |
| 2963 | canvas->drawRoundRect({20, 20, 120, 120}, 20, 20, paint); |
| 2964 | } |
| 2965 | ## |
| 2966 | |
| 2967 | #SeeAlso Path_Effect |
| 2968 | |
| 2969 | #Method SkPathEffect* getPathEffect() const |
| 2970 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2971 | #In Path_Effect_Methods |
| 2972 | #Line # returns Path_Effect, modifications to path geometry; dashing ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2973 | Returns Path_Effect if set, or nullptr. |
| 2974 | Does not alter Path_Effect Reference_Count. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 2975 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2976 | #Return Path_Effect if previously set, nullptr otherwise ## |
| 2977 | |
| 2978 | #Example |
| 2979 | void draw(SkCanvas* canvas) { |
| 2980 | SkPaint paint; |
| 2981 | SkDebugf("nullptr %c= path effect\n", paint.getPathEffect() ? '!' : '='); |
| 2982 | paint.setPathEffect(SkCornerPathEffect::Make(10)); |
| 2983 | SkDebugf("nullptr %c= path effect\n", paint.getPathEffect() ? '!' : '='); |
| 2984 | } |
| 2985 | |
| 2986 | #StdOut |
| 2987 | nullptr == path effect |
| 2988 | nullptr != path effect |
| 2989 | ## |
| 2990 | ## |
| 2991 | |
| 2992 | ## |
| 2993 | |
| 2994 | |
| 2995 | #Method sk_sp<SkPathEffect> refPathEffect() const |
| 2996 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2997 | #In Path_Effect_Methods |
| 2998 | #Line # references Path_Effect, modifications to path geometry; dashing ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2999 | Returns Path_Effect if set, or nullptr. |
| 3000 | Increases Path_Effect Reference_Count by one. |
| 3001 | |
| 3002 | #Return Path_Effect if previously set, nullptr otherwise ## |
| 3003 | |
| 3004 | #Example |
| 3005 | void draw(SkCanvas* canvas) { |
| 3006 | SkPaint paint1, paint2; |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 3007 | SkScalar intervals[] = {1, 2}; |
| 3008 | paint1.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 10)); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3009 | SkDebugf("path effect unique: %s\n", paint1.getPathEffect()->unique() ? "true" : "false"); |
| 3010 | paint2.setPathEffect(paint1.refPathEffect()); |
| 3011 | SkDebugf("path effect unique: %s\n", paint1.getPathEffect()->unique() ? "true" : "false"); |
| 3012 | } |
| 3013 | |
| 3014 | #StdOut |
| 3015 | path effect unique: true |
| 3016 | path effect unique: false |
| 3017 | ## |
| 3018 | ## |
| 3019 | |
| 3020 | ## |
| 3021 | |
| 3022 | |
| 3023 | #Method void setPathEffect(sk_sp<SkPathEffect> pathEffect) |
| 3024 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3025 | #In Path_Effect_Methods |
| 3026 | #Line # sets Path_Effect, modifications to path geometry; dashing ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 3027 | Sets Path_Effect to pathEffect, decreasing Reference_Count of the previous |
| 3028 | Path_Effect. Pass nullptr to leave the path geometry unaltered. |
| 3029 | |
| 3030 | Increments pathEffect Reference_Count by one. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3031 | |
| 3032 | #Param pathEffect replace Path with a modification when drawn ## |
| 3033 | |
| 3034 | #Example |
| 3035 | void draw(SkCanvas* canvas) { |
| 3036 | SkPaint paint; |
| 3037 | paint.setPathEffect(SkDiscretePathEffect::Make(3, 5)); |
| 3038 | canvas->drawRect(SkRect::MakeXYWH(40, 40, 175, 175), paint); |
| 3039 | } |
| 3040 | ## |
| 3041 | |
| 3042 | ## |
| 3043 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3044 | #Subtopic Path_Effect_Methods ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3045 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3046 | #Subtopic Mask_Filter_Methods |
| 3047 | #Line # get and set Mask_Filter ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3048 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3049 | Mask_Filter uses coverage of the shape drawn to create Mask_Alpha. |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 3050 | Mask_Filter takes a Mask, and returns a Mask. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 3051 | |
| 3052 | Mask_Filter may change the geometry and transparency of the shape, such as |
| 3053 | creating a blur effect. Set Mask_Filter to nullptr to prevent Mask_Filter from |
| 3054 | modifying the draw. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3055 | |
| 3056 | #Example |
| 3057 | void draw(SkCanvas* canvas) { |
| 3058 | SkPaint paint; |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 3059 | paint.setMaskFilter(SkMaskFilter::MakeBlur(kSolid_SkBlurStyle, 3)); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3060 | canvas->drawRect(SkRect::MakeXYWH(40, 40, 175, 175), paint); |
| 3061 | } |
| 3062 | ## |
| 3063 | |
| 3064 | #Method SkMaskFilter* getMaskFilter() const |
| 3065 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3066 | #In Mask_Filter_Methods |
| 3067 | #Line # returns Mask_Filter, alterations to Mask_Alpha ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3068 | Returns Mask_Filter if set, or nullptr. |
| 3069 | Does not alter Mask_Filter Reference_Count. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3070 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3071 | #Return Mask_Filter if previously set, nullptr otherwise ## |
| 3072 | |
| 3073 | #Example |
| 3074 | void draw(SkCanvas* canvas) { |
| 3075 | SkPaint paint; |
| 3076 | SkDebugf("nullptr %c= mask filter\n", paint.getMaskFilter() ? '!' : '='); |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 3077 | paint.setMaskFilter(SkMaskFilter::MakeBlur(kOuter_SkBlurStyle, 3)); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3078 | SkDebugf("nullptr %c= mask filter\n", paint.getMaskFilter() ? '!' : '='); |
| 3079 | } |
| 3080 | |
| 3081 | #StdOut |
| 3082 | nullptr == mask filter |
| 3083 | nullptr != mask filter |
| 3084 | ## |
| 3085 | ## |
| 3086 | |
| 3087 | ## |
| 3088 | |
| 3089 | #Method sk_sp<SkMaskFilter> refMaskFilter() const |
| 3090 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3091 | #In Mask_Filter_Methods |
| 3092 | #Line # references Mask_Filter, alterations to Mask_Alpha ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3093 | Returns Mask_Filter if set, or nullptr. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 3094 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3095 | Increases Mask_Filter Reference_Count by one. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3096 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3097 | #Return Mask_Filter if previously set, nullptr otherwise ## |
| 3098 | |
| 3099 | #Example |
| 3100 | void draw(SkCanvas* canvas) { |
| 3101 | SkPaint paint1, paint2; |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 3102 | paint1.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 1)); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3103 | SkDebugf("mask filter unique: %s\n", paint1.getMaskFilter()->unique() ? "true" : "false"); |
| 3104 | paint2.setMaskFilter(paint1.refMaskFilter()); |
| 3105 | SkDebugf("mask filter unique: %s\n", paint1.getMaskFilter()->unique() ? "true" : "false"); |
| 3106 | } |
| 3107 | |
| 3108 | #StdOut |
| 3109 | mask filter unique: true |
| 3110 | mask filter unique: false |
| 3111 | ## |
| 3112 | ## |
| 3113 | |
| 3114 | ## |
| 3115 | |
| 3116 | #Method void setMaskFilter(sk_sp<SkMaskFilter> maskFilter) |
| 3117 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3118 | #In Mask_Filter_Methods |
| 3119 | #Line # sets Mask_Filter, alterations to Mask_Alpha ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 3120 | Sets Mask_Filter to maskFilter, decreasing Reference_Count of the previous |
| 3121 | Mask_Filter. Pass nullptr to clear Mask_Filter and leave Mask_Filter effect on |
| 3122 | Mask_Alpha unaltered. |
| 3123 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 3124 | Increments maskFilter Reference_Count by one. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3125 | |
| 3126 | #Param maskFilter modifies clipping mask generated from drawn geometry ## |
| 3127 | |
| 3128 | #Example |
| 3129 | void draw(SkCanvas* canvas) { |
| 3130 | SkPaint paint; |
| 3131 | paint.setStyle(SkPaint::kStroke_Style); |
| 3132 | paint.setStrokeWidth(10); |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 3133 | paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 10)); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3134 | canvas->drawRect(SkRect::MakeXYWH(40, 40, 175, 175), paint); |
| 3135 | } |
| 3136 | ## |
| 3137 | |
| 3138 | ## |
| 3139 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3140 | #Subtopic Mask_Filter_Methods ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3141 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3142 | #Subtopic Typeface_Methods |
| 3143 | #Line # get and set Typeface ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3144 | |
| 3145 | Typeface identifies the font used when drawing and measuring text. |
| 3146 | Typeface may be specified by name, from a file, or from a data stream. |
| 3147 | The default Typeface defers to the platform-specific default font |
| 3148 | implementation. |
| 3149 | |
| 3150 | #Example |
| 3151 | #Height 100 |
| 3152 | void draw(SkCanvas* canvas) { |
| 3153 | SkPaint paint; |
Ben Wagner | 700ff17 | 2017-11-08 15:37:22 -0500 | [diff] [blame] | 3154 | paint.setTypeface(SkTypeface::MakeFromName(nullptr, SkFontStyle())); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3155 | paint.setAntiAlias(true); |
| 3156 | paint.setTextSize(36); |
| 3157 | canvas->drawString("A Big Hello!", 10, 40, paint); |
| 3158 | paint.setTypeface(nullptr); |
| 3159 | paint.setFakeBoldText(true); |
| 3160 | canvas->drawString("A Big Hello!", 10, 80, paint); |
| 3161 | } |
| 3162 | ## |
| 3163 | |
| 3164 | #Method SkTypeface* getTypeface() const |
| 3165 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3166 | #In Typeface_Methods |
| 3167 | #Line # returns Typeface, font description ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3168 | Returns Typeface if set, or nullptr. |
Ben Wagner | 900b536 | 2018-06-22 14:29:08 -0400 | [diff] [blame] | 3169 | Does not alter Typeface Reference_Count. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3170 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3171 | #Return Typeface if previously set, nullptr otherwise ## |
| 3172 | |
| 3173 | #Example |
| 3174 | void draw(SkCanvas* canvas) { |
| 3175 | SkPaint paint; |
| 3176 | SkDebugf("nullptr %c= typeface\n", paint.getTypeface() ? '!' : '='); |
Cary Clark | 71961fb | 2018-01-05 14:21:59 -0500 | [diff] [blame] | 3177 | paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle())); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3178 | SkDebugf("nullptr %c= typeface\n", paint.getTypeface() ? '!' : '='); |
| 3179 | } |
| 3180 | |
| 3181 | #StdOut |
| 3182 | nullptr == typeface |
| 3183 | nullptr != typeface |
| 3184 | ## |
| 3185 | ## |
| 3186 | |
| 3187 | ## |
| 3188 | |
| 3189 | #Method sk_sp<SkTypeface> refTypeface() const |
| 3190 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3191 | #In Typeface_Methods |
| 3192 | #Line # references Typeface, font description ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3193 | Increases Typeface Reference_Count by one. |
| 3194 | |
| 3195 | #Return Typeface if previously set, nullptr otherwise ## |
| 3196 | |
| 3197 | #Example |
| 3198 | void draw(SkCanvas* canvas) { |
| 3199 | SkPaint paint1, paint2; |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3200 | paint1.setTypeface(SkTypeface::MakeFromName("monospace", |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3201 | SkFontStyle(SkFontStyle::kNormal_Weight, SkFontStyle::kNormal_Width, |
| 3202 | SkFontStyle::kItalic_Slant))); |
| 3203 | SkDebugf("typeface1 %c= typeface2\n", |
| 3204 | paint1.getTypeface() == paint2.getTypeface() ? '=' : '!'); |
| 3205 | paint2.setTypeface(paint1.refTypeface()); |
| 3206 | SkDebugf("typeface1 %c= typeface2\n", |
| 3207 | paint1.getTypeface() == paint2.getTypeface() ? '=' : '!'); |
| 3208 | } |
| 3209 | |
| 3210 | #StdOut |
| 3211 | typeface1 != typeface2 |
| 3212 | typeface1 == typeface2 |
| 3213 | ## |
| 3214 | ## |
| 3215 | |
| 3216 | ## |
| 3217 | |
| 3218 | #Method void setTypeface(sk_sp<SkTypeface> typeface) |
| 3219 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3220 | #In Typeface_Methods |
| 3221 | #Line # sets Typeface, font description ## |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3222 | Sets Typeface to typeface, decreasing Reference_Count of the previous Typeface. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 3223 | Pass nullptr to clear Typeface and use the default typeface. Increments |
| 3224 | typeface Reference_Count by one. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3225 | |
| 3226 | #Param typeface font and style used to draw text ## |
| 3227 | |
| 3228 | #Example |
| 3229 | #Height 64 |
| 3230 | void draw(SkCanvas* canvas) { |
| 3231 | SkPaint paint; |
Cary Clark | 71961fb | 2018-01-05 14:21:59 -0500 | [diff] [blame] | 3232 | paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle())); |
| 3233 | canvas->drawString("hamburgerfons", 10, 30, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3234 | paint.setTypeface(nullptr); |
Cary Clark | 71961fb | 2018-01-05 14:21:59 -0500 | [diff] [blame] | 3235 | canvas->drawString("hamburgerfons", 10, 50, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3236 | } |
| 3237 | ## |
| 3238 | |
| 3239 | ## |
| 3240 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3241 | #Subtopic Typeface_Methods ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3242 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3243 | #Subtopic Image_Filter_Methods |
| 3244 | #Line # get and set Image_Filter ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3245 | |
| 3246 | Image_Filter operates on the pixel representation of the shape, as modified by Paint |
| 3247 | with Blend_Mode set to SkBlendMode::kSrcOver. Image_Filter creates a new bitmap, |
| 3248 | which is drawn to the device using the set Blend_Mode. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 3249 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3250 | Image_Filter is higher level than Mask_Filter; for instance, an Image_Filter |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3251 | can operate on all channels of Color, while Mask_Filter generates Alpha only. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3252 | Image_Filter operates independently of and can be used in combination with |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 3253 | Mask_Filter. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3254 | |
| 3255 | #Example |
| 3256 | #ToDo explain why the two draws are so different ## |
Cary Clark | 81abc43 | 2018-06-25 16:30:08 -0400 | [diff] [blame] | 3257 | #Function |
| 3258 | ###$ |
| 3259 | #include "SkBlurImageFilter.h" |
| 3260 | $$$# |
| 3261 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3262 | void draw(SkCanvas* canvas) { |
| 3263 | SkPaint paint; |
| 3264 | paint.setStyle(SkPaint::kStroke_Style); |
| 3265 | paint.setStrokeWidth(2); |
| 3266 | SkRegion region; |
| 3267 | region.op( 10, 10, 50, 50, SkRegion::kUnion_Op); |
| 3268 | region.op( 10, 50, 90, 90, SkRegion::kUnion_Op); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 3269 | paint.setImageFilter(SkBlurImageFilter::Make(5.0f, 5.0f, nullptr)); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3270 | canvas->drawRegion(region, paint); |
| 3271 | paint.setImageFilter(nullptr); |
Cary Clark | a7b84c5 | 2018-03-18 11:46:54 -0400 | [diff] [blame] | 3272 | paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 5)); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3273 | canvas->translate(100, 100); |
| 3274 | canvas->drawRegion(region, paint); |
| 3275 | } |
| 3276 | ## |
| 3277 | |
| 3278 | #Method SkImageFilter* getImageFilter() const |
| 3279 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3280 | #In Image_Filter_Methods |
| 3281 | #Line # returns Image_Filter, alter pixels; blur ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3282 | Returns Image_Filter if set, or nullptr. |
| 3283 | Does not alter Image_Filter Reference_Count. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3284 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3285 | #Return Image_Filter if previously set, nullptr otherwise ## |
| 3286 | |
| 3287 | #Example |
Cary Clark | 81abc43 | 2018-06-25 16:30:08 -0400 | [diff] [blame] | 3288 | #Function |
| 3289 | ###$ |
| 3290 | #include "SkBlurImageFilter.h" |
| 3291 | $$$# |
| 3292 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3293 | void draw(SkCanvas* canvas) { |
| 3294 | SkPaint paint; |
| 3295 | SkDebugf("nullptr %c= image filter\n", paint.getImageFilter() ? '!' : '='); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 3296 | paint.setImageFilter(SkBlurImageFilter::Make(kOuter_SkBlurStyle, 3, nullptr, nullptr)); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3297 | SkDebugf("nullptr %c= image filter\n", paint.getImageFilter() ? '!' : '='); |
| 3298 | } |
| 3299 | |
| 3300 | #StdOut |
| 3301 | nullptr == image filter |
| 3302 | nullptr != image filter |
| 3303 | ## |
| 3304 | ## |
| 3305 | |
| 3306 | ## |
| 3307 | |
| 3308 | #Method sk_sp<SkImageFilter> refImageFilter() const |
| 3309 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3310 | #In Image_Filter_Methods |
| 3311 | #Line # references Image_Filter, alter pixels; blur ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3312 | Returns Image_Filter if set, or nullptr. |
| 3313 | Increases Image_Filter Reference_Count by one. |
| 3314 | |
| 3315 | #Return Image_Filter if previously set, nullptr otherwise ## |
| 3316 | |
| 3317 | #Example |
| 3318 | void draw(SkCanvas* canvas) { |
| 3319 | SkPaint paint1, paint2; |
| 3320 | paint1.setImageFilter(SkOffsetImageFilter::Make(25, 25, nullptr)); |
| 3321 | SkDebugf("image filter unique: %s\n", paint1.getImageFilter()->unique() ? "true" : "false"); |
| 3322 | paint2.setImageFilter(paint1.refImageFilter()); |
| 3323 | SkDebugf("image filter unique: %s\n", paint1.getImageFilter()->unique() ? "true" : "false"); |
| 3324 | } |
| 3325 | |
| 3326 | #StdOut |
| 3327 | image filter unique: true |
| 3328 | image filter unique: false |
| 3329 | ## |
| 3330 | ## |
| 3331 | |
| 3332 | ## |
| 3333 | |
| 3334 | #Method void setImageFilter(sk_sp<SkImageFilter> imageFilter) |
| 3335 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3336 | #In Image_Filter_Methods |
| 3337 | #Line # sets Image_Filter, alter pixels; blur ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 3338 | Sets Image_Filter to imageFilter, decreasing Reference_Count of the previous |
| 3339 | Image_Filter. Pass nullptr to clear Image_Filter, and remove Image_Filter effect |
| 3340 | on drawing. |
| 3341 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 3342 | Increments imageFilter Reference_Count by one. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3343 | |
| 3344 | #Param imageFilter how Image is sampled when transformed ## |
| 3345 | |
| 3346 | #Example |
| 3347 | #Height 160 |
| 3348 | void draw(SkCanvas* canvas) { |
| 3349 | SkBitmap bitmap; |
| 3350 | bitmap.allocN32Pixels(100, 100); |
| 3351 | SkCanvas offscreen(bitmap); |
| 3352 | SkPaint paint; |
| 3353 | paint.setAntiAlias(true); |
| 3354 | paint.setColor(SK_ColorWHITE); |
| 3355 | paint.setTextSize(96); |
| 3356 | offscreen.clear(0); |
| 3357 | offscreen.drawString("e", 20, 70, paint); |
| 3358 | paint.setImageFilter( |
| 3359 | SkLightingImageFilter::MakePointLitDiffuse(SkPoint3::Make(80, 100, 10), |
| 3360 | SK_ColorWHITE, 1, 2, nullptr, nullptr)); |
| 3361 | canvas->drawBitmap(bitmap, 0, 0, &paint); |
| 3362 | } |
| 3363 | ## |
| 3364 | |
| 3365 | ## |
| 3366 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3367 | #Subtopic Image_Filter_Methods ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3368 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3369 | #Subtopic Draw_Looper_Methods |
| 3370 | #Line # get and set Draw_Looper ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3371 | |
| 3372 | Draw_Looper sets a modifier that communicates state from one Draw_Layer |
| 3373 | to another to construct the draw. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 3374 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3375 | Draw_Looper draws one or more times, modifying the canvas and paint each time. |
| 3376 | Draw_Looper may be used to draw multiple colors or create a colored shadow. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3377 | Set Draw_Looper to nullptr to prevent Draw_Looper from modifying the draw. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3378 | |
| 3379 | #Example |
| 3380 | #Height 128 |
| 3381 | void draw(SkCanvas* canvas) { |
| 3382 | SkLayerDrawLooper::LayerInfo info; |
| 3383 | info.fPaintBits = (SkLayerDrawLooper::BitFlags) SkLayerDrawLooper::kColorFilter_Bit; |
| 3384 | info.fColorMode = SkBlendMode::kSrc; |
| 3385 | SkLayerDrawLooper::Builder looperBuilder; |
| 3386 | SkPaint* loopPaint = looperBuilder.addLayer(info); |
| 3387 | loopPaint->setColor(SK_ColorRED); |
| 3388 | info.fOffset.set(20, 20); |
| 3389 | loopPaint = looperBuilder.addLayer(info); |
| 3390 | loopPaint->setColor(SK_ColorBLUE); |
| 3391 | SkPaint paint; |
| 3392 | paint.setDrawLooper(looperBuilder.detach()); |
| 3393 | canvas->drawCircle(50, 50, 50, paint); |
| 3394 | } |
| 3395 | |
| 3396 | ## |
| 3397 | |
| 3398 | #Method SkDrawLooper* getDrawLooper() const |
| 3399 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3400 | #In Draw_Looper_Methods |
| 3401 | #Line # returns Draw_Looper, multiple layers ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3402 | Returns Draw_Looper if set, or nullptr. |
| 3403 | Does not alter Draw_Looper Reference_Count. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3404 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3405 | #Return Draw_Looper if previously set, nullptr otherwise ## |
| 3406 | |
| 3407 | #Example |
| 3408 | void draw(SkCanvas* canvas) { |
| 3409 | SkPaint paint; |
| 3410 | SkDebugf("nullptr %c= draw looper\n", paint.getDrawLooper() ? '!' : '='); |
| 3411 | SkLayerDrawLooper::Builder looperBuilder; |
| 3412 | paint.setDrawLooper(looperBuilder.detach()); |
| 3413 | SkDebugf("nullptr %c= draw looper\n", paint.getDrawLooper() ? '!' : '='); |
| 3414 | } |
| 3415 | |
| 3416 | #StdOut |
| 3417 | nullptr == draw looper |
| 3418 | nullptr != draw looper |
| 3419 | ## |
| 3420 | ## |
| 3421 | |
| 3422 | ## |
| 3423 | |
| 3424 | #Method sk_sp<SkDrawLooper> refDrawLooper() const |
| 3425 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3426 | #In Draw_Looper_Methods |
| 3427 | #Line # references Draw_Looper, multiple layers ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3428 | Returns Draw_Looper if set, or nullptr. |
| 3429 | Increases Draw_Looper Reference_Count by one. |
| 3430 | |
| 3431 | #Return Draw_Looper if previously set, nullptr otherwise ## |
| 3432 | |
| 3433 | #Example |
| 3434 | void draw(SkCanvas* canvas) { |
| 3435 | SkPaint paint1, paint2; |
| 3436 | SkLayerDrawLooper::Builder looperBuilder; |
| 3437 | paint1.setDrawLooper(looperBuilder.detach()); |
| 3438 | SkDebugf("draw looper unique: %s\n", paint1.getDrawLooper()->unique() ? "true" : "false"); |
| 3439 | paint2.setDrawLooper(paint1.refDrawLooper()); |
| 3440 | SkDebugf("draw looper unique: %s\n", paint1.getDrawLooper()->unique() ? "true" : "false"); |
| 3441 | } |
| 3442 | |
| 3443 | #StdOut |
| 3444 | draw looper unique: true |
| 3445 | draw looper unique: false |
| 3446 | ## |
| 3447 | ## |
| 3448 | |
| 3449 | ## |
| 3450 | |
| 3451 | #Method SkDrawLooper* getLooper() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3452 | #Bug 6259 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3453 | #Deprecated |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3454 | ## |
| 3455 | |
| 3456 | #Method void setDrawLooper(sk_sp<SkDrawLooper> drawLooper) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3457 | #In Draw_Looper_Methods |
| 3458 | #Line # sets Draw_Looper, multiple layers ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 3459 | Sets Draw_Looper to drawLooper, decreasing Reference_Count of the previous |
| 3460 | drawLooper. Pass nullptr to clear Draw_Looper and leave Draw_Looper effect on |
| 3461 | drawing unaltered. |
| 3462 | |
| 3463 | Increments drawLooper Reference_Count by one. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3464 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 3465 | #Param drawLooper iterates through drawing one or more time, altering Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3466 | |
| 3467 | #Example |
| 3468 | #Height 128 |
| 3469 | void draw(SkCanvas* canvas) { |
| 3470 | SkPaint paint; |
| 3471 | paint.setDrawLooper(SkBlurDrawLooper::Make(0x7FFF0000, 4, -5, -10)); |
| 3472 | paint.setStyle(SkPaint::kStroke_Style); |
| 3473 | paint.setStrokeWidth(10); |
| 3474 | paint.setAntiAlias(true); |
| 3475 | paint.setColor(0x7f0000ff); |
| 3476 | canvas->drawCircle(70, 70, 50, paint); |
| 3477 | } |
| 3478 | ## |
| 3479 | |
| 3480 | ## |
| 3481 | |
| 3482 | #Method void setLooper(sk_sp<SkDrawLooper> drawLooper) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3483 | #Bug 6259 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3484 | #Deprecated |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3485 | ## |
| 3486 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3487 | #Subtopic Draw_Looper_Methods ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3488 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3489 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3490 | #Subtopic Text_Align |
| 3491 | #Line # text placement relative to position ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3492 | |
| 3493 | #Enum Align |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3494 | #Line # glyph locations relative to text position ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3495 | #Code |
| 3496 | enum Align { |
| 3497 | kLeft_Align, |
| 3498 | kCenter_Align, |
| 3499 | kRight_Align, |
| 3500 | }; |
Cary Clark | d98f78c | 2018-04-26 08:32:37 -0400 | [diff] [blame] | 3501 | |
| 3502 | static constexpr int kAlignCount = 3; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3503 | ## |
| 3504 | |
| 3505 | Align adjusts the text relative to the text position. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3506 | Align affects Glyphs drawn with: SkCanvas::drawText, SkCanvas::drawPosText, |
Cary Clark | 153e76d | 2018-08-28 11:48:28 -0400 | [diff] [blame] | 3507 | SkCanvas::drawPosTextH, SkCanvas::drawTextRSXform, SkCanvas::drawTextBlob, |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3508 | and SkCanvas::drawString; |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3509 | as well as calls that place text Glyphs like getTextWidths and getTextPath. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3510 | |
| 3511 | The text position is set by the font for both horizontal and vertical text. |
| 3512 | Typically, for horizontal text, the position is to the left side of the glyph on the |
| 3513 | base line; and for vertical text, the position is the horizontal center of the glyph |
| 3514 | at the caps height. |
| 3515 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3516 | Align adjusts the glyph position to center it or move it to abut the position |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3517 | using the metrics returned by the font. |
| 3518 | |
| 3519 | Align defaults to kLeft_Align. |
| 3520 | |
| 3521 | #Const kLeft_Align 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3522 | #Line # positions glyph by computed font offset ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3523 | Leaves the glyph at the position computed by the font offset by the text position. |
| 3524 | ## |
| 3525 | |
| 3526 | #Const kCenter_Align 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3527 | #Line # centers line of glyphs by its width or height ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3528 | Moves the glyph half its width if Flags has kVerticalText_Flag clear, and |
| 3529 | half its height if Flags has kVerticalText_Flag set. |
| 3530 | ## |
| 3531 | |
| 3532 | #Const kRight_Align 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3533 | #Line # moves lines of glyphs by its width or height ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3534 | Moves the glyph by its width if Flags has kVerticalText_Flag clear, |
| 3535 | and by its height if Flags has kVerticalText_Flag set. |
| 3536 | ## |
| 3537 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3538 | #Const kAlignCount 3 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3539 | #Line # number of different Text_Align values defined ## |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 3540 | May be used to verify that Align is a legal value. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3541 | ## |
| 3542 | |
| 3543 | #Enum ## |
| 3544 | |
| 3545 | #Example |
| 3546 | #Height 160 |
| 3547 | #Description |
| 3548 | Each position separately moves the glyph in drawPosText. |
| 3549 | ## |
| 3550 | void draw(SkCanvas* canvas) { |
| 3551 | SkPaint paint; |
| 3552 | paint.setTextSize(40); |
| 3553 | SkPoint position[] = {{100, 50}, {150, 40}}; |
| 3554 | for (SkPaint::Align a : { SkPaint::kLeft_Align, |
| 3555 | SkPaint::kCenter_Align, |
| 3556 | SkPaint::kRight_Align}) { |
| 3557 | paint.setTextAlign(a); |
| 3558 | canvas->drawPosText("Aa", 2, position, paint); |
| 3559 | canvas->translate(0, 50); |
| 3560 | } |
| 3561 | } |
| 3562 | ## |
| 3563 | |
| 3564 | #Example |
| 3565 | #Height 160 |
| 3566 | #Description |
| 3567 | Vertical_Text treats kLeft_Align as top align, and kRight_Align as bottom align. |
| 3568 | ## |
| 3569 | void draw(SkCanvas* canvas) { |
| 3570 | SkPaint paint; |
| 3571 | paint.setTextSize(40); |
| 3572 | paint.setVerticalText(true); |
| 3573 | for (SkPaint::Align a : { SkPaint::kLeft_Align, |
| 3574 | SkPaint::kCenter_Align, |
| 3575 | SkPaint::kRight_Align }) { |
| 3576 | paint.setTextAlign(a); |
| 3577 | canvas->drawString("Aa", 50, 80, paint); |
| 3578 | canvas->translate(50, 0); |
| 3579 | } |
| 3580 | } |
| 3581 | ## |
| 3582 | |
| 3583 | #Method Align getTextAlign() const |
| 3584 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3585 | #In Text_Align |
| 3586 | #Line # returns Align: left, center, or right ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3587 | Returns Text_Align. |
| 3588 | Returns kLeft_Align if Text_Align has not been set. |
| 3589 | |
| 3590 | #Return text placement relative to position ## |
| 3591 | |
| 3592 | #Example |
| 3593 | SkPaint paint; |
| 3594 | SkDebugf("kLeft_Align %c= default\n", SkPaint::kLeft_Align == paint.getTextAlign() ? '=' : '!'); |
| 3595 | |
| 3596 | #StdOut |
| 3597 | kLeft_Align == default |
| 3598 | ## |
| 3599 | ## |
| 3600 | ## |
| 3601 | |
| 3602 | #Method void setTextAlign(Align align) |
| 3603 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3604 | #In Text_Align |
| 3605 | #Line # sets Align: left, center, or right ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3606 | Sets Text_Align to align. |
| 3607 | Has no effect if align is an invalid value. |
| 3608 | |
| 3609 | #Param align text placement relative to position ## |
| 3610 | |
| 3611 | #Example |
| 3612 | #Height 160 |
| 3613 | #Description |
| 3614 | Text is left-aligned by default, and then set to center. Setting the |
| 3615 | alignment out of range has no effect. |
| 3616 | ## |
| 3617 | void draw(SkCanvas* canvas) { |
| 3618 | SkPaint paint; |
| 3619 | paint.setTextSize(40); |
| 3620 | canvas->drawString("Aa", 100, 50, paint); |
| 3621 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 3622 | canvas->drawString("Aa", 100, 100, paint); |
| 3623 | paint.setTextAlign((SkPaint::Align) SkPaint::kAlignCount); |
| 3624 | canvas->drawString("Aa", 100, 150, paint); |
| 3625 | } |
| 3626 | ## |
| 3627 | |
| 3628 | ## |
| 3629 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3630 | #Subtopic Text_Align ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3631 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3632 | #Subtopic Text_Size |
| 3633 | #Line # overall height in points ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3634 | |
| 3635 | Text_Size adjusts the overall text size in points. |
| 3636 | Text_Size can be set to any positive value or zero. |
| 3637 | Text_Size defaults to 12. |
| 3638 | Set SkPaintDefaults_TextSize at compile time to change the default setting. |
| 3639 | |
| 3640 | #Example |
| 3641 | #Height 135 |
| 3642 | void draw(SkCanvas* canvas) { |
| 3643 | SkPaint paint; |
| 3644 | canvas->drawString("12 point", 10, 20, paint); |
| 3645 | paint.setTextSize(24); |
| 3646 | canvas->drawString("24 point", 10, 60, paint); |
| 3647 | paint.setTextSize(48); |
| 3648 | canvas->drawString("48 point", 10, 120, paint); |
| 3649 | } |
| 3650 | ## |
| 3651 | |
| 3652 | #Method SkScalar getTextSize() const |
| 3653 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3654 | #In Text_Size |
| 3655 | #Line # returns text size in points ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3656 | Returns Text_Size in points. |
| 3657 | |
| 3658 | #Return typographic height of text ## |
| 3659 | |
| 3660 | #Example |
| 3661 | SkPaint paint; |
| 3662 | SkDebugf("12 %c= default text size\n", 12 == paint.getTextSize() ? '=' : '!'); |
| 3663 | ## |
| 3664 | |
| 3665 | ## |
| 3666 | |
| 3667 | #Method void setTextSize(SkScalar textSize) |
| 3668 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3669 | #In Text_Size |
| 3670 | #Line # sets text size in points ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3671 | Sets Text_Size in points. |
| 3672 | Has no effect if textSize is not greater than or equal to zero. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3673 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3674 | #Param textSize typographic height of text ## |
| 3675 | |
| 3676 | #Example |
| 3677 | SkPaint paint; |
| 3678 | SkDebugf("12 %c= text size\n", 12 == paint.getTextSize() ? '=' : '!'); |
| 3679 | paint.setTextSize(-20); |
| 3680 | SkDebugf("12 %c= text size\n", 12 == paint.getTextSize() ? '=' : '!'); |
| 3681 | ## |
| 3682 | |
| 3683 | ## |
| 3684 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3685 | #Subtopic Text_Size ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3686 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3687 | #Subtopic Text_Scale_X |
| 3688 | #Line # text horizontal scale ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3689 | |
| 3690 | Text_Scale_X adjusts the text horizontal scale. |
| 3691 | Text scaling approximates condensed and expanded type faces when the actual face |
| 3692 | is not available. |
| 3693 | Text_Scale_X can be set to any value. |
| 3694 | Text_Scale_X defaults to 1. |
| 3695 | |
| 3696 | #Example |
| 3697 | #Height 128 |
| 3698 | void draw(SkCanvas* canvas) { |
| 3699 | SkPaint paint; |
| 3700 | paint.setAntiAlias(true); |
| 3701 | paint.setTextSize(24); |
| 3702 | paint.setTextScaleX(.8f); |
| 3703 | canvas->drawString("narrow", 10, 20, paint); |
| 3704 | paint.setTextScaleX(1); |
| 3705 | canvas->drawString("normal", 10, 60, paint); |
| 3706 | paint.setTextScaleX(1.2f); |
| 3707 | canvas->drawString("wide", 10, 100, paint); |
| 3708 | } |
| 3709 | ## |
| 3710 | |
| 3711 | #Method SkScalar getTextScaleX() const |
| 3712 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3713 | #In Text_Scale_X |
| 3714 | #Line # returns the text horizontal scale; condensed text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3715 | Returns Text_Scale_X. |
| 3716 | Default value is 1. |
| 3717 | |
| 3718 | #Return text horizontal scale ## |
| 3719 | |
| 3720 | #Example |
| 3721 | SkPaint paint; |
| 3722 | SkDebugf("1 %c= default text scale x\n", 1 == paint.getTextScaleX() ? '=' : '!'); |
| 3723 | ## |
| 3724 | |
| 3725 | ## |
| 3726 | |
| 3727 | |
| 3728 | #Method void setTextScaleX(SkScalar scaleX) |
| 3729 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3730 | #In Text_Scale_X |
| 3731 | #Line # sets the text horizontal scale; condensed text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3732 | Sets Text_Scale_X. |
| 3733 | Default value is 1. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3734 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3735 | #Param scaleX text horizontal scale ## |
| 3736 | |
| 3737 | #Example |
| 3738 | SkPaint paint; |
| 3739 | paint.setTextScaleX(0.f / 0.f); |
| 3740 | SkDebugf("text scale %s-a-number\n", SkScalarIsNaN(paint.getTextScaleX()) ? "not" : "is"); |
| 3741 | ## |
| 3742 | |
| 3743 | ## |
| 3744 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3745 | #Subtopic Text_Scale_X ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3746 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3747 | #Subtopic Text_Skew_X |
| 3748 | #Line # text horizontal slant ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3749 | |
| 3750 | |
| 3751 | Text_Skew_X adjusts the text horizontal slant. |
| 3752 | Text skewing approximates italic and oblique type faces when the actual face |
| 3753 | is not available. |
| 3754 | Text_Skew_X can be set to any value. |
| 3755 | Text_Skew_X defaults to 0. |
| 3756 | |
| 3757 | #Example |
| 3758 | #Height 128 |
| 3759 | void draw(SkCanvas* canvas) { |
| 3760 | SkPaint paint; |
| 3761 | paint.setAntiAlias(true); |
| 3762 | paint.setTextSize(24); |
| 3763 | paint.setTextSkewX(-.25f); |
| 3764 | canvas->drawString("right-leaning", 10, 100, paint); |
| 3765 | paint.setTextSkewX(0); |
| 3766 | canvas->drawString("normal", 10, 60, paint); |
| 3767 | paint.setTextSkewX(.25f); |
| 3768 | canvas->drawString("left-leaning", 10, 20, paint); |
| 3769 | } |
| 3770 | ## |
| 3771 | |
| 3772 | #Method SkScalar getTextSkewX() const |
| 3773 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3774 | #In Text_Skew_X |
| 3775 | #Line # returns the text horizontal skew; oblique text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3776 | Returns Text_Skew_X. |
| 3777 | Default value is zero. |
| 3778 | |
| 3779 | #Return additional shear in x-axis relative to y-axis ## |
| 3780 | |
| 3781 | #Example |
| 3782 | SkPaint paint; |
| 3783 | SkDebugf("0 %c= default text skew x\n", 0 == paint.getTextSkewX() ? '=' : '!'); |
| 3784 | ## |
| 3785 | |
| 3786 | ## |
| 3787 | |
| 3788 | #Method void setTextSkewX(SkScalar skewX) |
| 3789 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3790 | #In Text_Skew_X |
| 3791 | #Line # sets the text horizontal skew; oblique text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3792 | Sets Text_Skew_X. |
| 3793 | Default value is zero. |
| 3794 | |
| 3795 | #Param skewX additional shear in x-axis relative to y-axis ## |
| 3796 | |
| 3797 | #Example |
| 3798 | SkPaint paint; |
| 3799 | paint.setTextScaleX(1.f / 0.f); |
| 3800 | SkDebugf("text scale %s-finite\n", SkScalarIsFinite(paint.getTextScaleX()) ? "is" : "not"); |
| 3801 | ## |
| 3802 | |
| 3803 | ## |
| 3804 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3805 | #Subtopic Text_Skew_X ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3806 | |
| 3807 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3808 | #Subtopic Text_Encoding |
| 3809 | #Line # text encoded as characters or Glyphs ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3810 | |
| 3811 | #Enum TextEncoding |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3812 | #Line # character or glyph encoded size ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3813 | |
| 3814 | #Code |
| 3815 | enum TextEncoding { |
| 3816 | kUTF8_TextEncoding, |
| 3817 | kUTF16_TextEncoding, |
| 3818 | kUTF32_TextEncoding, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3819 | kGlyphID_TextEncoding, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3820 | }; |
| 3821 | ## |
| 3822 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 3823 | TextEncoding determines whether text specifies character codes and their encoded |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3824 | size, or glyph indices. Characters are encoded as specified by the |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3825 | #A Unicode standard # https://unicode.org/standard/standard.html ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 3826 | . |
| 3827 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3828 | Character codes encoded size are specified by UTF-8, UTF-16, or UTF-32. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3829 | All character code formats are able to represent all of Unicode, differing only |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3830 | in the total storage required. |
| 3831 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 3832 | #A UTF-8 (RFC 3629) # https://tools.ietf.org/html/rfc3629 ## |
| 3833 | encodes each character as one or more 8-bit bytes. |
| 3834 | |
| 3835 | #A UTF-16 (RFC 2781) # https://tools.ietf.org/html/rfc2781 ## |
| 3836 | encodes each character as one or two 16-bit words. |
| 3837 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3838 | #A UTF-32 # https://www.unicode.org/versions/Unicode5.0.0/ch03.pdf ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 3839 | encodes each character as one 32-bit word. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3840 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3841 | Font_Manager uses font data to convert character code points into glyph indices. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3842 | A glyph index is a 16-bit word. |
| 3843 | |
| 3844 | TextEncoding is set to kUTF8_TextEncoding by default. |
| 3845 | |
| 3846 | #Const kUTF8_TextEncoding 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3847 | #Line # uses bytes to represent UTF-8 or ASCII ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3848 | ## |
| 3849 | #Const kUTF16_TextEncoding 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3850 | #Line # uses two byte words to represent most of Unicode ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3851 | ## |
| 3852 | #Const kUTF32_TextEncoding 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3853 | #Line # uses four byte words to represent all of Unicode ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3854 | ## |
| 3855 | #Const kGlyphID_TextEncoding 3 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3856 | #Line # uses two byte words to represent glyph indices ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3857 | ## |
| 3858 | |
| 3859 | #Enum ## |
| 3860 | |
| 3861 | #Example |
| 3862 | #Height 128 |
| 3863 | #Description |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3864 | First line is encoded in UTF-8. |
| 3865 | Second line is encoded in UTF-16. |
| 3866 | Third line is encoded in UTF-32. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3867 | Fourth line has 16-bit glyph indices. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3868 | ## |
| 3869 | void draw(SkCanvas* canvas) { |
| 3870 | SkPaint paint; |
| 3871 | const char hello8[] = "Hello" "\xE2" "\x98" "\xBA"; |
| 3872 | const uint16_t hello16[] = { 'H', 'e', 'l', 'l', 'o', 0x263A }; |
| 3873 | const uint32_t hello32[] = { 'H', 'e', 'l', 'l', 'o', 0x263A }; |
| 3874 | paint.setTextSize(24); |
| 3875 | canvas->drawText(hello8, sizeof(hello8) - 1, 10, 30, paint); |
| 3876 | paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); |
| 3877 | canvas->drawText(hello16, sizeof(hello16), 10, 60, paint); |
| 3878 | paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); |
| 3879 | canvas->drawText(hello32, sizeof(hello32), 10, 90, paint); |
| 3880 | uint16_t glyphs[SK_ARRAY_COUNT(hello32)]; |
| 3881 | paint.textToGlyphs(hello32, sizeof(hello32), glyphs); |
| 3882 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 3883 | canvas->drawText(glyphs, sizeof(glyphs), 10, 120, paint); |
| 3884 | } |
| 3885 | ## |
| 3886 | |
| 3887 | #Method TextEncoding getTextEncoding() const |
| 3888 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3889 | #In Text_Encoding |
| 3890 | #Line # returns character or glyph encoded size ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3891 | Returns Text_Encoding. |
| 3892 | Text_Encoding determines how character code points are mapped to font glyph indices. |
| 3893 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3894 | #Return one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or |
| 3895 | kGlyphID_TextEncoding |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3896 | ## |
| 3897 | |
| 3898 | #Example |
| 3899 | SkPaint paint; |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3900 | SkDebugf("kUTF8_TextEncoding %c= text encoding\n", |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3901 | SkPaint::kUTF8_TextEncoding == paint.getTextEncoding() ? '=' : '!'); |
| 3902 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3903 | SkDebugf("kGlyphID_TextEncoding %c= text encoding\n", |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3904 | SkPaint::kGlyphID_TextEncoding == paint.getTextEncoding() ? '=' : '!'); |
| 3905 | |
| 3906 | #StdOut |
| 3907 | kUTF8_TextEncoding == text encoding |
| 3908 | kGlyphID_TextEncoding == text encoding |
| 3909 | ## |
| 3910 | ## |
| 3911 | |
| 3912 | ## |
| 3913 | |
| 3914 | |
| 3915 | #Method void setTextEncoding(TextEncoding encoding) |
| 3916 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3917 | #In Text_Encoding |
| 3918 | #Line # sets character or glyph encoded size ## |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3919 | Sets Text_Encoding to encoding. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3920 | Text_Encoding determines how character code points are mapped to font glyph indices. |
| 3921 | Invalid values for encoding are ignored. |
| 3922 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3923 | #Param encoding one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or |
| 3924 | kGlyphID_TextEncoding |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 3925 | #Param ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3926 | |
| 3927 | #Example |
| 3928 | SkPaint paint; |
| 3929 | paint.setTextEncoding((SkPaint::TextEncoding) 4); |
Cary Clark | 75fd449 | 2018-06-20 12:45:16 -0400 | [diff] [blame] | 3930 | SkDebugf("4 %c= text encoding\n", (SkPaint::TextEncoding) 4 == paint.getTextEncoding() ? '=' : '!'); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3931 | |
| 3932 | #StdOut |
| 3933 | 4 != text encoding |
| 3934 | ## |
| 3935 | ## |
| 3936 | |
| 3937 | ## |
| 3938 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3939 | #Subtopic Text_Encoding ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3940 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3941 | #Subtopic Font_Metrics |
| 3942 | #Line # common glyph dimensions ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3943 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3944 | Font_Metrics describe dimensions common to the Glyphs in Typeface. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 3945 | The dimensions are computed by Font_Manager from font data and do not take |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3946 | Paint settings other than Text_Size into account. |
| 3947 | |
| 3948 | Font dimensions specify the anchor to the left of the glyph at baseline as the origin. |
| 3949 | X-axis values to the left of the glyph are negative, and to the right of the left glyph edge |
| 3950 | are positive. |
| 3951 | Y-axis values above the baseline are negative, and below the baseline are positive. |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 3952 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3953 | #Example |
| 3954 | #Width 512 |
| 3955 | void draw(SkCanvas* canvas) { |
| 3956 | SkPaint paint; |
| 3957 | paint.setAntiAlias(true); |
| 3958 | paint.setTextSize(120); |
| 3959 | SkPaint::FontMetrics fm; |
| 3960 | SkScalar lineHeight = paint.getFontMetrics(&fm); |
| 3961 | SkPoint pt = { 70, 180 }; |
| 3962 | canvas->drawString("M", pt.fX, pt.fY, paint); |
| 3963 | canvas->drawLine(pt.fX, pt.fY, pt.fX, pt.fY + fm.fTop, paint); |
| 3964 | SkScalar ascent = pt.fY + fm.fAscent; |
| 3965 | canvas->drawLine(pt.fX - 25, ascent, pt.fX - 25, ascent + lineHeight, paint); |
| 3966 | canvas->drawLine(pt.fX - 50, pt.fY, pt.fX - 50, pt.fY + fm.fDescent, paint); |
| 3967 | canvas->drawLine(pt.fX + 100, pt.fY, pt.fX + 100, pt.fY + fm.fAscent, paint); |
| 3968 | canvas->drawLine(pt.fX + 125, pt.fY, pt.fX + 125, pt.fY - fm.fXHeight, paint); |
| 3969 | canvas->drawLine(pt.fX + 150, pt.fY, pt.fX + 150, pt.fY - fm.fCapHeight, paint); |
| 3970 | canvas->drawLine(pt.fX + 5, pt.fY, pt.fX + 5, pt.fY + fm.fBottom, paint); |
| 3971 | SkScalar xmin = pt.fX + fm.fXMin; |
| 3972 | canvas->drawLine(xmin, pt.fY + 60, xmin + fm.fMaxCharWidth, pt.fY + 60, paint); |
| 3973 | canvas->drawLine(xmin, pt.fY - 145, pt.fX, pt.fY - 145, paint); |
| 3974 | canvas->drawLine(pt.fX + fm.fXMax, pt.fY - 160, pt.fX, pt.fY - 160, paint); |
| 3975 | SkScalar upos = pt.fY + fm.fUnderlinePosition; |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 3976 | canvas->drawLine(pt.fX + 25, upos, pt.fX + 160, upos, paint); |
| 3977 | SkScalar ut = fm.fUnderlineThickness; |
| 3978 | canvas->drawLine(pt.fX + 130, upos + ut, pt.fX + 160, upos + ut, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3979 | paint.setTextSize(12); |
| 3980 | canvas->drawString("x-min", pt.fX - 50, pt.fY - 148, paint); |
| 3981 | canvas->drawString("x-max", pt.fX + 140, pt.fY - 150, paint); |
| 3982 | canvas->drawString("max char width", pt.fX + 120, pt.fY + 57, paint); |
| 3983 | canvas->drawString("underline position", pt.fX + 30, pt.fY + 22, paint); |
| 3984 | canvas->drawString("underline thickness", pt.fX + 162, pt.fY + 13, paint); |
| 3985 | canvas->rotate(-90); |
| 3986 | canvas->drawString("descent", -pt.fY - 30, pt.fX - 54, paint); |
| 3987 | canvas->drawString("line height", -pt.fY, pt.fX - 29, paint); |
| 3988 | canvas->drawString("top", -pt.fY + 30, pt.fX - 4, paint); |
| 3989 | canvas->drawString("ascent", -pt.fY, pt.fX + 110, paint); |
| 3990 | canvas->drawString("x-height", -pt.fY, pt.fX + 135, paint); |
| 3991 | canvas->drawString("cap-height", -pt.fY, pt.fX + 160, paint); |
| 3992 | canvas->drawString("bottom", -pt.fY - 50, pt.fX + 15, paint); |
| 3993 | } |
| 3994 | ## |
| 3995 | |
| 3996 | #Struct FontMetrics |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3997 | #Line # values computed by Font_Manager using Typeface ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3998 | |
| 3999 | #Code |
| 4000 | struct FontMetrics { |
| 4001 | enum FontMetricsFlags { |
| 4002 | kUnderlineThicknessIsValid_Flag = 1 << 0, |
| 4003 | kUnderlinePositionIsValid_Flag = 1 << 1, |
| 4004 | kStrikeoutThicknessIsValid_Flag = 1 << 2, |
| 4005 | kStrikeoutPositionIsValid_Flag = 1 << 3, |
| 4006 | }; |
| 4007 | |
| 4008 | uint32_t fFlags; |
| 4009 | SkScalar fTop; |
| 4010 | SkScalar fAscent; |
| 4011 | SkScalar fDescent; |
| 4012 | SkScalar fBottom; |
| 4013 | SkScalar fLeading; |
| 4014 | SkScalar fAvgCharWidth; |
| 4015 | SkScalar fMaxCharWidth; |
| 4016 | SkScalar fXMin; |
| 4017 | SkScalar fXMax; |
| 4018 | SkScalar fXHeight; |
| 4019 | SkScalar fCapHeight; |
| 4020 | SkScalar fUnderlineThickness; |
| 4021 | SkScalar fUnderlinePosition; |
| 4022 | SkScalar fStrikeoutThickness; |
| 4023 | SkScalar fStrikeoutPosition; |
| 4024 | |
| 4025 | bool hasUnderlineThickness(SkScalar* thickness) const; |
| 4026 | bool hasUnderlinePosition(SkScalar* position) const; |
| 4027 | bool hasStrikeoutThickness(SkScalar* thickness) const; |
| 4028 | bool hasStrikeoutPosition(SkScalar* position) const; |
| 4029 | }; |
| 4030 | ## |
| 4031 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4032 | FontMetrics is filled out by getFontMetrics. FontMetrics contents reflect the values |
| 4033 | computed by Font_Manager using Typeface. Values are set to zero if they are |
| 4034 | not available. |
Cary Clark | e4aa371 | 2017-09-15 02:56:12 -0400 | [diff] [blame] | 4035 | |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 4036 | All vertical values are relative to the baseline, on a y-axis pointing down. |
| 4037 | Zero is on the baseline, negative values are above the baseline, and positive |
| 4038 | values are below the baseline. |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4039 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4040 | fUnderlineThickness and fUnderlinePosition have a bit set in fFlags if their values |
| 4041 | are valid, since their value may be zero. |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4042 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4043 | fStrikeoutThickness and fStrikeoutPosition have a bit set in fFlags if their values |
| 4044 | are valid, since their value may be zero. |
| 4045 | |
| 4046 | #Enum FontMetricsFlags |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4047 | #Line # valid Font_Metrics ## |
Cary Clark | e4aa371 | 2017-09-15 02:56:12 -0400 | [diff] [blame] | 4048 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4049 | #Code |
| 4050 | enum FontMetricsFlags { |
| 4051 | kUnderlineThicknessIsValid_Flag = 1 << 0, |
| 4052 | kUnderlinePositionIsValid_Flag = 1 << 1, |
| 4053 | kStrikeoutThicknessIsValid_Flag = 1 << 2, |
| 4054 | kStrikeoutPositionIsValid_Flag = 1 << 3, |
| 4055 | }; |
| 4056 | ## |
| 4057 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4058 | FontMetricsFlags are set in fFlags when underline and strikeout metrics are valid; |
| 4059 | the underline or strikeout metric may be valid and zero. |
| 4060 | Fonts with embedded bitmaps may not have valid underline or strikeout metrics. |
| 4061 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4062 | #Const kUnderlineThicknessIsValid_Flag 0x0001 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4063 | #Line # set if fUnderlineThickness is valid ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4064 | ## |
| 4065 | #Const kUnderlinePositionIsValid_Flag 0x0002 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4066 | #Line # set if fUnderlinePosition is valid ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4067 | ## |
| 4068 | #Const kStrikeoutThicknessIsValid_Flag 0x0004 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4069 | #Line # set if fStrikeoutThickness is valid ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4070 | ## |
| 4071 | #Const kStrikeoutPositionIsValid_Flag 0x0008 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4072 | #Line # set if fStrikeoutPosition is valid ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4073 | ## |
| 4074 | |
| 4075 | #Enum ## |
| 4076 | |
| 4077 | #Member uint32_t fFlags |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4078 | #Line # is set to FontMetricsFlags when metrics are valid ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4079 | ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4080 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4081 | #Member SkScalar fTop |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4082 | #Line # extent above baseline ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4083 | Greatest extent above the baseline for any glyph. |
| 4084 | Typically less than zero. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4085 | ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4086 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4087 | #Member SkScalar fAscent |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4088 | #Line # distance to reserve above baseline ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4089 | Recommended distance above the baseline to reserve for a line of text. |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4090 | Typically less than zero. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4091 | ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4092 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4093 | #Member SkScalar fDescent |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4094 | #Line # distance to reserve below baseline ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4095 | Recommended distance below the baseline to reserve for a line of text. |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4096 | Typically greater than zero. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4097 | ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4098 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4099 | #Member SkScalar fBottom |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4100 | #Line # extent below baseline ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4101 | Greatest extent below the baseline for any glyph. |
| 4102 | Typically greater than zero. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4103 | ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4104 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4105 | #Member SkScalar fLeading |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4106 | #Line # distance to add between lines ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4107 | Recommended distance to add between lines of text. |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4108 | Typically greater than or equal to zero. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4109 | ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4110 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4111 | #Member SkScalar fAvgCharWidth |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4112 | #Line # average character width ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4113 | Average character width, if it is available. |
| 4114 | Zero if no average width is stored in the font. |
| 4115 | ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4116 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4117 | #Member SkScalar fMaxCharWidth |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4118 | #Line # maximum character width ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4119 | ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4120 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4121 | #Member SkScalar fXMin |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4122 | #Line # minimum x ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 4123 | Minimum bounding box x-axis value for all Glyphs. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4124 | Typically less than zero. |
| 4125 | ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4126 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4127 | #Member SkScalar fXMax |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4128 | #Line # maximum x ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 4129 | Maximum bounding box x-axis value for all Glyphs. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4130 | Typically greater than zero. |
| 4131 | ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4132 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4133 | #Member SkScalar fXHeight |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4134 | #Line # height of lower-case 'x' ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4135 | May be zero if no lower-case height is stored in the font. |
| 4136 | ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4137 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4138 | #Member SkScalar fCapHeight |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4139 | #Line # height of an upper-case letter ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4140 | May be zero if no upper-case height is stored in the font. |
| 4141 | ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4142 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4143 | #Member SkScalar fUnderlineThickness |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4144 | #Line # underline thickness ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4145 | If the metric is valid, the kUnderlineThicknessIsValid_Flag is set in fFlags. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4146 | If kUnderlineThicknessIsValid_Flag is clear, fUnderlineThickness is zero. |
| 4147 | ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4148 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4149 | #Member SkScalar fUnderlinePosition |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4150 | #Line # underline position relative to baseline ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4151 | Position of the top of the underline stroke relative to the baseline. |
| 4152 | Typically positive when valid. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4153 | |
| 4154 | If the metric is valid, the kUnderlinePositionIsValid_Flag is set in fFlags. |
| 4155 | If kUnderlinePositionIsValid_Flag is clear, fUnderlinePosition is zero. |
| 4156 | ## |
| 4157 | |
| 4158 | #Member SkScalar fStrikeoutThickness |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4159 | #Line # strikeout thickness ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4160 | |
| 4161 | If the metric is valid, the kStrikeoutThicknessIsValid_Flag is set in fFlags. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4162 | If kStrikeoutThicknessIsValid_Flag is clear, fStrikeoutThickness is zero. |
| 4163 | ## |
| 4164 | |
| 4165 | #Member SkScalar fStrikeoutPosition |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4166 | #Line # strikeout position relative to baseline ## |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4167 | Position of the bottom of the strikeout stroke relative to the baseline. |
| 4168 | Typically negative when valid. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4169 | |
Ben Wagner | e580649 | 2017-11-09 12:08:31 -0500 | [diff] [blame] | 4170 | If the metric is valid, the kStrikeoutPositionIsValid_Flag is set in fFlags. |
| 4171 | If kStrikeoutPositionIsValid_Flag is clear, fStrikeoutPosition is zero. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4172 | ## |
| 4173 | |
| 4174 | #Method bool hasUnderlineThickness(SkScalar* thickness) const |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4175 | #Line # returns underline thickness if set ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4176 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4177 | Returns true if Font_Metrics has a valid underline thickness, and sets |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4178 | thickness to that value. If the underline thickness is not valid, |
| 4179 | return false, and ignore thickness. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4180 | |
| 4181 | #Param thickness storage for underline width ## |
| 4182 | |
| 4183 | #Return true if font specifies underline width ## |
| 4184 | |
| 4185 | #NoExample |
| 4186 | ## |
| 4187 | ## |
| 4188 | |
| 4189 | #Method bool hasUnderlinePosition(SkScalar* position) const |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4190 | #Line # returns underline position if set ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4191 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4192 | Returns true if Font_Metrics has a valid underline position, and sets |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4193 | position to that value. If the underline position is not valid, |
| 4194 | return false, and ignore position. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4195 | |
| 4196 | #Param position storage for underline position ## |
| 4197 | |
| 4198 | #Return true if font specifies underline position ## |
| 4199 | |
| 4200 | #NoExample |
| 4201 | ## |
| 4202 | ## |
| 4203 | |
| 4204 | #Method bool hasStrikeoutThickness(SkScalar* thickness) const |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4205 | #Line # returns strikeout thickness if set ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4206 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4207 | Returns true if Font_Metrics has a valid strikeout thickness, and sets |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4208 | thickness to that value. If the underline thickness is not valid, |
| 4209 | return false, and ignore thickness. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4210 | |
| 4211 | #Param thickness storage for strikeout width ## |
| 4212 | |
| 4213 | #Return true if font specifies strikeout width ## |
| 4214 | |
| 4215 | #NoExample |
| 4216 | ## |
| 4217 | ## |
| 4218 | |
| 4219 | #Method bool hasStrikeoutPosition(SkScalar* position) const |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4220 | #Line # returns strikeout position if set ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4221 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4222 | Returns true if Font_Metrics has a valid strikeout position, and sets |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4223 | position to that value. If the underline position is not valid, |
| 4224 | return false, and ignore position. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4225 | |
| 4226 | #Param position storage for strikeout position ## |
| 4227 | |
| 4228 | #Return true if font specifies strikeout position ## |
| 4229 | |
| 4230 | #NoExample |
| 4231 | ## |
| 4232 | ## |
| 4233 | |
| 4234 | #Struct ## |
| 4235 | |
| 4236 | #Method SkScalar getFontMetrics(FontMetrics* metrics, SkScalar scale = 0) const |
| 4237 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4238 | #In Font_Metrics |
| 4239 | #Line # returns Typeface metrics scaled by text size ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4240 | Returns Font_Metrics associated with Typeface. |
| 4241 | The return value is the recommended spacing between lines: the sum of metrics |
| 4242 | descent, ascent, and leading. |
| 4243 | If metrics is not nullptr, Font_Metrics is copied to metrics. |
| 4244 | Results are scaled by Text_Size but does not take into account |
| 4245 | dimensions required by Text_Scale_X, Text_Skew_X, Fake_Bold, |
| 4246 | Style_Stroke, and Path_Effect. |
| 4247 | Results can be additionally scaled by scale; a scale of zero |
| 4248 | is ignored. |
| 4249 | |
| 4250 | #Param metrics storage for Font_Metrics from Typeface; may be nullptr ## |
| 4251 | #Param scale additional multiplier for returned values ## |
| 4252 | |
| 4253 | #Return recommended spacing between lines ## |
| 4254 | |
| 4255 | #Example |
| 4256 | #Height 128 |
| 4257 | void draw(SkCanvas* canvas) { |
| 4258 | SkPaint paint; |
| 4259 | paint.setTextSize(32); |
| 4260 | SkScalar lineHeight = paint.getFontMetrics(nullptr); |
| 4261 | canvas->drawString("line 1", 10, 40, paint); |
| 4262 | canvas->drawString("line 2", 10, 40 + lineHeight, paint); |
| 4263 | paint.setStyle(SkPaint::kStroke_Style); |
| 4264 | paint.setStrokeWidth(10); |
| 4265 | lineHeight = paint.getFontMetrics(nullptr, 1.10f); // account for stroke height |
| 4266 | canvas->drawString("line 3", 120, 40, paint); |
| 4267 | canvas->drawString("line 4", 120, 40 + lineHeight, paint); |
| 4268 | } |
| 4269 | ## |
| 4270 | |
| 4271 | #SeeAlso Text_Size Typeface Typeface_Methods |
| 4272 | |
| 4273 | ## |
| 4274 | |
| 4275 | |
| 4276 | #Method SkScalar getFontSpacing() const |
| 4277 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4278 | #In Font_Metrics |
| 4279 | #Line # returns recommended spacing between lines ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4280 | Returns the recommended spacing between lines: the sum of metrics |
| 4281 | descent, ascent, and leading. |
| 4282 | Result is scaled by Text_Size but does not take into account |
| 4283 | dimensions required by stroking and Path_Effect. |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 4284 | Returns the same result as getFontMetrics. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4285 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 4286 | #Return recommended spacing between lines ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4287 | |
| 4288 | #Example |
| 4289 | SkPaint paint; |
| 4290 | for (SkScalar textSize : { 12, 18, 24, 32 } ) { |
| 4291 | paint.setTextSize(textSize); |
| 4292 | SkDebugf("textSize: %g fontSpacing: %g\n", textSize, paint.getFontSpacing()); |
| 4293 | } |
| 4294 | |
| 4295 | #StdOut |
| 4296 | textSize: 12 fontSpacing: 13.9688 |
| 4297 | textSize: 18 fontSpacing: 20.9531 |
| 4298 | textSize: 24 fontSpacing: 27.9375 |
| 4299 | textSize: 32 fontSpacing: 37.25 |
| 4300 | ## |
| 4301 | ## |
| 4302 | |
| 4303 | ## |
| 4304 | |
| 4305 | |
| 4306 | #Method SkRect getFontBounds() const |
| 4307 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4308 | #In Font_Metrics |
| 4309 | #Line # returns union all glyph bounds ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4310 | Returns the union of bounds of all Glyphs. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4311 | Returned dimensions are computed by Font_Manager from font data, |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 4312 | ignoring Hinting. Includes Text_Size, Text_Scale_X, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4313 | and Text_Skew_X, but not Fake_Bold or Path_Effect. |
| 4314 | |
| 4315 | If Text_Size is large, Text_Scale_X is one, and Text_Skew_X is zero, |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4316 | returns the same bounds as Font_Metrics { FontMetrics::fXMin, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4317 | FontMetrics::fTop, FontMetrics::fXMax, FontMetrics::fBottom }. |
| 4318 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4319 | #Return union of bounds of all Glyphs ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4320 | |
| 4321 | #Example |
| 4322 | SkPaint paint; |
| 4323 | SkPaint::FontMetrics fm; |
| 4324 | paint.getFontMetrics(&fm); |
| 4325 | SkRect fb = paint.getFontBounds(); |
| 4326 | SkDebugf("metrics bounds = { %g, %g, %g, %g }\n", fm.fXMin, fm.fTop, fm.fXMax, fm.fBottom ); |
| 4327 | SkDebugf("font bounds = { %g, %g, %g, %g }\n", fb.fLeft, fb.fTop, fb.fRight, fm.fBottom ); |
| 4328 | |
| 4329 | #StdOut |
| 4330 | metrics bounds = { -12.2461, -14.7891, 21.5215, 5.55469 } |
| 4331 | font bounds = { -12.2461, -14.7891, 21.5215, 5.55469 } |
| 4332 | ## |
| 4333 | ## |
| 4334 | |
| 4335 | ## |
| 4336 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4337 | #Subtopic Font_Metrics ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4338 | # ------------------------------------------------------------------------------ |
| 4339 | |
| 4340 | #Method int textToGlyphs(const void* text, size_t byteLength, |
| 4341 | SkGlyphID glyphs[]) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4342 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4343 | #Line # converts text into glyph indices ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4344 | |
| 4345 | Converts text into glyph indices. |
| 4346 | Returns the number of glyph indices represented by text. |
| 4347 | Text_Encoding specifies how text represents characters or glyphs. |
| 4348 | glyphs may be nullptr, to compute the glyph count. |
| 4349 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4350 | Does not check text for valid character codes or valid glyph indices. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4351 | |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 4352 | If byteLength equals zero, returns zero. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4353 | If byteLength includes a partial character, the partial character is ignored. |
| 4354 | |
| 4355 | If Text_Encoding is kUTF8_TextEncoding and |
| 4356 | text contains an invalid UTF-8 sequence, zero is returned. |
| 4357 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4358 | #Param text character storage encoded with Text_Encoding ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4359 | #Param byteLength length of character storage in bytes ## |
| 4360 | #Param glyphs storage for glyph indices; may be nullptr ## |
| 4361 | |
| 4362 | #Return number of glyphs represented by text of length byteLength ## |
| 4363 | |
| 4364 | #Example |
| 4365 | #Height 64 |
| 4366 | void draw(SkCanvas* canvas) { |
| 4367 | SkPaint paint; |
| 4368 | const uint8_t utf8[] = { 0x24, 0xC2, 0xA2, 0xE2, 0x82, 0xAC, 0xC2, 0xA5, 0xC2, 0xA3 }; |
| 4369 | std::vector<SkGlyphID> glyphs; |
| 4370 | int count = paint.textToGlyphs(utf8, sizeof(utf8), nullptr); |
| 4371 | glyphs.resize(count); |
| 4372 | (void) paint.textToGlyphs(utf8, sizeof(utf8), &glyphs.front()); |
| 4373 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 4374 | paint.setTextSize(32); |
| 4375 | canvas->drawText(&glyphs.front(), glyphs.size() * sizeof(SkGlyphID), 10, 40, paint); |
| 4376 | } |
| 4377 | ## |
| 4378 | |
| 4379 | ## |
| 4380 | |
| 4381 | #Method int countText(const void* text, size_t byteLength) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4382 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4383 | #Line # returns number of Glyphs in text ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4384 | Returns the number of Glyphs in text. |
| 4385 | Uses Text_Encoding to count the Glyphs. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4386 | Returns the same result as textToGlyphs. |
| 4387 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4388 | #Param text character storage encoded with Text_Encoding ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4389 | #Param byteLength length of character storage in bytes ## |
| 4390 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4391 | #Return number of Glyphs represented by text of length byteLength ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4392 | |
| 4393 | #Example |
| 4394 | SkPaint paint; |
| 4395 | const uint8_t utf8[] = { 0x24, 0xC2, 0xA2, 0xE2, 0x82, 0xAC, 0xC2, 0xA5, 0xC2, 0xA3 }; |
| 4396 | SkDebugf("count = %d\n", paint.countText(utf8, sizeof(utf8))); |
| 4397 | |
| 4398 | #StdOut |
| 4399 | count = 5 |
| 4400 | ## |
| 4401 | ## |
| 4402 | ## |
| 4403 | |
| 4404 | # ------------------------------------------------------------------------------ |
| 4405 | |
| 4406 | #Method bool containsText(const void* text, size_t byteLength) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4407 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4408 | #Line # returns if all text corresponds to Glyphs ## |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4409 | Returns true if all text corresponds to a non-zero glyph index. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4410 | Returns false if any characters in text are not supported in |
| 4411 | Typeface. |
| 4412 | |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 4413 | If Text_Encoding is kGlyphID_TextEncoding, |
| 4414 | returns true if all glyph indices in text are non-zero; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4415 | does not check to see if text contains valid glyph indices for Typeface. |
| 4416 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4417 | Returns true if byteLength is zero. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4418 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4419 | #Param text array of characters or Glyphs ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4420 | #Param byteLength number of bytes in text array ## |
| 4421 | |
| 4422 | #Return true if all text corresponds to a non-zero glyph index ## |
| 4423 | |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 4424 | #NoExample |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4425 | #Description |
| 4426 | containsText succeeds for degree symbol, but cannot find a glyph index |
| 4427 | corresponding to the Unicode surrogate code point. |
| 4428 | ## |
| 4429 | SkPaint paint; |
| 4430 | const uint16_t goodChar = 0x00B0; // degree symbol |
| 4431 | const uint16_t badChar = 0xD800; // Unicode surrogate |
| 4432 | paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4433 | SkDebugf("0x%04x %c= has char\n", goodChar, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4434 | paint.containsText(&goodChar, 2) ? '=' : '!'); |
| 4435 | SkDebugf("0x%04x %c= has char\n", badChar, |
| 4436 | paint.containsText(&badChar, 2) ? '=' : '!'); |
| 4437 | |
| 4438 | #StdOut |
| 4439 | 0x00b0 == has char |
| 4440 | 0xd800 != has char |
| 4441 | ## |
| 4442 | ## |
| 4443 | |
| 4444 | #Example |
| 4445 | #Description |
| 4446 | containsText returns true that glyph index is greater than zero, not |
| 4447 | that it corresponds to an entry in Typeface. |
| 4448 | ## |
| 4449 | SkPaint paint; |
| 4450 | const uint16_t goodGlyph = 511; |
| 4451 | const uint16_t zeroGlyph = 0; |
| 4452 | const uint16_t badGlyph = 65535; // larger than glyph count in font |
| 4453 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4454 | SkDebugf("0x%04x %c= has glyph\n", goodGlyph, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4455 | paint.containsText(&goodGlyph, 2) ? '=' : '!'); |
| 4456 | SkDebugf("0x%04x %c= has glyph\n", zeroGlyph, |
| 4457 | paint.containsText(&zeroGlyph, 2) ? '=' : '!'); |
| 4458 | SkDebugf("0x%04x %c= has glyph\n", badGlyph, |
| 4459 | paint.containsText(&badGlyph, 2) ? '=' : '!'); |
| 4460 | |
| 4461 | #StdOut |
| 4462 | 0x01ff == has glyph |
| 4463 | 0x0000 != has glyph |
| 4464 | 0xffff == has glyph |
| 4465 | ## |
| 4466 | ## |
| 4467 | |
| 4468 | #SeeAlso setTextEncoding Typeface |
| 4469 | |
| 4470 | ## |
| 4471 | |
| 4472 | # ------------------------------------------------------------------------------ |
| 4473 | |
| 4474 | #Method void glyphsToUnichars(const SkGlyphID glyphs[], |
| 4475 | int count, SkUnichar text[]) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4476 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4477 | #Line # converts Glyphs into text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4478 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4479 | Converts glyphs into text if possible. |
| 4480 | Glyph values without direct Unicode equivalents are mapped to zero. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4481 | Uses the Typeface, but is unaffected |
| 4482 | by Text_Encoding; the text values returned are equivalent to kUTF32_TextEncoding. |
| 4483 | |
| 4484 | Only supported on platforms that use FreeType as the Font_Engine. |
| 4485 | |
| 4486 | #Param glyphs array of indices into font ## |
| 4487 | #Param count length of glyph array ## |
| 4488 | #Param text storage for character codes, one per glyph ## |
| 4489 | |
| 4490 | #Example |
| 4491 | #Height 64 |
| 4492 | #Description |
| 4493 | Convert UTF-8 text to glyphs; then convert glyphs to Unichar code points. |
| 4494 | ## |
| 4495 | void draw(SkCanvas* canvas) { |
| 4496 | SkPaint paint; |
| 4497 | const char hello[] = "Hello!"; |
| 4498 | const int count = sizeof(hello) - 1; |
| 4499 | SkGlyphID glyphs[count]; |
| 4500 | if (count != paint.textToGlyphs(hello, count, glyphs)) { |
| 4501 | return; |
| 4502 | } |
| 4503 | SkUnichar unichars[count]; |
| 4504 | paint.glyphsToUnichars(glyphs, count, unichars); |
| 4505 | paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); |
| 4506 | canvas->drawText(unichars, sizeof(unichars), 10, 30, paint); |
| 4507 | } |
| 4508 | ## |
| 4509 | |
| 4510 | ## |
| 4511 | |
| 4512 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4513 | #Subtopic Measure_Text |
| 4514 | #Line # width, height, bounds of text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4515 | |
| 4516 | #Method SkScalar measureText(const void* text, size_t length, SkRect* bounds) const |
| 4517 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4518 | #In Measure_Text |
| 4519 | #Line # returns advance width and bounds of text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4520 | Returns the advance width of text if kVerticalText_Flag is clear, |
| 4521 | and the height of text if kVerticalText_Flag is set. |
| 4522 | The advance is the normal distance to move before drawing additional text. |
| 4523 | Uses Text_Encoding to decode text, Typeface to get the font metrics, |
| 4524 | and Text_Size, Text_Scale_X, Text_Skew_X, Stroke_Width, and |
| 4525 | Path_Effect to scale the metrics and bounds. |
| 4526 | Returns the bounding box of text if bounds is not nullptr. |
| 4527 | The bounding box is computed as if the text was drawn at the origin. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4528 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4529 | #Param text character codes or glyph indices to be measured ## |
| 4530 | #Param length number of bytes of text to measure ## |
| 4531 | #Param bounds returns bounding box relative to (0, 0) if not nullptr ## |
| 4532 | |
| 4533 | #Return advance width or height ## |
| 4534 | |
| 4535 | #Example |
| 4536 | #Height 64 |
| 4537 | void draw(SkCanvas* canvas) { |
| 4538 | SkPaint paint; |
| 4539 | paint.setAntiAlias(true); |
| 4540 | paint.setTextSize(50); |
| 4541 | const char str[] = "ay^jZ"; |
| 4542 | const int count = sizeof(str) - 1; |
| 4543 | canvas->drawText(str, count, 25, 50, paint); |
| 4544 | SkRect bounds; |
| 4545 | paint.measureText(str, count, &bounds); |
| 4546 | canvas->translate(25, 50); |
| 4547 | paint.setStyle(SkPaint::kStroke_Style); |
| 4548 | canvas->drawRect(bounds, paint); |
| 4549 | } |
| 4550 | ## |
| 4551 | |
| 4552 | ## |
| 4553 | |
| 4554 | #Method SkScalar measureText(const void* text, size_t length) const |
| 4555 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4556 | #In Measure_Text |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4557 | Returns the advance width of text if kVerticalText_Flag is clear, |
| 4558 | and the height of text if kVerticalText_Flag is set. |
| 4559 | The advance is the normal distance to move before drawing additional text. |
| 4560 | Uses Text_Encoding to decode text, Typeface to get the font metrics, |
| 4561 | and Text_Size to scale the metrics. |
| 4562 | Does not scale the advance or bounds by Fake_Bold or Path_Effect. |
| 4563 | |
| 4564 | #Param text character codes or glyph indices to be measured ## |
| 4565 | #Param length number of bytes of text to measure ## |
| 4566 | |
| 4567 | #Return advance width or height ## |
| 4568 | |
| 4569 | #Example |
| 4570 | SkPaint paint; |
| 4571 | SkDebugf("default width = %g\n", paint.measureText("!", 1)); |
| 4572 | paint.setTextSize(paint.getTextSize() * 2); |
| 4573 | SkDebugf("double width = %g\n", paint.measureText("!", 1)); |
| 4574 | |
| 4575 | #StdOut |
| 4576 | default width = 5 |
| 4577 | double width = 10 |
| 4578 | ## |
| 4579 | ## |
| 4580 | |
| 4581 | ## |
| 4582 | |
| 4583 | #Method size_t breakText(const void* text, size_t length, SkScalar maxWidth, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4584 | SkScalar* measuredWidth = nullptr) const |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4585 | #In Measure_Text |
| 4586 | #Line # returns text that fits in a width ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4587 | |
| 4588 | Returns the bytes of text that fit within maxWidth. |
| 4589 | If kVerticalText_Flag is clear, the text fragment fits if its advance width is less than or |
| 4590 | equal to maxWidth. |
| 4591 | If kVerticalText_Flag is set, the text fragment fits if its advance height is less than or |
| 4592 | equal to maxWidth. |
| 4593 | Measures only while the advance is less than or equal to maxWidth. |
| 4594 | Returns the advance or the text fragment in measuredWidth if it not nullptr. |
| 4595 | Uses Text_Encoding to decode text, Typeface to get the font metrics, |
| 4596 | and Text_Size to scale the metrics. |
| 4597 | Does not scale the advance or bounds by Fake_Bold or Path_Effect. |
| 4598 | |
| 4599 | #Param text character codes or glyph indices to be measured ## |
| 4600 | #Param length number of bytes of text to measure ## |
| 4601 | #Param maxWidth advance limit; text is measured while advance is less than maxWidth ## |
| 4602 | #Param measuredWidth returns the width of the text less than or equal to maxWidth ## |
| 4603 | #Return bytes of text that fit, always less than or equal to length ## |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4604 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4605 | #Example |
| 4606 | #Description |
| 4607 | Line under "Breakfast" shows desired width, shorter than available characters. |
| 4608 | Line under "Bre" shows measured width after breaking text. |
| 4609 | ## |
| 4610 | #Height 128 |
| 4611 | #Width 280 |
| 4612 | void draw(SkCanvas* canvas) { |
| 4613 | SkPaint paint; |
| 4614 | paint.setAntiAlias(true); |
| 4615 | paint.setTextSize(50); |
| 4616 | const char str[] = "Breakfast"; |
| 4617 | const int count = sizeof(str) - 1; |
| 4618 | canvas->drawText(str, count, 25, 50, paint); |
| 4619 | SkScalar measuredWidth; |
| 4620 | int partialBytes = paint.breakText(str, count, 100, &measuredWidth); |
| 4621 | canvas->drawText(str, partialBytes, 25, 100, paint); |
| 4622 | canvas->drawLine(25, 60, 25 + 100, 60, paint); |
| 4623 | canvas->drawLine(25, 110, 25 + measuredWidth, 110, paint); |
| 4624 | } |
| 4625 | ## |
| 4626 | |
| 4627 | ## |
| 4628 | |
| 4629 | #Method int getTextWidths(const void* text, size_t byteLength, SkScalar widths[], |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4630 | SkRect bounds[] = nullptr) const |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4631 | #In Measure_Text |
| 4632 | #Line # returns advance and bounds for each glyph in text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4633 | |
| 4634 | Retrieves the advance and bounds for each glyph in text, and returns |
| 4635 | the glyph count in text. |
| 4636 | Both widths and bounds may be nullptr. |
| 4637 | If widths is not nullptr, widths must be an array of glyph count entries. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4638 | if bounds is not nullptr, bounds must be an array of glyph count entries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4639 | If kVerticalText_Flag is clear, widths returns the horizontal advance. |
| 4640 | If kVerticalText_Flag is set, widths returns the vertical advance. |
| 4641 | Uses Text_Encoding to decode text, Typeface to get the font metrics, |
| 4642 | and Text_Size to scale the widths and bounds. |
| 4643 | Does not scale the advance by Fake_Bold or Path_Effect. |
| 4644 | Does include Fake_Bold and Path_Effect in the bounds. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4645 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4646 | #Param text character codes or glyph indices to be measured ## |
| 4647 | #Param byteLength number of bytes of text to measure ## |
| 4648 | #Param widths returns text advances for each glyph; may be nullptr ## |
| 4649 | #Param bounds returns bounds for each glyph relative to (0, 0); may be nullptr ## |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4650 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4651 | #Return glyph count in text ## |
| 4652 | |
| 4653 | #Example |
| 4654 | #Height 160 |
| 4655 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4656 | Bounds of Glyphs increase for stroked text, but text advance remains the same. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4657 | The underlines show the text advance, spaced to keep them distinct. |
| 4658 | ## |
| 4659 | void draw(SkCanvas* canvas) { |
| 4660 | SkPaint paint; |
| 4661 | paint.setAntiAlias(true); |
| 4662 | paint.setTextSize(50); |
| 4663 | const char str[] = "abc"; |
| 4664 | const int bytes = sizeof(str) - 1; |
| 4665 | int count = paint.getTextWidths(str, bytes, nullptr); |
| 4666 | std::vector<SkScalar> widths; |
| 4667 | std::vector<SkRect> bounds; |
| 4668 | widths.resize(count); |
| 4669 | bounds.resize(count); |
| 4670 | for (int loop = 0; loop < 2; ++loop) { |
| 4671 | (void) paint.getTextWidths(str, count, &widths.front(), &bounds.front()); |
| 4672 | SkPoint loc = { 25, 50 }; |
| 4673 | canvas->drawText(str, bytes, loc.fX, loc.fY, paint); |
| 4674 | paint.setStyle(SkPaint::kStroke_Style); |
| 4675 | paint.setStrokeWidth(0); |
| 4676 | SkScalar advanceY = loc.fY + 10; |
| 4677 | for (int index = 0; index < count; ++index) { |
| 4678 | bounds[index].offset(loc.fX, loc.fY); |
| 4679 | canvas->drawRect(bounds[index], paint); |
| 4680 | canvas->drawLine(loc.fX, advanceY, loc.fX + widths[index], advanceY, paint); |
| 4681 | loc.fX += widths[index]; |
| 4682 | advanceY += 5; |
| 4683 | } |
| 4684 | canvas->translate(0, 80); |
| 4685 | paint.setStrokeWidth(3); |
| 4686 | } |
| 4687 | } |
| 4688 | ## |
| 4689 | |
| 4690 | ## |
| 4691 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4692 | #Subtopic Measure_Text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4693 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4694 | #Subtopic Text_Path |
| 4695 | #Line # geometry of Glyphs ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4696 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4697 | Text_Path describes the geometry of Glyphs used to draw text. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4698 | |
| 4699 | #Method void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y, |
| 4700 | SkPath* path) const |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4701 | #In Text_Path |
| 4702 | #Line # returns Path equivalent to text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4703 | |
| 4704 | Returns the geometry as Path equivalent to the drawn text. |
| 4705 | Uses Text_Encoding to decode text, Typeface to get the glyph paths, |
| 4706 | and Text_Size, Fake_Bold, and Path_Effect to scale and modify the glyph paths. |
| 4707 | All of the glyph paths are stored in path. |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 4708 | Uses x, y, and Text_Align to position path. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4709 | |
| 4710 | #Param text character codes or glyph indices ## |
| 4711 | #Param length number of bytes of text ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 4712 | #Param x x-axis value of the origin of the text ## |
| 4713 | #Param y y-axis value of the origin of the text ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4714 | #Param path geometry of the Glyphs ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4715 | |
| 4716 | #Example |
| 4717 | #Description |
| 4718 | Text is added to Path, offset, and subtracted from Path, then added at |
| 4719 | the offset location. The result is rendered with one draw call. |
| 4720 | ## |
| 4721 | #Height 128 |
| 4722 | void draw(SkCanvas* canvas) { |
| 4723 | SkPaint paint; |
| 4724 | paint.setTextSize(80); |
| 4725 | SkPath path, path2; |
| 4726 | paint.getTextPath("ABC", 3, 20, 80, &path); |
| 4727 | path.offset(20, 20, &path2); |
| 4728 | Op(path, path2, SkPathOp::kDifference_SkPathOp, &path); |
| 4729 | path.addPath(path2); |
| 4730 | paint.setStyle(SkPaint::kStroke_Style); |
| 4731 | canvas->drawPath(path, paint); |
| 4732 | } |
| 4733 | ## |
| 4734 | |
| 4735 | ## |
| 4736 | |
| 4737 | #Method void getPosTextPath(const void* text, size_t length, |
| 4738 | const SkPoint pos[], SkPath* path) const |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4739 | #In Text_Path |
| 4740 | #Line # returns Path equivalent to positioned text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4741 | |
| 4742 | Returns the geometry as Path equivalent to the drawn text. |
| 4743 | Uses Text_Encoding to decode text, Typeface to get the glyph paths, |
| 4744 | and Text_Size, Fake_Bold, and Path_Effect to scale and modify the glyph paths. |
| 4745 | All of the glyph paths are stored in path. |
| 4746 | Uses pos array and Text_Align to position path. |
| 4747 | pos contains a position for each glyph. |
| 4748 | |
| 4749 | #Param text character codes or glyph indices ## |
| 4750 | #Param length number of bytes of text ## |
| 4751 | #Param pos positions of each glyph ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4752 | #Param path geometry of the Glyphs ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4753 | |
| 4754 | #Example |
| 4755 | #Height 85 |
| 4756 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4757 | Simplifies three Glyphs to eliminate overlaps, and strokes the result. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4758 | ## |
| 4759 | void draw(SkCanvas* canvas) { |
| 4760 | SkPaint paint; |
| 4761 | paint.setTextSize(80); |
| 4762 | SkPath path, path2; |
| 4763 | SkPoint pos[] = {{20, 60}, {30, 70}, {40, 80}}; |
| 4764 | paint.getPosTextPath("ABC", 3, pos, &path); |
| 4765 | Simplify(path, &path); |
| 4766 | paint.setStyle(SkPaint::kStroke_Style); |
| 4767 | canvas->drawPath(path, paint); |
| 4768 | } |
| 4769 | ## |
| 4770 | |
| 4771 | ## |
| 4772 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4773 | #Subtopic Text_Path ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4774 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4775 | #Subtopic Text_Intercepts |
| 4776 | #Line # advanced underline, strike through ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4777 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4778 | Text_Intercepts describe the intersection of drawn text Glyphs with a pair |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4779 | of lines parallel to the text advance. Text_Intercepts permits creating a |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4780 | underline that skips Descenders. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4781 | |
| 4782 | #Method int getTextIntercepts(const void* text, size_t length, SkScalar x, SkScalar y, |
| 4783 | const SkScalar bounds[2], SkScalar* intervals) const |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4784 | #In Text_Intercepts |
| 4785 | #Line # returns where lines intersect text; underlines ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4786 | |
| 4787 | Returns the number of intervals that intersect bounds. |
| 4788 | bounds describes a pair of lines parallel to the text advance. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4789 | The return count is zero or a multiple of two, and is at most twice the number of Glyphs in |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4790 | the string. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4791 | Uses Text_Encoding to decode text, Typeface to get the glyph paths, |
| 4792 | and Text_Size, Fake_Bold, and Path_Effect to scale and modify the glyph paths. |
| 4793 | Uses x, y, and Text_Align to position intervals. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4794 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4795 | Pass nullptr for intervals to determine the size of the interval array. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4796 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4797 | intervals are cached to improve performance for multiple calls. |
| 4798 | |
| 4799 | #Param text character codes or glyph indices ## |
| 4800 | #Param length number of bytes of text ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 4801 | #Param x x-axis value of the origin of the text ## |
| 4802 | #Param y y-axis value of the origin of the text ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4803 | #Param bounds lower and upper line parallel to the advance ## |
| 4804 | #Param intervals returned intersections; may be nullptr ## |
| 4805 | |
| 4806 | #Return number of intersections; may be zero ## |
| 4807 | |
| 4808 | #Example |
| 4809 | #Height 128 |
| 4810 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4811 | Underline uses intercepts to draw on either side of the glyph Descender. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4812 | ## |
| 4813 | void draw(SkCanvas* canvas) { |
| 4814 | SkPaint paint; |
| 4815 | paint.setTextSize(120); |
| 4816 | SkPoint textOrigin = { 20, 100 }; |
| 4817 | SkScalar bounds[] = { 100, 108 }; |
| 4818 | int count = paint.getTextIntercepts("y", 1, textOrigin.fX, textOrigin.fY, bounds, nullptr); |
| 4819 | std::vector<SkScalar> intervals; |
| 4820 | intervals.resize(count); |
| 4821 | (void) paint.getTextIntercepts("y", 1, textOrigin.fX, textOrigin.fY, bounds, |
| 4822 | &intervals.front()); |
| 4823 | canvas->drawString("y", textOrigin.fX, textOrigin.fY, paint); |
| 4824 | paint.setColor(SK_ColorRED); |
| 4825 | SkScalar x = textOrigin.fX; |
| 4826 | for (int i = 0; i < count; i += 2) { |
| 4827 | canvas->drawRect({x, bounds[0], intervals[i], bounds[1]}, paint); |
| 4828 | x = intervals[i + 1]; |
| 4829 | } |
| 4830 | canvas->drawRect({intervals[count - 1], bounds[0], |
| 4831 | textOrigin.fX + paint.measureText("y", 1), bounds[1]}, paint); |
| 4832 | } |
| 4833 | ## |
| 4834 | |
| 4835 | ## |
| 4836 | |
| 4837 | #Method int getPosTextIntercepts(const void* text, size_t length, const SkPoint pos[], |
| 4838 | const SkScalar bounds[2], SkScalar* intervals) const |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4839 | #In Text_Intercepts |
| 4840 | #Line # returns where lines intersect positioned text; underlines ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4841 | |
| 4842 | Returns the number of intervals that intersect bounds. |
| 4843 | bounds describes a pair of lines parallel to the text advance. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4844 | The return count is zero or a multiple of two, and is at most twice the number of Glyphs in |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4845 | the string. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4846 | Uses Text_Encoding to decode text, Typeface to get the glyph paths, |
| 4847 | and Text_Size, Fake_Bold, and Path_Effect to scale and modify the glyph paths. |
| 4848 | Uses pos array and Text_Align to position intervals. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4849 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4850 | Pass nullptr for intervals to determine the size of the interval array. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4851 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4852 | intervals are cached to improve performance for multiple calls. |
| 4853 | |
| 4854 | #Param text character codes or glyph indices ## |
| 4855 | #Param length number of bytes of text ## |
| 4856 | #Param pos positions of each glyph ## |
| 4857 | #Param bounds lower and upper line parallel to the advance ## |
| 4858 | #Param intervals returned intersections; may be nullptr ## |
| 4859 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 4860 | #Return number of intersections; may be zero ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4861 | |
| 4862 | #Example |
| 4863 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4864 | Text intercepts draw on either side of, but not inside, Glyphs in a run. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4865 | ## |
| 4866 | void draw(SkCanvas* canvas) { |
| 4867 | SkPaint paint; |
| 4868 | paint.setTextSize(120); |
| 4869 | paint.setVerticalText(true); |
| 4870 | SkPoint textPos[] = {{ 60, 40 }, { 60, 140 }}; |
| 4871 | SkScalar bounds[] = { 56, 64 }; |
| 4872 | const char str[] = "A-"; |
| 4873 | int len = sizeof(str) - 1; |
| 4874 | int count = paint.getPosTextIntercepts(str, len, textPos, bounds, nullptr); |
| 4875 | std::vector<SkScalar> intervals; |
| 4876 | intervals.resize(count); |
| 4877 | (void) paint.getPosTextIntercepts(str, len, textPos, bounds, &intervals.front()); |
| 4878 | canvas->drawPosText(str, len, textPos, paint); |
| 4879 | paint.setColor(SK_ColorRED); |
| 4880 | SkScalar y = textPos[0].fY; |
| 4881 | for (int i = 0; i < count; i+= 2) { |
| 4882 | canvas->drawRect({bounds[0], y, bounds[1], intervals[i]}, paint); |
| 4883 | y = intervals[i + 1]; |
| 4884 | } |
| 4885 | canvas->drawRect({bounds[0], intervals[count - 1], bounds[1], 240}, paint); |
| 4886 | } |
| 4887 | ## |
| 4888 | |
| 4889 | ## |
| 4890 | |
| 4891 | #Method int getPosTextHIntercepts(const void* text, size_t length, const SkScalar xpos[], |
| 4892 | SkScalar constY, const SkScalar bounds[2], |
| 4893 | SkScalar* intervals) const |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4894 | #In Text_Intercepts |
| 4895 | #Line # returns where lines intersect horizontally positioned text; underlines ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4896 | |
| 4897 | Returns the number of intervals that intersect bounds. |
| 4898 | bounds describes a pair of lines parallel to the text advance. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4899 | The return count is zero or a multiple of two, and is at most twice the number of Glyphs in |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4900 | the string. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4901 | Uses Text_Encoding to decode text, Typeface to get the glyph paths, |
| 4902 | and Text_Size, Fake_Bold, and Path_Effect to scale and modify the glyph paths. |
| 4903 | Uses xpos array, constY, and Text_Align to position intervals. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4904 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4905 | Pass nullptr for intervals to determine the size of the interval array. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4906 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4907 | intervals are cached to improve performance for multiple calls. |
| 4908 | |
| 4909 | #Param text character codes or glyph indices ## |
| 4910 | #Param length number of bytes of text ## |
| 4911 | #Param xpos positions of each glyph in x ## |
| 4912 | #Param constY position of each glyph in y ## |
| 4913 | #Param bounds lower and upper line parallel to the advance ## |
| 4914 | #Param intervals returned intersections; may be nullptr ## |
| 4915 | |
| 4916 | #Return number of intersections; may be zero ## |
| 4917 | |
| 4918 | #Example |
| 4919 | #Height 128 |
| 4920 | #Description |
| 4921 | Text intercepts do not take stroke thickness into consideration. |
| 4922 | ## |
| 4923 | void draw(SkCanvas* canvas) { |
| 4924 | SkPaint paint; |
| 4925 | paint.setTextSize(120); |
| 4926 | paint.setStyle(SkPaint::kStroke_Style); |
| 4927 | paint.setStrokeWidth(4); |
| 4928 | SkScalar textPosH[] = { 20, 80, 140 }; |
| 4929 | SkScalar y = 100; |
| 4930 | SkScalar bounds[] = { 56, 78 }; |
| 4931 | const char str[] = "\\-/"; |
| 4932 | int len = sizeof(str) - 1; |
| 4933 | int count = paint.getPosTextHIntercepts(str, len, textPosH, y, bounds, nullptr); |
| 4934 | std::vector<SkScalar> intervals; |
| 4935 | intervals.resize(count); |
| 4936 | (void) paint.getPosTextHIntercepts(str, len, textPosH, y, bounds, &intervals.front()); |
| 4937 | canvas->drawPosTextH(str, len, textPosH, y, paint); |
| 4938 | paint.setColor(0xFFFF7777); |
| 4939 | paint.setStyle(SkPaint::kFill_Style); |
| 4940 | SkScalar x = textPosH[0]; |
| 4941 | for (int i = 0; i < count; i+= 2) { |
| 4942 | canvas->drawRect({x, bounds[0], intervals[i], bounds[1]}, paint); |
| 4943 | x = intervals[i + 1]; |
| 4944 | } |
| 4945 | canvas->drawRect({intervals[count - 1], bounds[0], 180, bounds[1]}, paint); |
| 4946 | } |
| 4947 | ## |
| 4948 | |
| 4949 | ## |
| 4950 | |
| 4951 | |
| 4952 | #Method int getTextBlobIntercepts(const SkTextBlob* blob, const SkScalar bounds[2], |
| 4953 | SkScalar* intervals) const |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4954 | #In Text_Intercepts |
| 4955 | #Line # returns where lines intersect Text_Blob; underlines ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4956 | |
| 4957 | Returns the number of intervals that intersect bounds. |
| 4958 | bounds describes a pair of lines parallel to the text advance. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4959 | The return count is zero or a multiple of two, and is at most twice the number of Glyphs in |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4960 | the string. |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 4961 | Uses Typeface to get the glyph paths, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4962 | and Text_Size, Fake_Bold, and Path_Effect to scale and modify the glyph paths. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4963 | Uses run array and Text_Align to position intervals. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4964 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 4965 | Text_Encoding must be set to SkPaint::kGlyphID_TextEncoding. |
| 4966 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4967 | Pass nullptr for intervals to determine the size of the interval array. |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4968 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4969 | intervals are cached to improve performance for multiple calls. |
| 4970 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4971 | #Param blob Glyphs, positions, and text paint attributes ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4972 | #Param bounds lower and upper line parallel to the advance ## |
| 4973 | #Param intervals returned intersections; may be nullptr ## |
| 4974 | |
| 4975 | #Return number of intersections; may be zero ## |
| 4976 | |
| 4977 | #Example |
| 4978 | #Height 143 |
| 4979 | void draw(SkCanvas* canvas) { |
| 4980 | SkPaint paint; |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 4981 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4982 | paint.setTextSize(120); |
| 4983 | SkPoint textPos = { 20, 110 }; |
| 4984 | int len = 3; |
| 4985 | SkTextBlobBuilder textBlobBuilder; |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4986 | const SkTextBlobBuilder::RunBuffer& run = |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4987 | textBlobBuilder.allocRun(paint, len, textPos.fX, textPos.fY); |
| 4988 | run.glyphs[0] = 10; |
| 4989 | run.glyphs[1] = 20; |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 4990 | run.glyphs[2] = 30; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4991 | sk_sp<const SkTextBlob> blob = textBlobBuilder.make(); |
| 4992 | canvas->drawTextBlob(blob.get(), textPos.fX, textPos.fY, paint); |
| 4993 | SkScalar bounds[] = { 116, 134 }; |
| 4994 | int count = paint.getTextBlobIntercepts(blob.get(), bounds, nullptr); |
| 4995 | std::vector<SkScalar> intervals; |
| 4996 | intervals.resize(count); |
| 4997 | (void) paint.getTextBlobIntercepts(blob.get(), bounds, &intervals.front()); |
| 4998 | canvas->drawTextBlob(blob.get(), 0, 0, paint); |
| 4999 | paint.setColor(0xFFFF7777); |
| 5000 | SkScalar x = textPos.fX; |
| 5001 | for (int i = 0; i < count; i+= 2) { |
| 5002 | canvas->drawRect({x, bounds[0], intervals[i], bounds[1]}, paint); |
| 5003 | x = intervals[i + 1]; |
| 5004 | } |
| 5005 | canvas->drawRect({intervals[count - 1], bounds[0], 180, bounds[1]}, paint); |
| 5006 | } |
| 5007 | ## |
| 5008 | |
| 5009 | ## |
| 5010 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 5011 | #Subtopic Text_Intercepts ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5012 | # ------------------------------------------------------------------------------ |
| 5013 | |
| 5014 | #Method bool nothingToDraw() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5015 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5016 | #Line # returns true if Paint prevents all drawing ## |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 5017 | Returns true if Paint prevents all drawing; |
| 5018 | otherwise, the Paint may or may not allow drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5019 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5020 | Returns true if, for example, Blend_Mode combined with Color_Alpha computes a |
| 5021 | new Alpha of zero. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5022 | |
| 5023 | #Return true if Paint prevents all drawing ## |
| 5024 | |
| 5025 | #Example |
| 5026 | void draw(SkCanvas* canvas) { |
| 5027 | auto debugster = [](const char* prefix, const SkPaint& p) -> void { |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 5028 | SkDebugf("%s nothing to draw: %s\n", prefix, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5029 | p.nothingToDraw() ? "true" : "false"); |
| 5030 | }; |
| 5031 | SkPaint paint; |
| 5032 | debugster("initial", paint); |
| 5033 | paint.setBlendMode(SkBlendMode::kDst); |
| 5034 | debugster("blend dst", paint); |
| 5035 | paint.setBlendMode(SkBlendMode::kSrcOver); |
| 5036 | debugster("blend src over", paint); |
| 5037 | paint.setAlpha(0); |
| 5038 | debugster("alpha 0", paint); |
| 5039 | } |
| 5040 | |
| 5041 | #StdOut |
| 5042 | initial nothing to draw: false |
| 5043 | blend dst nothing to draw: true |
| 5044 | blend src over nothing to draw: false |
| 5045 | alpha 0 nothing to draw: true |
| 5046 | #StdOut ## |
| 5047 | ## |
| 5048 | |
| 5049 | ## |
| 5050 | |
| 5051 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 5052 | #Subtopic Fast_Bounds |
| 5053 | #Line # approximate area required by Paint ## |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 5054 | #Private |
| 5055 | To be made private. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5056 | ## |
| 5057 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5058 | Fast_Bounds functions conservatively outset a drawing bounds by additional area |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5059 | Paint may draw to. |
| 5060 | |
| 5061 | #Method bool canComputeFastBounds() const |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 5062 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5063 | #In Fast_Bounds |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 5064 | #Line # returns true if settings allow for fast bounds computation ## |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 5065 | #Private |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5066 | (to be made private) |
| 5067 | ## |
| 5068 | |
| 5069 | Returns true if Paint does not include elements requiring extensive computation |
| 5070 | to compute Device bounds of drawn geometry. For instance, Paint with Path_Effect |
| 5071 | always returns false. |
| 5072 | |
| 5073 | #Return true if Paint allows for fast computation of bounds ## |
| 5074 | ## |
| 5075 | |
| 5076 | #Method const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 5077 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5078 | #In Fast_Bounds |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 5079 | #Line # returns fill bounds for quick reject tests ## |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 5080 | #Private |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5081 | (to be made private) |
| 5082 | ## |
| 5083 | |
| 5084 | Only call this if canComputeFastBounds returned true. This takes a |
| 5085 | raw rectangle (the raw bounds of a shape), and adjusts it for stylistic |
| 5086 | effects in the paint (e.g. stroking). If needed, it uses the storage |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5087 | parameter. It returns the adjusted bounds that can then be used |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5088 | for SkCanvas::quickReject tests. |
| 5089 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5090 | The returned Rect will either be orig or storage, thus the caller |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5091 | should not rely on storage being set to the result, but should always |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5092 | use the returned value. It is legal for orig and storage to be the same |
| 5093 | Rect. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5094 | |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 5095 | #Private |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5096 | For example: |
| 5097 | if (!path.isInverseFillType() && paint.canComputeFastBounds()) { |
| 5098 | SkRect storage; |
| 5099 | if (canvas->quickReject(paint.computeFastBounds(path.getBounds(), &storage))) { |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 5100 | return; // do not draw the path |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5101 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5102 | } |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5103 | // draw the path |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5104 | ## |
| 5105 | |
| 5106 | #Param orig geometry modified by Paint when drawn ## |
| 5107 | #Param storage computed bounds of geometry; may not be nullptr ## |
| 5108 | |
| 5109 | #Return fast computed bounds ## |
| 5110 | ## |
| 5111 | |
| 5112 | #Method const SkRect& computeFastStrokeBounds(const SkRect& orig, |
| 5113 | SkRect* storage) const |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5114 | #In Fast_Bounds |
| 5115 | #Line # returns stroke bounds for quick reject tests ## |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 5116 | #Private |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5117 | (to be made private) |
| 5118 | ## |
| 5119 | |
| 5120 | #Param orig geometry modified by Paint when drawn ## |
| 5121 | #Param storage computed bounds of geometry ## |
| 5122 | |
| 5123 | #Return fast computed bounds ## |
| 5124 | ## |
| 5125 | |
| 5126 | #Method const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage, |
| 5127 | Style style) const |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5128 | #In Fast_Bounds |
| 5129 | #Line # returns bounds for quick reject tests ## |
Herb Derby | fcac00f | 2018-05-01 11:57:56 -0400 | [diff] [blame] | 5130 | #Private |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5131 | (to be made private) |
| 5132 | ## |
| 5133 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5134 | Computes the bounds, overriding the Paint Style. This can be used to |
| 5135 | account for additional width required by stroking orig, without |
| 5136 | altering Style set to fill. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5137 | |
| 5138 | #Param orig geometry modified by Paint when drawn ## |
| 5139 | #Param storage computed bounds of geometry ## |
| 5140 | #Param style overrides Style ## |
| 5141 | |
| 5142 | #Return fast computed bounds ## |
| 5143 | ## |
| 5144 | |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 5145 | #Subtopic Fast_Bounds ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5146 | |
| 5147 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5148 | #Subtopic Utility |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5149 | #Line # rarely called management functions ## |
| 5150 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5151 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5152 | # ------------------------------------------------------------------------------ |
| 5153 | |
| 5154 | #Class SkPaint ## |
| 5155 | |
| 5156 | #Topic Paint ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 5157 | |