OLD | NEW |
---|---|
(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, | |
mtklein
2014/08/14 14:00:42
Doesn't this need another SkScalar for the shared
f(malita)
2014/08/14 14:29:26
I'm hoping most blobs will be relocatable (at leas
| |
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 SkPaint& paint, cons t SkRect* bounds); | |
42 SkTextChunk(const uint16_t* glyphs, size_t count, const SkScalar* pos, const SkPaint& paint, | |
43 const SkRect* bounds); | |
44 SkTextChunk(const uint16_t* glyphs, size_t count, const SkPoint* pos, const SkPaint& paint, | |
45 const SkRect* bounds); | |
46 | |
47 void init(const uint16_t*, size_t, const SkRect*, const SkScalar*); | |
48 | |
49 friend class SkPictureRecord; | |
50 | |
51 size_t fGlyphCount; | |
52 uint16_t* fGlyphs; | |
53 SkScalar* fPos; // FIXME: merge glyphs/pos storage? | |
54 | |
55 SkPaint fFont; // FIXME: SkFont | |
56 | |
57 mutable SkRect fBounds; | |
mtklein
2014/08/14 14:00:42
We create TextChunks all at once right? If so, le
f(malita)
2014/08/14 14:29:26
It's not completely clear whether we *always* need
mtklein
2014/08/14 14:38:45
I'm going to try have pictures start querying the
f(malita)
2014/08/14 16:13:36
Awesome, that settles it :)
I think it also makes
| |
58 mutable bool fBoundsDirty : 1; | |
mtklein
2014/08/14 14:00:42
I'd drop the bit packing for now? It's particular
f(malita)
2014/08/14 14:29:26
Done.
| |
59 | |
60 unsigned fScalarsPerPos : 2; | |
61 }; | |
62 | |
63 /** \class SkTextBlob | |
64 | |
65 SkTextBlob combines multiple text chunks into an immutable, ref-counted stru cture. | |
66 */ | |
67 class SK_API SkTextBlob : public SkRefCnt { | |
68 public: | |
69 static const SkTextBlob* Create(const SkTextChunk* chunk); | |
70 static const SkTextBlob* Create(const SkTDArray<const SkTextChunk*>& chunks) ; | |
71 | |
72 ~SkTextBlob(); | |
73 | |
74 uint32_t uniqueID() const; | |
75 | |
76 class SK_API Iter { | |
77 public: | |
78 Iter(const SkTextBlob* blob) : fBlob(blob), fIndex(0) { SkASSERT(blob); } | |
79 const SkTextChunk* next() { | |
80 return (fIndex < fBlob->fChunks.count()) ? fBlob->fChunks[fIndex++] : NULL; | |
81 } | |
82 | |
83 private: | |
84 const SkTextBlob* fBlob; | |
85 int fIndex; | |
86 }; | |
87 | |
88 private: | |
89 SkTextBlob(const SkTDArray<const SkTextChunk*>& chunks); | |
90 | |
91 const SkTDArray<const SkTextChunk*> fChunks; | |
92 mutable uint32_t fUniqueID; | |
93 }; | |
94 | |
95 /** \class SkTextBlobBuilder | |
96 | |
97 Helper class for constructing SkTextBlobs. | |
98 */ | |
99 class SK_API SkTextBlobBuilder { | |
100 public: | |
101 SkTextBlobBuilder(); | |
102 ~SkTextBlobBuilder(); | |
103 | |
104 void addChunk(const SkTextChunk* chunk); | |
105 | |
106 // FIXME: should we support glyph-wise ops? Not sure whether this is interes ting | |
107 // for clients at this point -- they likely have a better idea of chunking. | |
108 /* | |
109 void addGlyph(uint16_t glyph, const SkPaint& font, const SkRect* bounds = NU LL); | |
110 void addGlyph(uint16_t glyph, const SkScalar pos, const SkPaint& font, | |
111 const SkRect* bounds = NULL); | |
112 void addGlyph(uint16_t glyph, const SkPoint pos, const SkPaint& font, | |
113 const SkRect* bounds = NULL); | |
114 */ | |
115 | |
116 const SkTextBlob* build(); | |
jbroman
2014/08/14 14:46:02
nit: If SkTextBlobs are always immutable, why the
f(malita)
2014/08/14 16:13:36
In general, I would actually find that desirable:
mtklein
2014/08/14 16:22:23
I'm in (perhaps, am?) the the-more-const-the-bette
| |
117 | |
118 private: | |
119 | |
120 SkTDArray<const SkTextChunk*> fChunks; | |
jbroman
2014/08/14 14:46:02
Random thought: pros/cons of having this approach
f(malita)
2014/08/14 16:13:36
The reason it turned out this way is trying to avo
| |
121 }; | |
122 | |
123 #endif // SkTextBlob_DEFINED | |
OLD | NEW |