blob: e2e121e9a0e3a6fc5f66d92a09830070a05a1b16 [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
6Helper class for constructing SkTextBlob.
7
8#Subtopic Overview
9#Populate
10##
11
12#Subtopic Class
13#Populate
14##
15
16#Subtopic Constructor
17#Populate
18##
19
20#Subtopic Member_Function
21#Populate
22##
23
24# ------------------------------------------------------------------------------
25
26#Struct RunBuffer
27#Line # storage for Glyphs and Glyph positions ##
28
29#Code
30 struct RunBuffer {
31 SkGlyphID* glyphs;
32 SkScalar* pos;
33 char* utf8text;
34 uint32_t* clusters;
35 };
36##
37
38RunBuffer supplies storage for Glyphs and positions within a run.
39
40A run is a sequence of Glyphs sharing Paint_Font_Metrics and positioning.
41Each run may position its Glyphs in one of three ways:
42by specifying where the first Glyph is drawn, and allowing Paint_Font_Metrics to
43determine the advance to subsequent Glyphs; by specifying a baseline, and
44the position on that baseline for each Glyph in run; or by providing Point
45array, one per Glyph.
46
47#Subtopic Member
48#Populate
49##
50
51#Member SkGlyphID* glyphs
52#Line # storage for Glyphs in run ##
53 glyphs points to memory for one or more Glyphs. glyphs memory must be
54 written to by the caller.
55##
56
57#Member SkScalar* pos
58#Line # storage for positions in run ##
59 pos points to memory for Glyph positions. Depending on how RunBuffer
60 is allocated, pos may point to zero bytes per Glyph, one Scalar per Glyph,
61 or one Point per Glyph.
62##
63
64#Member char* utf8text
65#Line # reserved for future use ##
66 Reserved for future use. utf8text should not be read or written.
67##
68
69#Member uint32_t* clusters
70#Line # reserved for future use ##
71 Reserved for future use. clusters should not be read or written.
72##
73
74#SeeAlso allocRun allocRunPos allocRunPosH
75
76#Struct RunBuffer ##
77
78# ------------------------------------------------------------------------------
79
80#Method SkTextBlobBuilder()
81#In Constructor
82#Line # constructs with default values ##
83
84Constructs empty Text_Blob_Builder. By default, Text_Blob_Builder has no runs.
85
86#Return empty Text_Blob_Builder ##
87
88#Example
89 SkTextBlobBuilder builder;
90 sk_sp<SkTextBlob> blob = builder.make();
91 SkDebugf("blob " "%s" " nullptr", blob == nullptr ? "equals" : "does not equal");
92#StdOut
93blob equals nullptr
94##
95##
96
97#SeeAlso make SkTextBlob::MakeFromText
98
99#Method ##
100
101# ------------------------------------------------------------------------------
102
103#Method ~SkTextBlobBuilder()
104#In Constructor
105#Line # deletes storage ##
106Deletes data allocated internally by Text_Blob_Builder.
107
108#NoExample
109##
110
111#SeeAlso SkTextBlobBuilder()
112
113#Method ##
114
115# ------------------------------------------------------------------------------
116
117#Method sk_sp<SkTextBlob> make()
118#In Constructor
119#Line # constructs Text_Blob from bulider ##
120
121Returns Text_Blob built from runs of Glyphs added by builder. Returned
122Text_Blob is immutable; it may be copied, but its contents may not be altered.
123Returns nullptr if no runs of Glyphs were added by builder.
124
125Resets Text_Blob_Builder to its initial empty state, allowing it to be
126reused to build a new set of runs.
127
128#Return Text_Blob or nullptr ##
129
130#Example
131 SkTextBlobBuilder builder;
132 sk_sp<SkTextBlob> blob = builder.make();
133 SkDebugf("blob " "%s" " nullptr\n", blob == nullptr ? "equals" : "does not equal");
134 SkPaint paint;
135 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
136 paint.textToGlyphs("x", 1, builder.allocRun(paint, 1, 20, 20).glyphs);
137 blob = builder.make();
138 SkDebugf("blob " "%s" " nullptr\n", blob == nullptr ? "equals" : "does not equal");
139 blob = builder.make();
140 SkDebugf("blob " "%s" " nullptr\n", blob == nullptr ? "equals" : "does not equal");
141#StdOut
142blob equals nullptr
143blob does not equal nullptr
144blob equals nullptr
145##
146##
147
148#SeeAlso SkTextBlob::MakeFromText
149
150#Method ##
151
152# ------------------------------------------------------------------------------
153
154#Method const RunBuffer& allocRun(const SkPaint& font, int count, SkScalar x, SkScalar y,
155 const SkRect* bounds = nullptr)
156#In Allocator
157#Line # returns writable glyph buffer at Point ##
158
159Returns run with storage for Glyphs. Caller must write count Glyphs to
160RunBuffer.glyphs before next call to FontBlobBuilder.
161
162RunBuffer.utf8text, and RunBuffer.clusters should be ignored.
163
164Glyphs share Paint_Font_Metrics in font, including: #paint_font_metrics#.
165
166Glyphs are positioned on a baseline at (x, y), using font Paint_Font_Metrics to
167determine their relative placement.
168
169bounds defines an optional bounding box, used to suppress drawing when Text_Blob
170bounds does not intersect Surface bounds. If bounds is nullptr, Text_Blob bounds
171is computed from (x, y) and RunBuffer.glyphs Paint_Font_Metrics.
172
173#Param font Paint used for this run ##
174#Param count number of glyphs ##
175#Param x horizontal offset within the blob ##
176#Param y vertical offset within the blob ##
177#Param bounds optional run bounding box ##
178
179#Return writable glyph buffer ##
180
181#Example
182#Height 60
183 SkTextBlobBuilder builder;
184 SkPaint paint, glyphPaint;
185 glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
186 const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(glyphPaint, 5, 20, 20);
187 paint.textToGlyphs("hello", 5, run.glyphs);
188 canvas->drawRect({20, 20, 30, 30}, paint);
189 canvas->drawTextBlob(builder.make(), 20, 20, paint);
190##
191
192#SeeAlso allocRunPosH allocRunPos
193
194#Method ##
195
196# ------------------------------------------------------------------------------
197
198#Method const RunBuffer& allocRunPosH(const SkPaint& font, int count, SkScalar y,
199 const SkRect* bounds = nullptr)
200#In Allocator
201#Line # returns writable glyph and x-axis position buffers ##
202
203Returns run with storage for Glyphs and positions along baseline. Caller must
204write count Glyphs to RunBuffer.glyphs, and count Scalars to RunBuffer.pos;
205before next call to FontBlobBuilder.
206
207RunBuffer.utf8text, and RunBuffer.clusters should be ignored.
208
209Glyphs share Paint_Font_Metrics in font, including: #paint_font_metrics#.
210
211Glyphs are positioned on a baseline at y, using x-axis positions written by
212caller to RunBuffer.pos.
213
214bounds defines an optional bounding box, used to suppress drawing when Text_Blob
215bounds does not intersect Surface bounds. If bounds is nullptr, Text_Blob bounds
216is computed from y, RunBuffer.pos, and RunBuffer.glyphs Paint_Font_Metrics.
217
218#Param font Paint used for this run ##
219#Param count number of Glyphs ##
220#Param y vertical offset within the blob ##
221#Param bounds optional run bounding box ##
222
223#Return writable glyph buffer and x-axis position buffer ##
224
225#Example
226#Height 60
227 SkTextBlobBuilder builder;
228 SkPaint paint, glyphPaint;
229 glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
230 const SkTextBlobBuilder::RunBuffer& run = builder.allocRunPosH(glyphPaint, 5, 20);
231 paint.textToGlyphs("hello", 5, run.glyphs);
232 SkScalar positions[] = {0, 10, 20, 40, 80};
233 memcpy(run.pos, positions, sizeof(positions));
234 canvas->drawTextBlob(builder.make(), 20, 20, paint);
235##
236
237#SeeAlso allocRunPos allocRun
238
239#Method ##
240
241# ------------------------------------------------------------------------------
242
243#Method const RunBuffer& allocRunPos(const SkPaint& font, int count,
244 const SkRect* bounds = nullptr)
245#In Allocator
246#Line # returns writable glyph and Point buffers ##
247
248Returns run with storage for Glyphs and Point positions. Caller must
249write count Glyphs to RunBuffer.glyphs, and count Points to RunBuffer.pos;
250before next call to FontBlobBuilder.
251
252RunBuffer.utf8text, and RunBuffer.clusters should be ignored.
253
254Glyphs share Paint_Font_Metrics in font, including: #paint_font_metrics#.
255
256Glyphs are positioned using Points written by caller to RunBuffer.pos, using
257two Scalar values for each Point.
258
259bounds defines an optional bounding box, used to suppress drawing when Text_Blob
260bounds does not intersect Surface bounds. If bounds is nullptr, Text_Blob bounds
261is computed from RunBuffer.pos, and RunBuffer.glyphs Paint_Font_Metrics.
262
263#Param font Paint used for this run ##
264#Param count number of Glyphs ##
265#Param bounds optional run bounding box ##
266
267#Return writable glyph buffer and Point buffer ##
268
269#Example
270#Height 90
271 SkTextBlobBuilder builder;
272 SkPaint paint, glyphPaint;
273 glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
274 const SkTextBlobBuilder::RunBuffer& run = builder.allocRunPos(glyphPaint, 5);
275 paint.textToGlyphs("hello", 5, run.glyphs);
276 SkPoint positions[] = {{0, 0}, {10, 10}, {20, 20}, {40, 40}, {80, 80}};
277 memcpy(run.pos, positions, sizeof(positions));
278 canvas->drawTextBlob(builder.make(), 20, 20, paint);
279##
280
281#SeeAlso allocRunPosH allocRun
282
283#Method ##
284
285#Class SkTextBlobBuilder ##
286
287#Topic Text_Blob_Builder ##