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

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

Issue 473633002: SkTextBlob (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Consolidated blob constructor + 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 "SkRect.h"
13 #include "SkRefCnt.h"
14 #include "SkTDArray.h"
15
16 class SkBaseDevice;
17 class SkDraw;
18 struct SkPoint;
19
20 /** \class SkTextChunk
21
22 A text chunk is a sequence of (optionally positioned) glyphs sharing the sam e
23 font data/metrics.
24 */
25 class SK_API SkTextChunk {
26 public:
27 static const SkTextChunk* Create(const uint16_t* glyphs, size_t count, const SkPaint& paint,
28 const SkRect* bounds = NULL);
29 static const SkTextChunk* Create(const uint16_t* glyphs, size_t count, const SkScalar* pos,
30 const SkPaint& paint, const SkRect* bounds = NULL);
31 static const SkTextChunk* Create(const uint16_t* glyphs, size_t count, const SkPoint* pos,
32 const SkPaint& paint, const SkRect* bounds = NULL);
33
34 ~SkTextChunk();
35
36 void draw(SkBaseDevice*, const SkDraw&, const SkPaint&) const;
37
38 const SkRect& bounds() const;
39
40 private:
41 SkTextChunk(const uint16_t* glyphs, size_t count, const SkScalar* pos, unsig ned scalarsPerPos,
42 const SkPaint& paint, const SkRect* bounds);
43
44 friend class SkPictureRecord;
45
46 size_t fGlyphCount;
47 uint16_t* fGlyphs;
48 SkScalar* fPos; // FIXME: merge glyphs/pos storage?
49
50 SkPaint fFont; // FIXME: SkFont
51
52 mutable SkRect fBounds;
53 mutable bool fBoundsDirty;
54
55 unsigned short fScalarsPerPos;
56 };
57
58 /** \class SkTextBlob
59
60 SkTextBlob combines multiple text chunks into an immutable, ref-counted stru cture.
61 */
62 class SK_API SkTextBlob : public SkRefCnt {
63 public:
64 static const SkTextBlob* Create(const SkTextChunk* chunk);
65 static const SkTextBlob* Create(const SkTDArray<const SkTextChunk*>& chunks) ;
66
67 ~SkTextBlob();
68
69 uint32_t uniqueID() const;
70
71 class SK_API Iter {
72 public:
73 Iter(const SkTextBlob* blob) : fBlob(blob), fIndex(0) { SkASSERT(blob); }
74 const SkTextChunk* next() {
75 return (fIndex < fBlob->fChunks.count()) ? fBlob->fChunks[fIndex++] : NULL;
76 }
77
78 private:
79 const SkTextBlob* fBlob;
80 int fIndex;
81 };
82
83 private:
84 SkTextBlob(const SkTDArray<const SkTextChunk*>& chunks);
85
86 const SkTDArray<const SkTextChunk*> fChunks;
87 mutable uint32_t fUniqueID;
88 };
89
90 /** \class SkTextBlobBuilder
91
92 Helper class for constructing SkTextBlobs.
93 */
94 class SK_API SkTextBlobBuilder {
95 public:
96 SkTextBlobBuilder();
97 ~SkTextBlobBuilder();
98
99 void addChunk(const SkTextChunk* chunk);
reed1 2014/08/14 15:55:49 Hmmm, I was imagining an alternate adder style: u
f(malita) 2014/08/14 16:27:01 I like this idea, and there's no reason not to hav
100
101 // FIXME: should we support glyph-wise ops? Not sure whether this is interes ting
102 // for clients at this point -- they likely have a better idea of chunking.
103 /*
104 void addGlyph(uint16_t glyph, const SkPaint& font, const SkRect* bounds = NU LL);
105 void addGlyph(uint16_t glyph, const SkScalar pos, const SkPaint& font,
106 const SkRect* bounds = NULL);
107 void addGlyph(uint16_t glyph, const SkPoint pos, const SkPaint& font,
108 const SkRect* bounds = NULL);
109 */
110
111 const SkTextBlob* build();
112
113 private:
114
115 SkTDArray<const SkTextChunk*> fChunks;
116 };
117
118 #endif // SkTextBlob_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698