OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkTextBlob_DEFINED | 8 #ifndef SkTextBlob_DEFINED |
9 #define SkTextBlob_DEFINED | 9 #define SkTextBlob_DEFINED |
10 | 10 |
11 #include "../private/SkTemplates.h" | 11 #include "../private/SkTemplates.h" |
12 #include "SkPaint.h" | 12 #include "SkPaint.h" |
13 #include "SkString.h" | |
13 #include "SkRefCnt.h" | 14 #include "SkRefCnt.h" |
14 | 15 |
15 class SkReadBuffer; | 16 class SkReadBuffer; |
16 class SkWriteBuffer; | 17 class SkWriteBuffer; |
17 | 18 |
18 /** \class SkTextBlob | 19 /** \class SkTextBlob |
19 | 20 |
20 SkTextBlob combines multiple text runs into an immutable, ref-counted struct ure. | 21 SkTextBlob combines multiple text runs into an immutable, ref-counted struct ure. |
21 */ | 22 */ |
22 class SK_API SkTextBlob : public SkRefCnt { | 23 class SK_API SkTextBlob : public SkRefCnt { |
(...skipping 15 matching lines...) Expand all Loading... | |
38 | 39 |
39 /** | 40 /** |
40 * Recreate an SkTextBlob that was serialized into a buffer. | 41 * Recreate an SkTextBlob that was serialized into a buffer. |
41 * | 42 * |
42 * @param SkReadBuffer Serialized blob data. | 43 * @param SkReadBuffer Serialized blob data. |
43 * @return A new SkTextBlob representing the serialized data, or NULL if th e buffer is | 44 * @return A new SkTextBlob representing the serialized data, or NULL if th e buffer is |
44 * invalid. | 45 * invalid. |
45 */ | 46 */ |
46 static const SkTextBlob* CreateFromBuffer(SkReadBuffer&); | 47 static const SkTextBlob* CreateFromBuffer(SkReadBuffer&); |
47 | 48 |
48 enum GlyphPositioning { | 49 enum GlyphPositioning : uint8_t { |
49 kDefault_Positioning = 0, // Default glyph advances -- zero scalars per glyph. | 50 kDefault_Positioning = 0, // Default glyph advances -- zero scalars per glyph. |
50 kHorizontal_Positioning = 1, // Horizontal positioning -- one scalar p er glyph. | 51 kHorizontal_Positioning = 1, // Horizontal positioning -- one scalar p er glyph. |
51 kFull_Positioning = 2 // Point positioning -- two scalars per g lyph. | 52 kFull_Positioning = 2 // Point positioning -- two scalars per g lyph. |
52 }; | 53 }; |
53 | 54 |
54 private: | 55 private: |
55 class RunRecord; | 56 class RunRecord; |
56 | 57 |
57 SkTextBlob(int runCount, const SkRect& bounds); | 58 SkTextBlob(int runCount, const SkRect& bounds); |
58 | 59 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 | 97 |
97 /** | 98 /** |
98 * Returns an immutable SkTextBlob for the current runs/glyphs. The builder is reset and | 99 * Returns an immutable SkTextBlob for the current runs/glyphs. The builder is reset and |
99 * can be reused. | 100 * can be reused. |
100 */ | 101 */ |
101 const SkTextBlob* build(); | 102 const SkTextBlob* build(); |
102 | 103 |
103 /** | 104 /** |
104 * Glyph and position buffers associated with a run. | 105 * Glyph and position buffers associated with a run. |
105 * | 106 * |
106 * A run is a sequence of glyphs sharing the same font metrics and position ing mode. | 107 * A run is a sequence of glyphs sharing the same font metrics |
108 * and positioning mode. | |
109 * | |
110 * If textByteCount is 0, utf8text and clusters will be NULL (no | |
111 * character information will be associated with the glyphs). | |
112 * | |
113 * utf8text will point to a buffer of size textByteCount bytes. | |
114 * | |
115 * clusters (if not NULL) will point to an array of size count. | |
116 * For each glyph, give the byte-offset into the text for the | |
117 * first byte in the first character in that glyph's cluster. | |
118 * Each value in the array should be an integer less than | |
119 * textByteCount. Values in the array should either be | |
120 * monotonically increasing (left-to-right text) or monotonically | |
121 * decreasing (right-to-left text). This definiton is conviently | |
122 * the same as used by Harfbuzz's hb_glyph_info_t::cluster field, | |
123 * except that Harfbuzz interleaves glyphs and clusters. | |
107 */ | 124 */ |
108 struct RunBuffer { | 125 struct RunBuffer { |
109 uint16_t* glyphs; | 126 uint16_t* glyphs; |
110 SkScalar* pos; | 127 SkScalar* pos; |
128 char* utf8text; | |
129 uint32_t* clusters; | |
111 }; | 130 }; |
112 | 131 |
113 /** | 132 /** |
114 * Allocates a new default-positioned run and returns its writable glyph bu ffer | 133 * Allocates a new default-positioned run and returns its writable glyph bu ffer |
115 * for direct manipulation. | 134 * for direct manipulation. |
116 * | 135 * |
117 * @param font The font to be used for this run. | 136 * @param font The font to be used for this run. |
118 * @param count Number of glyphs. | 137 * @param count Number of glyphs. |
119 * @param x,y Position within the blob. | 138 * @param x,y Position within the blob. |
139 * @param textByteCount length of the original UTF-8 text that | |
140 * corresponds to this sequence of glyphs. If 0, | |
141 * text will not be included in the textblob. | |
142 * @param lang Language code, currently unimplemented. | |
f(malita)
2016/06/27 20:21:55
If not implemented, is it worth adding the param a
hal.canary
2016/06/28 15:39:12
Good question. It's a pain to change the API, and
| |
120 * @param bounds Optional run bounding box. If known in advance (!= NULL), it will | 143 * @param bounds Optional run bounding box. If known in advance (!= NULL), it will |
121 * be used when computing the blob bounds, to avoid re-measu ring. | 144 * be used when computing the blob bounds, to avoid re-measu ring. |
122 * | 145 * |
123 * @return A writable glyph buffer, valid until the next allocRun() or | 146 * @return A writable glyph buffer, valid until the next allocRun() or |
124 * build() call. The buffer is guaranteed to hold @count@ gl yphs. | 147 * build() call. The buffer is guaranteed to hold @count@ gl yphs. |
125 */ | 148 */ |
149 const RunBuffer& allocRunText(const SkPaint& font, | |
150 int count, | |
151 SkScalar x, | |
152 SkScalar y, | |
153 int textByteCount, | |
154 SkString lang, | |
155 const SkRect* bounds = NULL); | |
126 const RunBuffer& allocRun(const SkPaint& font, int count, SkScalar x, SkScal ar y, | 156 const RunBuffer& allocRun(const SkPaint& font, int count, SkScalar x, SkScal ar y, |
127 const SkRect* bounds = NULL); | 157 const SkRect* bounds = NULL) { |
158 return this->allocRunText(font, count, x, y, 0, SkString(), bounds); | |
159 } | |
128 | 160 |
129 /** | 161 /** |
130 * Allocates a new horizontally-positioned run and returns its writable gly ph and position | 162 * Allocates a new horizontally-positioned run and returns its writable gly ph and position |
131 * buffers for direct manipulation. | 163 * buffers for direct manipulation. |
132 * | 164 * |
133 * @param font The font to be used for this run. | 165 * @param font The font to be used for this run. |
134 * @param count Number of glyphs. | 166 * @param count Number of glyphs. |
135 * @param y Vertical offset within the blob. | 167 * @param y Vertical offset within the blob. |
168 * @param textByteCount length of the original UTF-8 text that | |
169 * corresponds to this sequence of glyphs. If 0, | |
170 * text will not be included in the textblob. | |
171 * @param lang Language code, currently unimplemented. | |
136 * @param bounds Optional run bounding box. If known in advance (!= NULL), it will | 172 * @param bounds Optional run bounding box. If known in advance (!= NULL), it will |
137 * be used when computing the blob bounds, to avoid re-measu ring. | 173 * be used when computing the blob bounds, to avoid re-measu ring. |
138 * | 174 * |
139 * @return Writable glyph and position buffers, valid until the next allocRun() | 175 * @return Writable glyph and position buffers, valid until the next allocRun() |
140 * or build() call. The buffers are guaranteed to hold @coun t@ elements. | 176 * or build() call. The buffers are guaranteed to hold @coun t@ elements. |
141 */ | 177 */ |
178 const RunBuffer& allocRunTextPosH(const SkPaint& font, int count, SkScalar y , | |
179 int textByteCount, SkString lang, | |
180 const SkRect* bounds = NULL); | |
142 const RunBuffer& allocRunPosH(const SkPaint& font, int count, SkScalar y, | 181 const RunBuffer& allocRunPosH(const SkPaint& font, int count, SkScalar y, |
143 const SkRect* bounds = NULL); | 182 const SkRect* bounds = NULL) { |
183 return this->allocRunTextPosH(font, count, y, 0, SkString(), bounds); | |
184 } | |
144 | 185 |
145 /** | 186 /** |
146 * Allocates a new fully-positioned run and returns its writable glyph and position | 187 * Allocates a new fully-positioned run and returns its writable glyph and position |
147 * buffers for direct manipulation. | 188 * buffers for direct manipulation. |
148 * | 189 * |
149 * @param font The font to be used for this run. | 190 * @param font The font to be used for this run. |
150 * @param count Number of glyphs. | 191 * @param count Number of glyphs. |
192 * @param textByteCount length of the original UTF-8 text that | |
193 * corresponds to this sequence of glyphs. If 0, | |
194 * text will not be included in the textblob. | |
195 * @param lang Language code, currently unimplemented. | |
151 * @param bounds Optional run bounding box. If known in advance (!= NULL), it will | 196 * @param bounds Optional run bounding box. If known in advance (!= NULL), it will |
152 * be used when computing the blob bounds, to avoid re-measur ing. | 197 * be used when computing the blob bounds, to avoid re-measur ing. |
153 * | 198 * |
154 * @return Writable glyph and position buffers, valid until the next allocRun() | 199 * @return Writable glyph and position buffers, valid until the next allocRun() |
155 * or build() call. The glyph buffer and position buffer are | 200 * or build() call. The glyph buffer and position buffer are |
156 * guaranteed to hold @count@ and 2 * @count@ elements, respe ctively. | 201 * guaranteed to hold @count@ and 2 * @count@ elements, respe ctively. |
157 */ | 202 */ |
158 const RunBuffer& allocRunPos(const SkPaint& font, int count, const SkRect* b ounds = NULL); | 203 const RunBuffer& allocRunTextPos(const SkPaint& font, int count, |
204 int textByteCount, SkString lang, | |
205 const SkRect* bounds = NULL); | |
206 const RunBuffer& allocRunPos(const SkPaint& font, int count, | |
207 const SkRect* bounds = NULL) { | |
208 return this->allocRunTextPos(font, count, 0, SkString(), bounds); | |
209 } | |
159 | 210 |
160 private: | 211 private: |
161 void reserve(size_t size); | 212 void reserve(size_t size); |
162 void allocInternal(const SkPaint& font, SkTextBlob::GlyphPositioning positio ning, | 213 void allocInternal(const SkPaint& font, SkTextBlob::GlyphPositioning positio ning, |
163 int count, SkPoint offset, const SkRect* bounds); | 214 int count, int textBytes, SkPoint offset, const SkRect* b ounds); |
164 bool mergeRun(const SkPaint& font, SkTextBlob::GlyphPositioning positioning, | 215 bool mergeRun(const SkPaint& font, SkTextBlob::GlyphPositioning positioning, |
165 int count, SkPoint offset); | 216 int count, SkPoint offset); |
166 void updateDeferredBounds(); | 217 void updateDeferredBounds(); |
167 | 218 |
168 static SkRect ConservativeRunBounds(const SkTextBlob::RunRecord&); | 219 static SkRect ConservativeRunBounds(const SkTextBlob::RunRecord&); |
169 static SkRect TightRunBounds(const SkTextBlob::RunRecord&); | 220 static SkRect TightRunBounds(const SkTextBlob::RunRecord&); |
170 | 221 |
171 SkAutoTMalloc<uint8_t> fStorage; | 222 SkAutoTMalloc<uint8_t> fStorage; |
172 size_t fStorageSize; | 223 size_t fStorageSize; |
173 size_t fStorageUsed; | 224 size_t fStorageUsed; |
174 | 225 |
175 SkRect fBounds; | 226 SkRect fBounds; |
176 int fRunCount; | 227 int fRunCount; |
177 bool fDeferredBounds; | 228 bool fDeferredBounds; |
178 size_t fLastRun; // index into fStorage | 229 size_t fLastRun; // index into fStorage |
179 | 230 |
180 RunBuffer fCurrentRunBuffer; | 231 RunBuffer fCurrentRunBuffer; |
181 }; | 232 }; |
182 | 233 |
183 #endif // SkTextBlob_DEFINED | 234 #endif // SkTextBlob_DEFINED |
OLD | NEW |