Index: include/core/SkTextBlob.h |
diff --git a/include/core/SkTextBlob.h b/include/core/SkTextBlob.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7de034e751f83f19c77311aad66f5373219fd561 |
--- /dev/null |
+++ b/include/core/SkTextBlob.h |
@@ -0,0 +1,118 @@ |
+/* |
+ * Copyright 2014 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#ifndef SkTextBlob_DEFINED |
+#define SkTextBlob_DEFINED |
+ |
+#include "SkPaint.h" |
+#include "SkRect.h" |
+#include "SkRefCnt.h" |
+#include "SkTDArray.h" |
+ |
+class SkBaseDevice; |
+class SkDraw; |
+struct SkPoint; |
+ |
+/** \class SkTextChunk |
+ |
+ A text chunk is a sequence of (optionally positioned) glyphs sharing the same |
+ font data/metrics. |
+*/ |
+class SK_API SkTextChunk { |
+public: |
+ static const SkTextChunk* Create(const uint16_t* glyphs, size_t count, const SkPaint& paint, |
+ const SkRect* bounds = NULL); |
+ static const SkTextChunk* Create(const uint16_t* glyphs, size_t count, const SkScalar* pos, |
+ const SkPaint& paint, const SkRect* bounds = NULL); |
+ static const SkTextChunk* Create(const uint16_t* glyphs, size_t count, const SkPoint* pos, |
+ const SkPaint& paint, const SkRect* bounds = NULL); |
+ |
+ ~SkTextChunk(); |
+ |
+ void draw(SkBaseDevice*, const SkDraw&, const SkPaint&) const; |
+ |
+ const SkRect& bounds() const; |
+ |
+private: |
+ SkTextChunk(const uint16_t* glyphs, size_t count, const SkScalar* pos, unsigned scalarsPerPos, |
+ const SkPaint& paint, const SkRect* bounds); |
+ |
+ friend class SkPictureRecord; |
+ |
+ size_t fGlyphCount; |
+ uint16_t* fGlyphs; |
+ SkScalar* fPos; // FIXME: merge glyphs/pos storage? |
+ |
+ SkPaint fFont; // FIXME: SkFont |
+ |
+ mutable SkRect fBounds; |
+ mutable bool fBoundsDirty; |
+ |
+ unsigned short fScalarsPerPos; |
+}; |
+ |
+/** \class SkTextBlob |
+ |
+ SkTextBlob combines multiple text chunks into an immutable, ref-counted structure. |
+*/ |
+class SK_API SkTextBlob : public SkRefCnt { |
+public: |
+ static const SkTextBlob* Create(const SkTextChunk* chunk); |
+ static const SkTextBlob* Create(const SkTDArray<const SkTextChunk*>& chunks); |
+ |
+ ~SkTextBlob(); |
+ |
+ uint32_t uniqueID() const; |
+ |
+ class SK_API Iter { |
+ public: |
+ Iter(const SkTextBlob* blob) : fBlob(blob), fIndex(0) { SkASSERT(blob); } |
+ const SkTextChunk* next() { |
+ return (fIndex < fBlob->fChunks.count()) ? fBlob->fChunks[fIndex++] : NULL; |
+ } |
+ |
+ private: |
+ const SkTextBlob* fBlob; |
+ int fIndex; |
+ }; |
+ |
+private: |
+ SkTextBlob(const SkTDArray<const SkTextChunk*>& chunks); |
+ |
+ const SkTDArray<const SkTextChunk*> fChunks; |
+ mutable uint32_t fUniqueID; |
+}; |
+ |
+/** \class SkTextBlobBuilder |
+ |
+ Helper class for constructing SkTextBlobs. |
+*/ |
+class SK_API SkTextBlobBuilder { |
+public: |
+ SkTextBlobBuilder(); |
+ ~SkTextBlobBuilder(); |
+ |
+ 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
|
+ |
+ // FIXME: should we support glyph-wise ops? Not sure whether this is interesting |
+ // for clients at this point -- they likely have a better idea of chunking. |
+ /* |
+ void addGlyph(uint16_t glyph, const SkPaint& font, const SkRect* bounds = NULL); |
+ void addGlyph(uint16_t glyph, const SkScalar pos, const SkPaint& font, |
+ const SkRect* bounds = NULL); |
+ void addGlyph(uint16_t glyph, const SkPoint pos, const SkPaint& font, |
+ const SkRect* bounds = NULL); |
+ */ |
+ |
+ const SkTextBlob* build(); |
+ |
+private: |
+ |
+ SkTDArray<const SkTextChunk*> fChunks; |
+}; |
+ |
+#endif // SkTextBlob_DEFINED |