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

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: 2016-06-20 (Monday) 15:33:30 EDT Created 4 years, 6 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
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 : public SkRefCnt { 23 class SK_API SkTextBlob : public SkRefCnt {
(...skipping 15 matching lines...) Expand all
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 22 matching lines...) Expand all
81 // The actual payload resides in externally-managed storage, following the o bject. 82 // The actual payload resides in externally-managed storage, following the o bject.
82 // (see the .cpp for more details) 83 // (see the .cpp for more details)
83 84
84 typedef SkRefCnt INHERITED; 85 typedef SkRefCnt INHERITED;
85 }; 86 };
86 87
87 /** \class SkTextBlobBuilder 88 /** \class SkTextBlobBuilder
88 89
89 Helper class for constructing SkTextBlobs. 90 Helper class for constructing SkTextBlobs.
90 */ 91 */
91 class SK_API SkTextBlobBuilder { 92 class SK_API SkTextBlobBuilder {
tomhudson 2016/06/21 14:51:28 Tangent not for this CL: do we really have to have
hal.canary 2016/06/22 17:59:57 How else will a client construct aSkTextBlob?
92 public: 93 public:
93 SkTextBlobBuilder(); 94 SkTextBlobBuilder();
94 95
95 ~SkTextBlobBuilder(); 96 ~SkTextBlobBuilder();
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 and position ing mode.
108 *
109 * If textByteCount is 0, utf8text and clusters will be NUL.
Rik 2016/06/20 23:05:16 It's unclear where textByteCount comes from. Maybe
tomhudson 2016/06/21 14:51:28 nit: NULL?
hal.canary 2016/06/22 17:59:57 Done.
hal.canary 2016/06/22 17:59:57 Acknowledged.
110 *
111 * utf8text will point to a buffer of size textByteCount bytes.
112 *
113 * clusters (if not NULL) will point to an array of size count.
Rik 2016/06/20 23:05:16 Could be more descriptive.
hal.canary 2016/06/22 17:59:57 Done.
114 * For each glyph, give the byte-offset into the text for the
115 * first character in that glyph's cluster.
107 */ 116 */
108 struct RunBuffer { 117 struct RunBuffer {
109 uint16_t* glyphs; 118 uint16_t* glyphs;
110 SkScalar* pos; 119 SkScalar* pos;
120 char* utf8text;
121 uint32_t* clusters;
111 }; 122 };
112 123
113 /** 124 /**
114 * Allocates a new default-positioned run and returns its writable glyph bu ffer 125 * Allocates a new default-positioned run and returns its writable glyph bu ffer
115 * for direct manipulation. 126 * for direct manipulation.
116 * 127 *
117 * @param font The font to be used for this run. 128 * @param font The font to be used for this run.
118 * @param count Number of glyphs. 129 * @param count Number of glyphs.
119 * @param x,y Position within the blob. 130 * @param x,y Position within the blob.
131 * @param textByteCount length of the original UTF-8 text that corresponds to this
132 * sequence of glyphs. If 0, text will be unkown.
tomhudson 2016/06/21 14:51:28 nit: unknown?
hal.canary 2016/06/22 17:59:57 Done.
133 * @param lang Language code, currently unimplemented.
120 * @param bounds Optional run bounding box. If known in advance (!= NULL), it will 134 * @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. 135 * be used when computing the blob bounds, to avoid re-measu ring.
122 * 136 *
123 * @return A writable glyph buffer, valid until the next allocRun() or 137 * @return A writable glyph buffer, valid until the next allocRun() or
124 * build() call. The buffer is guaranteed to hold @count@ gl yphs. 138 * build() call. The buffer is guaranteed to hold @count@ gl yphs.
125 */ 139 */
140 const RunBuffer& allocRunText(const SkPaint& font,
141 int count,
142 SkScalar x,
143 SkScalar y,
144 int textByteCount,
Rik 2016/06/20 23:05:16 Why not pass the UTF-8 buffer here?
hal.canary 2016/06/22 17:59:57 Let's pass the text and glyphs the same way.
145 SkString lang,
146 const SkRect* bounds = NULL);
126 const RunBuffer& allocRun(const SkPaint& font, int count, SkScalar x, SkScal ar y, 147 const RunBuffer& allocRun(const SkPaint& font, int count, SkScalar x, SkScal ar y,
127 const SkRect* bounds = NULL); 148 const SkRect* bounds = NULL) {
149 return this->allocRunText(font, count, x, y, 0, SkString(), bounds);
150 }
128 151
129 /** 152 /**
130 * Allocates a new horizontally-positioned run and returns its writable gly ph and position 153 * Allocates a new horizontally-positioned run and returns its writable gly ph and position
131 * buffers for direct manipulation. 154 * buffers for direct manipulation.
132 * 155 *
133 * @param font The font to be used for this run. 156 * @param font The font to be used for this run.
134 * @param count Number of glyphs. 157 * @param count Number of glyphs.
135 * @param y Vertical offset within the blob. 158 * @param y Vertical offset within the blob.
159 * @param textByteCount length of the original UTF-8 text that corresponds to this
160 * sequence of glyphs. If 0, text will be unkown.
161 * @param lang Language code, currently unimplemented.
136 * @param bounds Optional run bounding box. If known in advance (!= NULL), it will 162 * @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. 163 * be used when computing the blob bounds, to avoid re-measu ring.
138 * 164 *
139 * @return Writable glyph and position buffers, valid until the next allocRun() 165 * @return Writable glyph and position buffers, valid until the next allocRun()
140 * or build() call. The buffers are guaranteed to hold @coun t@ elements. 166 * or build() call. The buffers are guaranteed to hold @coun t@ elements.
141 */ 167 */
168 const RunBuffer& allocRunTextPosH(const SkPaint& font, int count, SkScalar y ,
169 int textByteCount, SkString lang,
170 const SkRect* bounds = NULL);
142 const RunBuffer& allocRunPosH(const SkPaint& font, int count, SkScalar y, 171 const RunBuffer& allocRunPosH(const SkPaint& font, int count, SkScalar y,
143 const SkRect* bounds = NULL); 172 const SkRect* bounds = NULL) {
173 return this->allocRunTextPosH(font, count, y, 0, SkString(), bounds);
174 }
144 175
145 /** 176 /**
146 * Allocates a new fully-positioned run and returns its writable glyph and position 177 * Allocates a new fully-positioned run and returns its writable glyph and position
147 * buffers for direct manipulation. 178 * buffers for direct manipulation.
148 * 179 *
149 * @param font The font to be used for this run. 180 * @param font The font to be used for this run.
150 * @param count Number of glyphs. 181 * @param count Number of glyphs.
182 * @param textByteCount length of the original UTF-8 text that corresponds to this
183 * sequence of glyphs. If 0, text will be unkown.
184 * @param lang Language code, currently unimplemented.
151 * @param bounds Optional run bounding box. If known in advance (!= NULL), it will 185 * @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. 186 * be used when computing the blob bounds, to avoid re-measur ing.
153 * 187 *
154 * @return Writable glyph and position buffers, valid until the next allocRun() 188 * @return Writable glyph and position buffers, valid until the next allocRun()
155 * or build() call. The glyph buffer and position buffer are 189 * or build() call. The glyph buffer and position buffer are
156 * guaranteed to hold @count@ and 2 * @count@ elements, respe ctively. 190 * guaranteed to hold @count@ and 2 * @count@ elements, respe ctively.
157 */ 191 */
158 const RunBuffer& allocRunPos(const SkPaint& font, int count, const SkRect* b ounds = NULL); 192 const RunBuffer& allocRunTextPos(const SkPaint& font, int count,
193 int textByteCount, SkString lang,
194 const SkRect* bounds = NULL);
195 const RunBuffer& allocRunPos(const SkPaint& font, int count,
196 const SkRect* bounds = NULL) {
197 return this->allocRunTextPos(font, count, 0, SkString(), bounds);
198 }
159 199
160 private: 200 private:
161 void reserve(size_t size); 201 void reserve(size_t size);
162 void allocInternal(const SkPaint& font, SkTextBlob::GlyphPositioning positio ning, 202 void allocInternal(const SkPaint& font, SkTextBlob::GlyphPositioning positio ning,
163 int count, SkPoint offset, const SkRect* bounds); 203 int count, int testSize, SkPoint offset, const SkRect* bo unds);
reed1 2016/06/20 19:56:24 size_t? testSize -> textSize? is this a byte count
hal.canary 2016/06/22 17:59:57 I don't know. int, unsigned, or size_t would all
164 bool mergeRun(const SkPaint& font, SkTextBlob::GlyphPositioning positioning, 204 bool mergeRun(const SkPaint& font, SkTextBlob::GlyphPositioning positioning,
165 int count, SkPoint offset); 205 int count, SkPoint offset);
166 void updateDeferredBounds(); 206 void updateDeferredBounds();
167 207
168 static SkRect ConservativeRunBounds(const SkTextBlob::RunRecord&); 208 static SkRect ConservativeRunBounds(const SkTextBlob::RunRecord&);
169 static SkRect TightRunBounds(const SkTextBlob::RunRecord&); 209 static SkRect TightRunBounds(const SkTextBlob::RunRecord&);
170 210
171 SkAutoTMalloc<uint8_t> fStorage; 211 SkAutoTMalloc<uint8_t> fStorage;
172 size_t fStorageSize; 212 size_t fStorageSize;
173 size_t fStorageUsed; 213 size_t fStorageUsed;
174 214
175 SkRect fBounds; 215 SkRect fBounds;
176 int fRunCount; 216 int fRunCount;
177 bool fDeferredBounds; 217 bool fDeferredBounds;
178 size_t fLastRun; // index into fStorage 218 size_t fLastRun; // index into fStorage
179 219
180 RunBuffer fCurrentRunBuffer; 220 RunBuffer fCurrentRunBuffer;
181 }; 221 };
182 222
183 #endif // SkTextBlob_DEFINED 223 #endif // SkTextBlob_DEFINED
OLDNEW
« no previous file with comments | « include/core/SkPicture.h ('k') | src/core/SkTextBlob.cpp » ('j') | src/core/SkTextBlob.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698