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

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

Issue 473633002: SkTextBlob (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Alloc API + review comments Created 6 years, 4 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
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkTextBlob_DEFINED
9 #define SkTextBlob_DEFINED
10
11 #include "SkPaint.h"
12 #include "SkRefCnt.h"
13 #include "SkTArray.h"
14 #include "SkTDArray.h"
robertphillips 2014/08/20 14:52:18 Do we still need SkTemplates.h ?
f(malita) 2014/08/20 15:47:47 Done.
15 #include "SkTemplates.h"
16
17 /** \class SkTextBlob
18
19 SkTextBlob combines multiple text runs into an immutable, ref-counted struct ure.
20 */
21 class SkTextBlob : public SkRefCnt {
22 public:
23 /**
24 * Returns the blob bounding box.
25 */
26 const SkRect& bounds() const { return fBounds; }
27
28 /**
29 * Return a non-zero, unique value representing the text blob.
30 */
31 uint32_t uniqueID() const;
32
33 private:
34 enum GlyphPositioning {
35 kDefault_Positioning = 0, // Default glyph advances -- zero scalars per glyph.
36 kHorizontal_Positioning = 1, // Horizontal positioning -- one scalar p er glyph.
37 kFull_Positioning = 2 // Point positioning -- two scalars per g lyph.
38 };
39
40 class RunIterator {
41 public:
42 RunIterator(const SkTextBlob* blob);
43
44 bool done() const;
45 void next();
46
47 uint32_t glyphCount() const;
48 const uint16_t* glyphs() const;
49 const SkScalar* pos() const;
50 const SkPaint& font() const;
51 GlyphPositioning positioning() const;
52
53 private:
54 const SkTextBlob* fBlob;
55 int fIndex;
56 };
57
58 // A run is a sequence of glyphs sharing the same font metrics and positioni ng mode.
59 struct Run {
60 uint32_t count;
61 uint32_t glyphStart; // index into fGlyphBuffer
62 uint32_t posStart; // index into fPosBuffer
63 SkPoint offset; // run offset (unsued for fully positioned glyph s)
64 SkPaint font;
65 GlyphPositioning positioning;
66 };
67
68 SkTextBlob(uint16_t* glyphs, SkScalar* pos, const SkTArray<Run>* runs, const SkRect& bounds);
69
70 friend class SkCanvas;
71 friend class SkTextBlobBuilder;
72
73 const SkAutoTMalloc<uint16_t> fGlyphBuffer;
74 const SkAutoTMalloc<SkScalar> fPosBuffer;
robertphillips 2014/08/20 14:52:18 Can this be an SkTDArray ?
f(malita) 2014/08/20 15:47:47 It could, but technically the count and reserve fi
75 SkAutoTDelete<const SkTArray<Run> > fRuns;
76 const SkRect fBounds;
77
78 mutable uint32_t fUniqueID;
robertphillips 2014/08/20 14:52:17 INHERITED ?
f(malita) 2014/08/20 15:47:47 Done.
79 };
80
81 /** \class SkTextBlobBuilder
82
83 Helper class for constructing SkTextBlobs.
84 */
85 class SkTextBlobBuilder {
86 public:
87 /**
88 * @param runs The number of runs to be added, if known. This is a storage hint and
89 * not a limit.
90 */
91 SkTextBlobBuilder(unsigned runs = 0);
92
93 ~SkTextBlobBuilder();
94
95 /**
96 * Returns an immutable SkTextBlob for the current runs/glyphs. The builder is reset and
97 * can be reused.
98 */
99 const SkTextBlob* build();
100
101 /**
102 * Glyph and position buffers associated with a run.
103 *
104 * A run is a sequence of glyphs sharing the same font metrics and position ing mode.
105 */
106 struct RunBuffer {
107 uint16_t* glyphs;
108 SkScalar* pos;
109 };
110
111 /**
112 * Allocates a new default-positioned run and returns its writable glyph bu ffer
113 * for direct manipulation.
114 *
115 * @param font The font to be used for this run.
116 * @param count Number of glyphs.
117 * @param offset Run position within the blob.
118 * @param bounds Optional run bounding box. If known in advance (!= NULL), it will
119 * be used when computing the blob bounds, to avoid re-measu ring.
120 *
121 * @return A writable glyph buffer, valid until the next allocRun(), addRun() or
122 * build() call. The buffer is guaranteed to hold @count@ gl yphs.
123 */
124 uint16_t* allocRun(const SkPaint& font, size_t count, SkPoint offset,
reed1 2014/08/20 01:29:41 nit: we usually use x,y instead of a point for a p
f(malita) 2014/08/20 15:47:47 Done.
125 const SkRect* bounds = NULL);
126
127 /**
128 * Allocates a new horizontally-positioned run and returns its writable gly ph and position
129 * buffers for direct manipulation.
130 *
131 * @param font The font to be used for this run.
132 * @param count Number of glyphs.
133 * @param yOffset Run vertical position within the blob.
134 * @param bounds Optional run bounding box. If known in advance (!= NULL), it will
135 * be used when computing the blob bounds, to avoid re-measu ring.
136 *
137 * @return Writable glyph and position buffers, valid until the next allocRun(),
138 * addRun() or build() call. The buffers are guaranteed to h old @count@
139 * elements.
140 */
141 RunBuffer allocRun(const SkPaint& font, size_t count, SkScalar yOffset,
142 const SkRect* bounds = NULL);
143
144 /**
145 * Allocates a new fully-positioned run and returns its writable glyph and position
146 * buffers for direct manipulation.
147 *
148 * @param font The font to be used for this run.
149 * @param count Number of glyphs.
150 * @param bounds Optional run bounding box. If known in advance (!= NULL), it will
151 * be used when computing the blob bounds, to avoid re-measur ing.
152 *
153 * @return Writable glyph and position buffers, valid until the next allocRun(),
154 * addRun() or build() call. The glyph buffer and position bu ffer are
155 * guaranteed to hold @count@ and 2 * @count@ elements respec tively.
156 */
157 RunBuffer allocRun(const SkPaint& font, size_t count, const SkRect* bounds = NULL);
158
159 private:
robertphillips 2014/08/20 14:52:17 allocInternal ?
f(malita) 2014/08/20 15:47:47 Done.
160 void alloc_internal(const SkPaint& font, SkTextBlob::GlyphPositioning positi oning,
161 size_t count, SkPoint offset, const SkRect* bounds);
162 void ensureRun(const SkPaint& font, SkTextBlob::GlyphPositioning positioning ,
163 const SkPoint& offset);
164 RunBuffer currentRunBuffer();
165 void updateDeferredBounds();
166
167 SkTDArray<uint16_t> fGlyphBuffer;
168 SkTDArray<SkScalar> fPosBuffer;
169 SkTArray<SkTextBlob::Run>* fRuns;
170
171 SkRect fBounds;
172 bool fDeferredBounds;
173 };
174
175 #endif // SkTextBlob_DEFINED
OLDNEW
« no previous file with comments | « include/core/SkCanvas.h ('k') | samplecode/SampleText.cpp » ('j') | src/core/SkTextBlob.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698