blob: e3ee47a04044bdb522b790cb8c6f121687b34fbf [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 ##
67
68Constructs empty Text_Blob_Builder. By default, Text_Blob_Builder has no runs.
69
70#Return empty Text_Blob_Builder ##
71
72#Example
73 SkTextBlobBuilder builder;
74 sk_sp<SkTextBlob> blob = builder.make();
75 SkDebugf("blob " "%s" " nullptr", blob == nullptr ? "equals" : "does not equal");
76#StdOut
77blob equals nullptr
78##
79##
80
81#SeeAlso make SkTextBlob::MakeFromText
82
83#Method ##
84
85# ------------------------------------------------------------------------------
86
87#Method ~SkTextBlobBuilder()
Cary Clark61313f32018-10-08 14:57:48 -040088#In Constructors
Cary Clarkd2ca79c2018-08-10 13:09:13 -040089#Line # deletes storage ##
90Deletes data allocated internally by Text_Blob_Builder.
91
92#NoExample
93##
94
95#SeeAlso SkTextBlobBuilder()
96
97#Method ##
98
99# ------------------------------------------------------------------------------
100
101#Method sk_sp<SkTextBlob> make()
Cary Clark61313f32018-10-08 14:57:48 -0400102#In Constructors
Cary Clarkd2ca79c2018-08-10 13:09:13 -0400103#Line # constructs Text_Blob from bulider ##
104
105Returns Text_Blob built from runs of Glyphs added by builder. Returned
106Text_Blob is immutable; it may be copied, but its contents may not be altered.
107Returns nullptr if no runs of Glyphs were added by builder.
108
109Resets Text_Blob_Builder to its initial empty state, allowing it to be
110reused to build a new set of runs.
111
112#Return Text_Blob or nullptr ##
113
114#Example
115 SkTextBlobBuilder builder;
116 sk_sp<SkTextBlob> blob = builder.make();
117 SkDebugf("blob " "%s" " nullptr\n", blob == nullptr ? "equals" : "does not equal");
118 SkPaint paint;
119 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
120 paint.textToGlyphs("x", 1, builder.allocRun(paint, 1, 20, 20).glyphs);
121 blob = builder.make();
122 SkDebugf("blob " "%s" " nullptr\n", blob == nullptr ? "equals" : "does not equal");
123 blob = builder.make();
124 SkDebugf("blob " "%s" " nullptr\n", blob == nullptr ? "equals" : "does not equal");
125#StdOut
126blob equals nullptr
127blob does not equal nullptr
128blob equals nullptr
129##
130##
131
132#SeeAlso SkTextBlob::MakeFromText
133
134#Method ##
135
136# ------------------------------------------------------------------------------
137
138#Method const RunBuffer& allocRun(const SkPaint& font, int count, SkScalar x, SkScalar y,
139 const SkRect* bounds = nullptr)
140#In Allocator
141#Line # returns writable glyph buffer at Point ##
142
143Returns run with storage for Glyphs. Caller must write count Glyphs to
144RunBuffer.glyphs before next call to FontBlobBuilder.
145
146RunBuffer.utf8text, and RunBuffer.clusters should be ignored.
147
148Glyphs share Paint_Font_Metrics in font, including: #paint_font_metrics#.
149
150Glyphs are positioned on a baseline at (x, y), using font Paint_Font_Metrics to
151determine their relative placement.
152
153bounds defines an optional bounding box, used to suppress drawing when Text_Blob
154bounds does not intersect Surface bounds. If bounds is nullptr, Text_Blob bounds
155is computed from (x, y) and RunBuffer.glyphs Paint_Font_Metrics.
156
157#Param font Paint used for this run ##
158#Param count number of glyphs ##
159#Param x horizontal offset within the blob ##
160#Param y vertical offset within the blob ##
161#Param bounds optional run bounding box ##
162
163#Return writable glyph buffer ##
164
165#Example
166#Height 60
167 SkTextBlobBuilder builder;
168 SkPaint paint, glyphPaint;
169 glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
170 const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(glyphPaint, 5, 20, 20);
171 paint.textToGlyphs("hello", 5, run.glyphs);
172 canvas->drawRect({20, 20, 30, 30}, paint);
173 canvas->drawTextBlob(builder.make(), 20, 20, paint);
174##
175
176#SeeAlso allocRunPosH allocRunPos
177
178#Method ##
179
180# ------------------------------------------------------------------------------
181
182#Method const RunBuffer& allocRunPosH(const SkPaint& font, int count, SkScalar y,
183 const SkRect* bounds = nullptr)
184#In Allocator
185#Line # returns writable glyph and x-axis position buffers ##
186
187Returns run with storage for Glyphs and positions along baseline. Caller must
188write count Glyphs to RunBuffer.glyphs, and count Scalars to RunBuffer.pos;
189before next call to FontBlobBuilder.
190
191RunBuffer.utf8text, and RunBuffer.clusters should be ignored.
192
193Glyphs share Paint_Font_Metrics in font, including: #paint_font_metrics#.
194
195Glyphs are positioned on a baseline at y, using x-axis positions written by
196caller to RunBuffer.pos.
197
198bounds defines an optional bounding box, used to suppress drawing when Text_Blob
199bounds does not intersect Surface bounds. If bounds is nullptr, Text_Blob bounds
200is computed from y, RunBuffer.pos, and RunBuffer.glyphs Paint_Font_Metrics.
201
202#Param font Paint used for this run ##
203#Param count number of Glyphs ##
204#Param y vertical offset within the blob ##
205#Param bounds optional run bounding box ##
206
207#Return writable glyph buffer and x-axis position buffer ##
208
209#Example
210#Height 60
211 SkTextBlobBuilder builder;
212 SkPaint paint, glyphPaint;
213 glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
214 const SkTextBlobBuilder::RunBuffer& run = builder.allocRunPosH(glyphPaint, 5, 20);
215 paint.textToGlyphs("hello", 5, run.glyphs);
216 SkScalar positions[] = {0, 10, 20, 40, 80};
217 memcpy(run.pos, positions, sizeof(positions));
218 canvas->drawTextBlob(builder.make(), 20, 20, paint);
219##
220
221#SeeAlso allocRunPos allocRun
222
223#Method ##
224
225# ------------------------------------------------------------------------------
226
227#Method const RunBuffer& allocRunPos(const SkPaint& font, int count,
228 const SkRect* bounds = nullptr)
229#In Allocator
230#Line # returns writable glyph and Point buffers ##
231
232Returns run with storage for Glyphs and Point positions. Caller must
233write count Glyphs to RunBuffer.glyphs, and count Points to RunBuffer.pos;
234before next call to FontBlobBuilder.
235
236RunBuffer.utf8text, and RunBuffer.clusters should be ignored.
237
238Glyphs share Paint_Font_Metrics in font, including: #paint_font_metrics#.
239
240Glyphs are positioned using Points written by caller to RunBuffer.pos, using
241two Scalar values for each Point.
242
243bounds defines an optional bounding box, used to suppress drawing when Text_Blob
244bounds does not intersect Surface bounds. If bounds is nullptr, Text_Blob bounds
245is computed from RunBuffer.pos, and RunBuffer.glyphs Paint_Font_Metrics.
246
247#Param font Paint used for this run ##
248#Param count number of Glyphs ##
249#Param bounds optional run bounding box ##
250
251#Return writable glyph buffer and Point buffer ##
252
253#Example
254#Height 90
255 SkTextBlobBuilder builder;
256 SkPaint paint, glyphPaint;
257 glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
258 const SkTextBlobBuilder::RunBuffer& run = builder.allocRunPos(glyphPaint, 5);
259 paint.textToGlyphs("hello", 5, run.glyphs);
260 SkPoint positions[] = {{0, 0}, {10, 10}, {20, 20}, {40, 40}, {80, 80}};
261 memcpy(run.pos, positions, sizeof(positions));
262 canvas->drawTextBlob(builder.make(), 20, 20, paint);
263##
264
265#SeeAlso allocRunPosH allocRun
266
267#Method ##
268
269#Class SkTextBlobBuilder ##
270
271#Topic Text_Blob_Builder ##