blob: 306ac06918bfa227c0986ad583fe36ffe9b4c05e [file] [log] [blame]
Cary Clarkd2ca79c2018-08-10 13:09:13 -04001#Topic Text_Blob_Builder
2#Alias Text_Blob_Builder_Reference ##
3
4#Class SkTextBlobBuilder
5
Cary Clark61313f32018-10-08 14:57:48 -04006#Code
7#Populate
8##
9
Cary Clarkd2ca79c2018-08-10 13:09:13 -040010Helper class for constructing SkTextBlob.
11
Cary Clarkd2ca79c2018-08-10 13:09:13 -040012# ------------------------------------------------------------------------------
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
26RunBuffer supplies storage for Glyphs and positions within a run.
27
28A run is a sequence of Glyphs sharing Paint_Font_Metrics and positioning.
29Each run may position its Glyphs in one of three ways:
30by specifying where the first Glyph is drawn, and allowing Paint_Font_Metrics to
31determine the advance to subsequent Glyphs; by specifying a baseline, and
32the position on that baseline for each Glyph in run; or by providing Point
33array, one per Glyph.
34
Cary Clarkd2ca79c2018-08-10 13:09:13 -040035#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 Clark61313f32018-10-08 14:57:48 -040065#In Constructors
Cary Clarkd2ca79c2018-08-10 13:09:13 -040066#Line # constructs with default values ##
Cary Clark09d80c02018-10-31 12:14:03 -040067#Populate
Cary Clarkd2ca79c2018-08-10 13:09:13 -040068
69#Example
Cary Clark14768f62018-10-29 20:33:51 -040070 SkTextBlobBuilder builder;
71 sk_sp<SkTextBlob> blob = builder.make();
Cary Clarkd2ca79c2018-08-10 13:09:13 -040072 SkDebugf("blob " "%s" " nullptr", blob == nullptr ? "equals" : "does not equal");
73#StdOut
74blob equals nullptr
75##
76##
77
78#SeeAlso make SkTextBlob::MakeFromText
79
80#Method ##
81
82# ------------------------------------------------------------------------------
83
84#Method ~SkTextBlobBuilder()
Cary Clark61313f32018-10-08 14:57:48 -040085#In Constructors
Cary Clarkd2ca79c2018-08-10 13:09:13 -040086#Line # deletes storage ##
Cary Clark09d80c02018-10-31 12:14:03 -040087#Populate
Cary Clarkd2ca79c2018-08-10 13:09:13 -040088
89#NoExample
90##
91
92#SeeAlso SkTextBlobBuilder()
93
94#Method ##
95
96# ------------------------------------------------------------------------------
97
98#Method sk_sp<SkTextBlob> make()
Cary Clark61313f32018-10-08 14:57:48 -040099#In Constructors
Cary Clarkd2ca79c2018-08-10 13:09:13 -0400100#Line # constructs Text_Blob from bulider ##
Cary Clark09d80c02018-10-31 12:14:03 -0400101#Populate
Cary Clarkd2ca79c2018-08-10 13:09:13 -0400102
103#Example
Cary Clark14768f62018-10-29 20:33:51 -0400104 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
115blob equals nullptr
116blob does not equal nullptr
117blob equals nullptr
118##
Cary Clarkd2ca79c2018-08-10 13:09:13 -0400119##
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
132Returns run with storage for Glyphs. Caller must write count Glyphs to
133RunBuffer.glyphs before next call to FontBlobBuilder.
134
135RunBuffer.utf8text, and RunBuffer.clusters should be ignored.
136
137Glyphs share Paint_Font_Metrics in font, including: #paint_font_metrics#.
138
139Glyphs are positioned on a baseline at (x, y), using font Paint_Font_Metrics to
140determine their relative placement.
141
142bounds defines an optional bounding box, used to suppress drawing when Text_Blob
143bounds does not intersect Surface bounds. If bounds is nullptr, Text_Blob bounds
144is 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 Clark14768f62018-10-29 20:33:51 -0400156 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 Clarkd2ca79c2018-08-10 13:09:13 -0400162 canvas->drawTextBlob(builder.make(), 20, 20, paint);
163##
164
165#SeeAlso allocRunPosH allocRunPos
166
167#Method ##
168
169# ------------------------------------------------------------------------------
170
Cary Clark14768f62018-10-29 20:33:51 -0400171#Method const RunBuffer& allocRun(const SkFont& font, int count, SkScalar x, SkScalar y,
172const SkRect* bounds = nullptr)
173#In Allocator
174#Line # returns writable glyph buffer at Point ##
175
176Returns run with storage for Glyphs. Caller must write count Glyphs to
177RunBuffer.glyphs before next call to FontBlobBuilder.
178
179RunBuffer.utf8text, and RunBuffer.clusters should be ignored.
180
181Glyphs share Paint_Font_Metrics in font, including: #paint_font_metrics#.
182
183Glyphs are positioned on a baseline at (x, y), using font Paint_Font_Metrics to
184determine their relative placement.
185
186bounds defines an optional bounding box, used to suppress drawing when Text_Blob
187bounds does not intersect Surface bounds. If bounds is nullptr, Text_Blob bounds
188is 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 Clarkd2ca79c2018-08-10 13:09:13 -0400215#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
220Returns run with storage for Glyphs and positions along baseline. Caller must
221write count Glyphs to RunBuffer.glyphs, and count Scalars to RunBuffer.pos;
222before next call to FontBlobBuilder.
223
224RunBuffer.utf8text, and RunBuffer.clusters should be ignored.
225
226Glyphs share Paint_Font_Metrics in font, including: #paint_font_metrics#.
227
228Glyphs are positioned on a baseline at y, using x-axis positions written by
229caller to RunBuffer.pos.
230
231bounds defines an optional bounding box, used to suppress drawing when Text_Blob
232bounds does not intersect Surface bounds. If bounds is nullptr, Text_Blob bounds
233is 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 Clark14768f62018-10-29 20:33:51 -0400244 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
265Returns run with storage for Glyphs and positions along baseline. Caller must
266write count Glyphs to RunBuffer.glyphs, and count Scalars to RunBuffer.pos;
267before next call to FontBlobBuilder.
268
269RunBuffer.utf8text, and RunBuffer.clusters should be ignored.
270
271Glyphs share Paint_Font_Metrics in font, including: #paint_font_metrics#.
272
273Glyphs are positioned on a baseline at y, using x-axis positions written by
274caller to RunBuffer.pos.
275
276bounds defines an optional bounding box, used to suppress drawing when Text_Blob
277bounds does not intersect Surface bounds. If bounds is nullptr, Text_Blob bounds
278is 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 Clarkd2ca79c2018-08-10 13:09:13 -0400297##
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
310Returns run with storage for Glyphs and Point positions. Caller must
311write count Glyphs to RunBuffer.glyphs, and count Points to RunBuffer.pos;
312before next call to FontBlobBuilder.
313
314RunBuffer.utf8text, and RunBuffer.clusters should be ignored.
315
316Glyphs share Paint_Font_Metrics in font, including: #paint_font_metrics#.
317
318Glyphs are positioned using Points written by caller to RunBuffer.pos, using
319two Scalar values for each Point.
320
321bounds defines an optional bounding box, used to suppress drawing when Text_Blob
322bounds does not intersect Surface bounds. If bounds is nullptr, Text_Blob bounds
323is 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 Clark14768f62018-10-29 20:33:51 -0400333 SkTextBlobBuilder builder;
334 SkPaint paint, font;
Cary Clark09d80c02018-10-31 12:14:03 -0400335 font.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
Cary Clark14768f62018-10-29 20:33:51 -0400336 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
354Returns run with storage for Glyphs and Point positions. Caller must
355write count Glyphs to RunBuffer.glyphs, and count Points to RunBuffer.pos;
356before next call to FontBlobBuilder.
357
358RunBuffer.utf8text, and RunBuffer.clusters should be ignored.
359
360Glyphs share Paint_Font_Metrics in font, including: #paint_font_metrics#.
361
362Glyphs are positioned using Points written by caller to RunBuffer.pos, using
363two Scalar values for each Point.
364
365bounds defines an optional bounding box, used to suppress drawing when Text_Blob
366bounds does not intersect Surface bounds. If bounds is nullptr, Text_Blob bounds
367is 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 Clarkd2ca79c2018-08-10 13:09:13 -0400385##
386
387#SeeAlso allocRunPosH allocRun
388
389#Method ##
390
391#Class SkTextBlobBuilder ##
392
393#Topic Text_Blob_Builder ##