blob: 9ca937daf5e18086ce98761ba422089e9dd80ea0 [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
Cary Clark14768f62018-10-29 20:33:51 -0400127#Method const RunBuffer& allocRun(const SkFont& font, int count, SkScalar x, SkScalar y,
128const SkRect* bounds = nullptr)
129#In Allocator
130#Line # returns writable glyph buffer at Point ##
131
Cary Clark77b3f3a2018-11-07 14:59:03 -0500132#Populate
Cary Clark14768f62018-10-29 20:33:51 -0400133
134#Example
135#Height 60
136 SkTextBlobBuilder builder;
137 SkFont font;
138 SkPaint paint;
139 const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(font, 5, 20, 20);
140 paint.textToGlyphs("hello", 5, run.glyphs);
141 canvas->drawRect({20, 20, 30, 30}, paint);
142 canvas->drawTextBlob(builder.make(), 20, 20, paint);
143##
144
145#SeeAlso allocRunPosH allocRunPos
146
147#Method ##
148
149# ------------------------------------------------------------------------------
150
Cary Clark14768f62018-10-29 20:33:51 -0400151#Method const RunBuffer& allocRunPosH(const SkFont& font, int count, SkScalar y,
152 const SkRect* bounds = nullptr)
153#In Allocator
154#Line # returns writable glyph and x-axis position buffers ##
155
Cary Clark77b3f3a2018-11-07 14:59:03 -0500156#Populate
Cary Clark14768f62018-10-29 20:33:51 -0400157
158#Example
159#Height 60
160 SkTextBlobBuilder builder;
161 SkPaint paint;
162 SkFont font;
163 const SkTextBlobBuilder::RunBuffer& run = builder.allocRunPosH(font, 5, 20);
164 paint.textToGlyphs("hello", 5, run.glyphs);
165 SkScalar positions[] = {0, 10, 20, 40, 80};
166 memcpy(run.pos, positions, sizeof(positions));
167 canvas->drawTextBlob(builder.make(), 20, 20, paint);
Cary Clarkd2ca79c2018-08-10 13:09:13 -0400168##
169
170#SeeAlso allocRunPos allocRun
171
172#Method ##
173
174# ------------------------------------------------------------------------------
175
Cary Clark14768f62018-10-29 20:33:51 -0400176#Method const RunBuffer& allocRunPos(const SkFont& font, int count,
177 const SkRect* bounds = nullptr)
178#In Allocator
179#Line # returns writable glyph and Point buffers ##
180
Cary Clark77b3f3a2018-11-07 14:59:03 -0500181#Populate
Cary Clark14768f62018-10-29 20:33:51 -0400182
183#Example
184#Height 90
185 SkTextBlobBuilder builder;
186 SkPaint paint;
187 SkFont font;
188 const SkTextBlobBuilder::RunBuffer& run = builder.allocRunPos(font, 5);
189 paint.textToGlyphs("hello", 5, run.glyphs);
190 SkPoint positions[] = {{0, 0}, {10, 10}, {20, 20}, {40, 40}, {80, 80}};
191 memcpy(run.pos, positions, sizeof(positions));
192 canvas->drawTextBlob(builder.make(), 20, 20, paint);
Cary Clarkd2ca79c2018-08-10 13:09:13 -0400193##
194
195#SeeAlso allocRunPosH allocRun
196
197#Method ##
198
Cary Clark77b3f3a2018-11-07 14:59:03 -0500199# ------------------------------------------------------------------------------
200
201#Method const RunBuffer& allocRun(const SkPaint& font, int count, SkScalar x, SkScalar y,
202 const SkRect* bounds = nullptr)
203#Deprecated
204#Method ##
205
206# ------------------------------------------------------------------------------
207
208#Method const RunBuffer& allocRunPosH(const SkPaint& font, int count, SkScalar y,
209 const SkRect* bounds = nullptr)
210#Deprecated
211#Method ##
212
213# ------------------------------------------------------------------------------
214
215#Method const RunBuffer& allocRunPos(const SkPaint& font, int count,
216 const SkRect* bounds = nullptr)
217#Deprecated
218#Method ##
219
Cary Clarkd2ca79c2018-08-10 13:09:13 -0400220#Class SkTextBlobBuilder ##
221
222#Topic Text_Blob_Builder ##