Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: include/core/SkTextBlob.h

Issue 2084533004: SkTextBlob: Begin implementing Extended TextBlob API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkPicture.h ('k') | src/core/SkTextBlob.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 final : public SkNVRefCnt<SkTextBlob> { 23 class SK_API SkTextBlob final : public SkNVRefCnt<SkTextBlob> {
(...skipping 19 matching lines...) Expand all
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 sk_sp<SkTextBlob> MakeFromBuffer(SkReadBuffer&); 47 static sk_sp<SkTextBlob> MakeFromBuffer(SkReadBuffer&);
47 48
48 static const SkTextBlob* CreateFromBuffer(SkReadBuffer& buffer) { 49 static const SkTextBlob* CreateFromBuffer(SkReadBuffer& buffer) {
49 return MakeFromBuffer(buffer).release(); 50 return MakeFromBuffer(buffer).release();
50 } 51 }
51 52
52 enum GlyphPositioning { 53 enum GlyphPositioning : uint8_t {
53 kDefault_Positioning = 0, // Default glyph advances -- zero scalars per glyph. 54 kDefault_Positioning = 0, // Default glyph advances -- zero scalars per glyph.
54 kHorizontal_Positioning = 1, // Horizontal positioning -- one scalar p er glyph. 55 kHorizontal_Positioning = 1, // Horizontal positioning -- one scalar p er glyph.
55 kFull_Positioning = 2 // Point positioning -- two scalars per g lyph. 56 kFull_Positioning = 2 // Point positioning -- two scalars per g lyph.
56 }; 57 };
57 58
58 private: 59 private:
59 friend class SkNVRefCnt<SkTextBlob>; 60 friend class SkNVRefCnt<SkTextBlob>;
60 class RunRecord; 61 class RunRecord;
61 62
62 SkTextBlob(int runCount, const SkRect& bounds); 63 SkTextBlob(int runCount, const SkRect& bounds);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 */ 106 */
106 sk_sp<SkTextBlob> make(); 107 sk_sp<SkTextBlob> make();
107 108
108 const SkTextBlob* build() { 109 const SkTextBlob* build() {
109 return this->make().release(); 110 return this->make().release();
110 } 111 }
111 112
112 /** 113 /**
113 * Glyph and position buffers associated with a run. 114 * Glyph and position buffers associated with a run.
114 * 115 *
115 * A run is a sequence of glyphs sharing the same font metrics and position ing mode. 116 * A run is a sequence of glyphs sharing the same font metrics
117 * and positioning mode.
118 *
119 * If textByteCount is 0, utf8text and clusters will be NULL (no
120 * character information will be associated with the glyphs).
121 *
122 * utf8text will point to a buffer of size textByteCount bytes.
123 *
124 * clusters (if not NULL) will point to an array of size count.
125 * For each glyph, give the byte-offset into the text for the
126 * first byte in the first character in that glyph's cluster.
127 * Each value in the array should be an integer less than
128 * textByteCount. Values in the array should either be
129 * monotonically increasing (left-to-right text) or monotonically
130 * decreasing (right-to-left text). This definiton is conviently
131 * the same as used by Harfbuzz's hb_glyph_info_t::cluster field,
132 * except that Harfbuzz interleaves glyphs and clusters.
116 */ 133 */
117 struct RunBuffer { 134 struct RunBuffer {
118 SkGlyphID* glyphs; 135 SkGlyphID* glyphs;
119 SkScalar* pos; 136 SkScalar* pos;
137 char* utf8text;
138 uint32_t* clusters;
120 }; 139 };
121 140
122 /** 141 /**
123 * Allocates a new default-positioned run and returns its writable glyph bu ffer 142 * Allocates a new default-positioned run and returns its writable glyph bu ffer
124 * for direct manipulation. 143 * for direct manipulation.
125 * 144 *
126 * @param font The font to be used for this run. 145 * @param font The font to be used for this run.
127 * @param count Number of glyphs. 146 * @param count Number of glyphs.
128 * @param x,y Position within the blob. 147 * @param x,y Position within the blob.
148 * @param textByteCount length of the original UTF-8 text that
149 * corresponds to this sequence of glyphs. If 0,
150 * text will not be included in the textblob.
151 * @param lang Language code, currently unimplemented.
129 * @param bounds Optional run bounding box. If known in advance (!= NULL), it will 152 * @param bounds Optional run bounding box. If known in advance (!= NULL), it will
130 * be used when computing the blob bounds, to avoid re-measu ring. 153 * be used when computing the blob bounds, to avoid re-measu ring.
131 * 154 *
132 * @return A writable glyph buffer, valid until the next allocRun() or 155 * @return A writable glyph buffer, valid until the next allocRun() or
133 * build() call. The buffer is guaranteed to hold @count@ gl yphs. 156 * build() call. The buffer is guaranteed to hold @count@ gl yphs.
134 */ 157 */
158 const RunBuffer& allocRunText(const SkPaint& font,
159 int count,
160 SkScalar x,
161 SkScalar y,
162 int textByteCount,
163 SkString lang,
164 const SkRect* bounds = NULL);
135 const RunBuffer& allocRun(const SkPaint& font, int count, SkScalar x, SkScal ar y, 165 const RunBuffer& allocRun(const SkPaint& font, int count, SkScalar x, SkScal ar y,
136 const SkRect* bounds = NULL); 166 const SkRect* bounds = NULL) {
167 return this->allocRunText(font, count, x, y, 0, SkString(), bounds);
168 }
137 169
138 /** 170 /**
139 * Allocates a new horizontally-positioned run and returns its writable gly ph and position 171 * Allocates a new horizontally-positioned run and returns its writable gly ph and position
140 * buffers for direct manipulation. 172 * buffers for direct manipulation.
141 * 173 *
142 * @param font The font to be used for this run. 174 * @param font The font to be used for this run.
143 * @param count Number of glyphs. 175 * @param count Number of glyphs.
144 * @param y Vertical offset within the blob. 176 * @param y Vertical offset within the blob.
177 * @param textByteCount length of the original UTF-8 text that
178 * corresponds to this sequence of glyphs. If 0,
179 * text will not be included in the textblob.
180 * @param lang Language code, currently unimplemented.
145 * @param bounds Optional run bounding box. If known in advance (!= NULL), it will 181 * @param bounds Optional run bounding box. If known in advance (!= NULL), it will
146 * be used when computing the blob bounds, to avoid re-measu ring. 182 * be used when computing the blob bounds, to avoid re-measu ring.
147 * 183 *
148 * @return Writable glyph and position buffers, valid until the next allocRun() 184 * @return Writable glyph and position buffers, valid until the next allocRun()
149 * or build() call. The buffers are guaranteed to hold @coun t@ elements. 185 * or build() call. The buffers are guaranteed to hold @coun t@ elements.
150 */ 186 */
187 const RunBuffer& allocRunTextPosH(const SkPaint& font, int count, SkScalar y ,
188 int textByteCount, SkString lang,
189 const SkRect* bounds = NULL);
151 const RunBuffer& allocRunPosH(const SkPaint& font, int count, SkScalar y, 190 const RunBuffer& allocRunPosH(const SkPaint& font, int count, SkScalar y,
152 const SkRect* bounds = NULL); 191 const SkRect* bounds = NULL) {
192 return this->allocRunTextPosH(font, count, y, 0, SkString(), bounds);
193 }
153 194
154 /** 195 /**
155 * Allocates a new fully-positioned run and returns its writable glyph and position 196 * Allocates a new fully-positioned run and returns its writable glyph and position
156 * buffers for direct manipulation. 197 * buffers for direct manipulation.
157 * 198 *
158 * @param font The font to be used for this run. 199 * @param font The font to be used for this run.
159 * @param count Number of glyphs. 200 * @param count Number of glyphs.
201 * @param textByteCount length of the original UTF-8 text that
202 * corresponds to this sequence of glyphs. If 0,
203 * text will not be included in the textblob.
204 * @param lang Language code, currently unimplemented.
160 * @param bounds Optional run bounding box. If known in advance (!= NULL), it will 205 * @param bounds Optional run bounding box. If known in advance (!= NULL), it will
161 * be used when computing the blob bounds, to avoid re-measur ing. 206 * be used when computing the blob bounds, to avoid re-measur ing.
162 * 207 *
163 * @return Writable glyph and position buffers, valid until the next allocRun() 208 * @return Writable glyph and position buffers, valid until the next allocRun()
164 * or build() call. The glyph buffer and position buffer are 209 * or build() call. The glyph buffer and position buffer are
165 * guaranteed to hold @count@ and 2 * @count@ elements, respe ctively. 210 * guaranteed to hold @count@ and 2 * @count@ elements, respe ctively.
166 */ 211 */
167 const RunBuffer& allocRunPos(const SkPaint& font, int count, const SkRect* b ounds = NULL); 212 const RunBuffer& allocRunTextPos(const SkPaint& font, int count,
213 int textByteCount, SkString lang,
214 const SkRect* bounds = NULL);
215 const RunBuffer& allocRunPos(const SkPaint& font, int count,
216 const SkRect* bounds = NULL) {
217 return this->allocRunTextPos(font, count, 0, SkString(), bounds);
218 }
168 219
169 private: 220 private:
170 void reserve(size_t size); 221 void reserve(size_t size);
171 void allocInternal(const SkPaint& font, SkTextBlob::GlyphPositioning positio ning, 222 void allocInternal(const SkPaint& font, SkTextBlob::GlyphPositioning positio ning,
172 int count, SkPoint offset, const SkRect* bounds); 223 int count, int textBytes, SkPoint offset, const SkRect* b ounds);
173 bool mergeRun(const SkPaint& font, SkTextBlob::GlyphPositioning positioning, 224 bool mergeRun(const SkPaint& font, SkTextBlob::GlyphPositioning positioning,
174 int count, SkPoint offset); 225 int count, SkPoint offset);
175 void updateDeferredBounds(); 226 void updateDeferredBounds();
176 227
177 static SkRect ConservativeRunBounds(const SkTextBlob::RunRecord&); 228 static SkRect ConservativeRunBounds(const SkTextBlob::RunRecord&);
178 static SkRect TightRunBounds(const SkTextBlob::RunRecord&); 229 static SkRect TightRunBounds(const SkTextBlob::RunRecord&);
179 230
180 SkAutoTMalloc<uint8_t> fStorage; 231 SkAutoTMalloc<uint8_t> fStorage;
181 size_t fStorageSize; 232 size_t fStorageSize;
182 size_t fStorageUsed; 233 size_t fStorageUsed;
183 234
184 SkRect fBounds; 235 SkRect fBounds;
185 int fRunCount; 236 int fRunCount;
186 bool fDeferredBounds; 237 bool fDeferredBounds;
187 size_t fLastRun; // index into fStorage 238 size_t fLastRun; // index into fStorage
188 239
189 RunBuffer fCurrentRunBuffer; 240 RunBuffer fCurrentRunBuffer;
190 }; 241 };
191 242
192 #endif // SkTextBlob_DEFINED 243 #endif // SkTextBlob_DEFINED
OLDNEW
« no previous file with comments | « include/core/SkPicture.h ('k') | src/core/SkTextBlob.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698