Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 1 | #Topic Text_Blob_Builder |
| 2 | #Alias Text_Blob_Builder_Reference ## |
| 3 | |
| 4 | #Class SkTextBlobBuilder |
| 5 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 6 | #Code |
| 7 | #Populate |
| 8 | ## |
| 9 | |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 10 | Helper class for constructing SkTextBlob. |
| 11 | |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 12 | # ------------------------------------------------------------------------------ |
| 13 | |
| 14 | #Struct RunBuffer |
| 15 | #Line # storage for Glyphs and Glyph positions ## |
| 16 | |
| 17 | #Code |
| 18 | struct RunBuffer { |
| 19 | SkGlyphID* glyphs; |
| 20 | SkScalar* pos; |
| 21 | char* utf8text; |
| 22 | uint32_t* clusters; |
| 23 | }; |
| 24 | ## |
| 25 | |
| 26 | RunBuffer supplies storage for Glyphs and positions within a run. |
| 27 | |
| 28 | A run is a sequence of Glyphs sharing Paint_Font_Metrics and positioning. |
| 29 | Each run may position its Glyphs in one of three ways: |
| 30 | by specifying where the first Glyph is drawn, and allowing Paint_Font_Metrics to |
| 31 | determine the advance to subsequent Glyphs; by specifying a baseline, and |
| 32 | the position on that baseline for each Glyph in run; or by providing Point |
| 33 | array, one per Glyph. |
| 34 | |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 35 | #Member SkGlyphID* glyphs |
| 36 | #Line # storage for Glyphs in run ## |
| 37 | glyphs points to memory for one or more Glyphs. glyphs memory must be |
| 38 | written to by the caller. |
| 39 | ## |
| 40 | |
| 41 | #Member SkScalar* pos |
| 42 | #Line # storage for positions in run ## |
| 43 | pos points to memory for Glyph positions. Depending on how RunBuffer |
| 44 | is allocated, pos may point to zero bytes per Glyph, one Scalar per Glyph, |
| 45 | or one Point per Glyph. |
| 46 | ## |
| 47 | |
| 48 | #Member char* utf8text |
| 49 | #Line # reserved for future use ## |
| 50 | Reserved for future use. utf8text should not be read or written. |
| 51 | ## |
| 52 | |
| 53 | #Member uint32_t* clusters |
| 54 | #Line # reserved for future use ## |
| 55 | Reserved for future use. clusters should not be read or written. |
| 56 | ## |
| 57 | |
| 58 | #SeeAlso allocRun allocRunPos allocRunPosH |
| 59 | |
| 60 | #Struct RunBuffer ## |
| 61 | |
| 62 | # ------------------------------------------------------------------------------ |
| 63 | |
| 64 | #Method SkTextBlobBuilder() |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 65 | #In Constructors |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 66 | #Line # constructs with default values ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 67 | #Populate |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 68 | |
| 69 | #Example |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 70 | SkTextBlobBuilder builder; |
| 71 | sk_sp<SkTextBlob> blob = builder.make(); |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 72 | SkDebugf("blob " "%s" " nullptr", blob == nullptr ? "equals" : "does not equal"); |
| 73 | #StdOut |
| 74 | blob equals nullptr |
| 75 | ## |
| 76 | ## |
| 77 | |
| 78 | #SeeAlso make SkTextBlob::MakeFromText |
| 79 | |
| 80 | #Method ## |
| 81 | |
| 82 | # ------------------------------------------------------------------------------ |
| 83 | |
| 84 | #Method ~SkTextBlobBuilder() |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 85 | #In Constructors |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 86 | #Line # deletes storage ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 87 | #Populate |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 88 | |
| 89 | #NoExample |
| 90 | ## |
| 91 | |
| 92 | #SeeAlso SkTextBlobBuilder() |
| 93 | |
| 94 | #Method ## |
| 95 | |
| 96 | # ------------------------------------------------------------------------------ |
| 97 | |
| 98 | #Method sk_sp<SkTextBlob> make() |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 99 | #In Constructors |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 100 | #Line # constructs Text_Blob from bulider ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 101 | #Populate |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 102 | |
| 103 | #Example |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 104 | SkTextBlobBuilder builder; |
| 105 | sk_sp<SkTextBlob> blob = builder.make(); |
| 106 | SkDebugf("blob " "%s" " nullptr\n", blob == nullptr ? "equals" : "does not equal"); |
| 107 | SkPaint paint; |
| 108 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 109 | paint.textToGlyphs("x", 1, builder.allocRun(paint, 1, 20, 20).glyphs); |
| 110 | blob = builder.make(); |
| 111 | SkDebugf("blob " "%s" " nullptr\n", blob == nullptr ? "equals" : "does not equal"); |
| 112 | blob = builder.make(); |
| 113 | SkDebugf("blob " "%s" " nullptr\n", blob == nullptr ? "equals" : "does not equal"); |
| 114 | #StdOut |
| 115 | blob equals nullptr |
| 116 | blob does not equal nullptr |
| 117 | blob equals nullptr |
| 118 | ## |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 119 | ## |
| 120 | |
| 121 | #SeeAlso SkTextBlob::MakeFromText |
| 122 | |
| 123 | #Method ## |
| 124 | |
| 125 | # ------------------------------------------------------------------------------ |
| 126 | |
| 127 | #Method const RunBuffer& allocRun(const SkPaint& font, int count, SkScalar x, SkScalar y, |
| 128 | const SkRect* bounds = nullptr) |
| 129 | #In Allocator |
| 130 | #Line # returns writable glyph buffer at Point ## |
| 131 | |
| 132 | Returns run with storage for Glyphs. Caller must write count Glyphs to |
| 133 | RunBuffer.glyphs before next call to FontBlobBuilder. |
| 134 | |
| 135 | RunBuffer.utf8text, and RunBuffer.clusters should be ignored. |
| 136 | |
| 137 | Glyphs share Paint_Font_Metrics in font, including: #paint_font_metrics#. |
| 138 | |
| 139 | Glyphs are positioned on a baseline at (x, y), using font Paint_Font_Metrics to |
| 140 | determine their relative placement. |
| 141 | |
| 142 | bounds defines an optional bounding box, used to suppress drawing when Text_Blob |
| 143 | bounds does not intersect Surface bounds. If bounds is nullptr, Text_Blob bounds |
| 144 | is computed from (x, y) and RunBuffer.glyphs Paint_Font_Metrics. |
| 145 | |
| 146 | #Param font Paint used for this run ## |
| 147 | #Param count number of glyphs ## |
| 148 | #Param x horizontal offset within the blob ## |
| 149 | #Param y vertical offset within the blob ## |
| 150 | #Param bounds optional run bounding box ## |
| 151 | |
| 152 | #Return writable glyph buffer ## |
| 153 | |
| 154 | #Example |
| 155 | #Height 60 |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 156 | SkTextBlobBuilder builder; |
| 157 | SkPaint paint, glyphPaint; |
| 158 | glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 159 | const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(glyphPaint, 5, 20, 20); |
| 160 | paint.textToGlyphs("hello", 5, run.glyphs); |
| 161 | canvas->drawRect({20, 20, 30, 30}, paint); |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 162 | canvas->drawTextBlob(builder.make(), 20, 20, paint); |
| 163 | ## |
| 164 | |
| 165 | #SeeAlso allocRunPosH allocRunPos |
| 166 | |
| 167 | #Method ## |
| 168 | |
| 169 | # ------------------------------------------------------------------------------ |
| 170 | |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 171 | #Method const RunBuffer& allocRun(const SkFont& font, int count, SkScalar x, SkScalar y, |
| 172 | const SkRect* bounds = nullptr) |
| 173 | #In Allocator |
| 174 | #Line # returns writable glyph buffer at Point ## |
| 175 | |
| 176 | Returns run with storage for Glyphs. Caller must write count Glyphs to |
| 177 | RunBuffer.glyphs before next call to FontBlobBuilder. |
| 178 | |
| 179 | RunBuffer.utf8text, and RunBuffer.clusters should be ignored. |
| 180 | |
| 181 | Glyphs share Paint_Font_Metrics in font, including: #paint_font_metrics#. |
| 182 | |
| 183 | Glyphs are positioned on a baseline at (x, y), using font Paint_Font_Metrics to |
| 184 | determine their relative placement. |
| 185 | |
| 186 | bounds defines an optional bounding box, used to suppress drawing when Text_Blob |
| 187 | bounds does not intersect Surface bounds. If bounds is nullptr, Text_Blob bounds |
| 188 | is computed from (x, y) and RunBuffer.glyphs Paint_Font_Metrics. |
| 189 | |
| 190 | #Param font Font used for this run ## |
| 191 | #Param count number of glyphs ## |
| 192 | #Param x horizontal offset within the blob ## |
| 193 | #Param y vertical offset within the blob ## |
| 194 | #Param bounds optional run bounding box ## |
| 195 | |
| 196 | #Return writable glyph buffer ## |
| 197 | |
| 198 | #Example |
| 199 | #Height 60 |
| 200 | SkTextBlobBuilder builder; |
| 201 | SkFont font; |
| 202 | SkPaint paint; |
| 203 | const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(font, 5, 20, 20); |
| 204 | paint.textToGlyphs("hello", 5, run.glyphs); |
| 205 | canvas->drawRect({20, 20, 30, 30}, paint); |
| 206 | canvas->drawTextBlob(builder.make(), 20, 20, paint); |
| 207 | ## |
| 208 | |
| 209 | #SeeAlso allocRunPosH allocRunPos |
| 210 | |
| 211 | #Method ## |
| 212 | |
| 213 | # ------------------------------------------------------------------------------ |
| 214 | |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 215 | #Method const RunBuffer& allocRunPosH(const SkPaint& font, int count, SkScalar y, |
| 216 | const SkRect* bounds = nullptr) |
| 217 | #In Allocator |
| 218 | #Line # returns writable glyph and x-axis position buffers ## |
| 219 | |
| 220 | Returns run with storage for Glyphs and positions along baseline. Caller must |
| 221 | write count Glyphs to RunBuffer.glyphs, and count Scalars to RunBuffer.pos; |
| 222 | before next call to FontBlobBuilder. |
| 223 | |
| 224 | RunBuffer.utf8text, and RunBuffer.clusters should be ignored. |
| 225 | |
| 226 | Glyphs share Paint_Font_Metrics in font, including: #paint_font_metrics#. |
| 227 | |
| 228 | Glyphs are positioned on a baseline at y, using x-axis positions written by |
| 229 | caller to RunBuffer.pos. |
| 230 | |
| 231 | bounds defines an optional bounding box, used to suppress drawing when Text_Blob |
| 232 | bounds does not intersect Surface bounds. If bounds is nullptr, Text_Blob bounds |
| 233 | is computed from y, RunBuffer.pos, and RunBuffer.glyphs Paint_Font_Metrics. |
| 234 | |
| 235 | #Param font Paint used for this run ## |
| 236 | #Param count number of Glyphs ## |
| 237 | #Param y vertical offset within the blob ## |
| 238 | #Param bounds optional run bounding box ## |
| 239 | |
| 240 | #Return writable glyph buffer and x-axis position buffer ## |
| 241 | |
| 242 | #Example |
| 243 | #Height 60 |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 244 | SkTextBlobBuilder builder; |
| 245 | SkPaint paint, glyphPaint; |
| 246 | glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 247 | const SkTextBlobBuilder::RunBuffer& run = builder.allocRunPosH(glyphPaint, 5, 20); |
| 248 | paint.textToGlyphs("hello", 5, run.glyphs); |
| 249 | SkScalar positions[] = {0, 10, 20, 40, 80}; |
| 250 | memcpy(run.pos, positions, sizeof(positions)); |
| 251 | canvas->drawTextBlob(builder.make(), 20, 20, paint); |
| 252 | ## |
| 253 | |
| 254 | #SeeAlso allocRunPos allocRun |
| 255 | |
| 256 | #Method ## |
| 257 | |
| 258 | # ------------------------------------------------------------------------------ |
| 259 | |
| 260 | #Method const RunBuffer& allocRunPosH(const SkFont& font, int count, SkScalar y, |
| 261 | const SkRect* bounds = nullptr) |
| 262 | #In Allocator |
| 263 | #Line # returns writable glyph and x-axis position buffers ## |
| 264 | |
| 265 | Returns run with storage for Glyphs and positions along baseline. Caller must |
| 266 | write count Glyphs to RunBuffer.glyphs, and count Scalars to RunBuffer.pos; |
| 267 | before next call to FontBlobBuilder. |
| 268 | |
| 269 | RunBuffer.utf8text, and RunBuffer.clusters should be ignored. |
| 270 | |
| 271 | Glyphs share Paint_Font_Metrics in font, including: #paint_font_metrics#. |
| 272 | |
| 273 | Glyphs are positioned on a baseline at y, using x-axis positions written by |
| 274 | caller to RunBuffer.pos. |
| 275 | |
| 276 | bounds defines an optional bounding box, used to suppress drawing when Text_Blob |
| 277 | bounds does not intersect Surface bounds. If bounds is nullptr, Text_Blob bounds |
| 278 | is computed from y, RunBuffer.pos, and RunBuffer.glyphs Paint_Font_Metrics. |
| 279 | |
| 280 | #Param font Font used for this run ## |
| 281 | #Param count number of Glyphs ## |
| 282 | #Param y vertical offset within the blob ## |
| 283 | #Param bounds optional run bounding box ## |
| 284 | |
| 285 | #Return writable glyph buffer and x-axis position buffer ## |
| 286 | |
| 287 | #Example |
| 288 | #Height 60 |
| 289 | SkTextBlobBuilder builder; |
| 290 | SkPaint paint; |
| 291 | SkFont font; |
| 292 | const SkTextBlobBuilder::RunBuffer& run = builder.allocRunPosH(font, 5, 20); |
| 293 | paint.textToGlyphs("hello", 5, run.glyphs); |
| 294 | SkScalar positions[] = {0, 10, 20, 40, 80}; |
| 295 | memcpy(run.pos, positions, sizeof(positions)); |
| 296 | canvas->drawTextBlob(builder.make(), 20, 20, paint); |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 297 | ## |
| 298 | |
| 299 | #SeeAlso allocRunPos allocRun |
| 300 | |
| 301 | #Method ## |
| 302 | |
| 303 | # ------------------------------------------------------------------------------ |
| 304 | |
| 305 | #Method const RunBuffer& allocRunPos(const SkPaint& font, int count, |
| 306 | const SkRect* bounds = nullptr) |
| 307 | #In Allocator |
| 308 | #Line # returns writable glyph and Point buffers ## |
| 309 | |
| 310 | Returns run with storage for Glyphs and Point positions. Caller must |
| 311 | write count Glyphs to RunBuffer.glyphs, and count Points to RunBuffer.pos; |
| 312 | before next call to FontBlobBuilder. |
| 313 | |
| 314 | RunBuffer.utf8text, and RunBuffer.clusters should be ignored. |
| 315 | |
| 316 | Glyphs share Paint_Font_Metrics in font, including: #paint_font_metrics#. |
| 317 | |
| 318 | Glyphs are positioned using Points written by caller to RunBuffer.pos, using |
| 319 | two Scalar values for each Point. |
| 320 | |
| 321 | bounds defines an optional bounding box, used to suppress drawing when Text_Blob |
| 322 | bounds does not intersect Surface bounds. If bounds is nullptr, Text_Blob bounds |
| 323 | is computed from RunBuffer.pos, and RunBuffer.glyphs Paint_Font_Metrics. |
| 324 | |
| 325 | #Param font Paint used for this run ## |
| 326 | #Param count number of Glyphs ## |
| 327 | #Param bounds optional run bounding box ## |
| 328 | |
| 329 | #Return writable glyph buffer and Point buffer ## |
| 330 | |
| 331 | #Example |
| 332 | #Height 90 |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 333 | SkTextBlobBuilder builder; |
| 334 | SkPaint paint, font; |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 335 | font.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 336 | const SkTextBlobBuilder::RunBuffer& run = builder.allocRunPos(font, 5); |
| 337 | paint.textToGlyphs("hello", 5, run.glyphs); |
| 338 | SkPoint positions[] = {{0, 0}, {10, 10}, {20, 20}, {40, 40}, {80, 80}}; |
| 339 | memcpy(run.pos, positions, sizeof(positions)); |
| 340 | canvas->drawTextBlob(builder.make(), 20, 20, paint); |
| 341 | ## |
| 342 | |
| 343 | #SeeAlso allocRunPosH allocRun |
| 344 | |
| 345 | #Method ## |
| 346 | |
| 347 | # ------------------------------------------------------------------------------ |
| 348 | |
| 349 | #Method const RunBuffer& allocRunPos(const SkFont& font, int count, |
| 350 | const SkRect* bounds = nullptr) |
| 351 | #In Allocator |
| 352 | #Line # returns writable glyph and Point buffers ## |
| 353 | |
| 354 | Returns run with storage for Glyphs and Point positions. Caller must |
| 355 | write count Glyphs to RunBuffer.glyphs, and count Points to RunBuffer.pos; |
| 356 | before next call to FontBlobBuilder. |
| 357 | |
| 358 | RunBuffer.utf8text, and RunBuffer.clusters should be ignored. |
| 359 | |
| 360 | Glyphs share Paint_Font_Metrics in font, including: #paint_font_metrics#. |
| 361 | |
| 362 | Glyphs are positioned using Points written by caller to RunBuffer.pos, using |
| 363 | two Scalar values for each Point. |
| 364 | |
| 365 | bounds defines an optional bounding box, used to suppress drawing when Text_Blob |
| 366 | bounds does not intersect Surface bounds. If bounds is nullptr, Text_Blob bounds |
| 367 | is computed from RunBuffer.pos, and RunBuffer.glyphs Paint_Font_Metrics. |
| 368 | |
| 369 | #Param font Font used for this run ## |
| 370 | #Param count number of Glyphs ## |
| 371 | #Param bounds optional run bounding box ## |
| 372 | |
| 373 | #Return writable glyph buffer and Point buffer ## |
| 374 | |
| 375 | #Example |
| 376 | #Height 90 |
| 377 | SkTextBlobBuilder builder; |
| 378 | SkPaint paint; |
| 379 | SkFont font; |
| 380 | const SkTextBlobBuilder::RunBuffer& run = builder.allocRunPos(font, 5); |
| 381 | paint.textToGlyphs("hello", 5, run.glyphs); |
| 382 | SkPoint positions[] = {{0, 0}, {10, 10}, {20, 20}, {40, 40}, {80, 80}}; |
| 383 | memcpy(run.pos, positions, sizeof(positions)); |
| 384 | canvas->drawTextBlob(builder.make(), 20, 20, paint); |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 385 | ## |
| 386 | |
| 387 | #SeeAlso allocRunPosH allocRun |
| 388 | |
| 389 | #Method ## |
| 390 | |
| 391 | #Class SkTextBlobBuilder ## |
| 392 | |
| 393 | #Topic Text_Blob_Builder ## |