diff options
author | halcanary <halcanary@google.com> | 2016-08-30 11:58:33 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-30 11:58:33 -0700 |
commit | 4f0a23a8d54f5eb0fdacfff7c109b9045b548978 (patch) | |
tree | 18a57576bf48037cbf2f4485b0f2c635de4fc567 /include | |
parent | fd7f867a0577a241ddbcb06eaa6aa104b78ff695 (diff) |
SkTextBlob: Begin implementing Extended TextBlob API
BUG=skia:5434
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2084533004
Review-Url: https://codereview.chromium.org/2084533004
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkPicture.h | 3 | ||||
-rw-r--r-- | include/core/SkTextBlob.h | 63 |
2 files changed, 59 insertions, 7 deletions
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h index 7cfa6679f3..9ba851005d 100644 --- a/include/core/SkPicture.h +++ b/include/core/SkPicture.h @@ -213,10 +213,11 @@ private: // V45: Add invNormRotation to SkLightingShader. // V46: Add drawTextRSXform // V47: Add occluder rect to SkBlurMaskFilter + // V48: Read and write extended SkTextBlobs. // Only SKPs within the min/current picture version range (inclusive) can be read. static const uint32_t MIN_PICTURE_VERSION = 35; // Produced by Chrome M39. - static const uint32_t CURRENT_PICTURE_VERSION = 47; + static const uint32_t CURRENT_PICTURE_VERSION = 48; static_assert(MIN_PICTURE_VERSION <= 41, "Remove kFontFileName and related code from SkFontDescriptor.cpp."); diff --git a/include/core/SkTextBlob.h b/include/core/SkTextBlob.h index 1addb6f914..01263af02d 100644 --- a/include/core/SkTextBlob.h +++ b/include/core/SkTextBlob.h @@ -10,6 +10,7 @@ #include "../private/SkTemplates.h" #include "SkPaint.h" +#include "SkString.h" #include "SkRefCnt.h" class SkReadBuffer; @@ -49,7 +50,7 @@ public: return MakeFromBuffer(buffer).release(); } - enum GlyphPositioning { + enum GlyphPositioning : uint8_t { kDefault_Positioning = 0, // Default glyph advances -- zero scalars per glyph. kHorizontal_Positioning = 1, // Horizontal positioning -- one scalar per glyph. kFull_Positioning = 2 // Point positioning -- two scalars per glyph. @@ -112,11 +113,29 @@ public: /** * Glyph and position buffers associated with a run. * - * A run is a sequence of glyphs sharing the same font metrics and positioning mode. + * A run is a sequence of glyphs sharing the same font metrics + * and positioning mode. + * + * If textByteCount is 0, utf8text and clusters will be NULL (no + * character information will be associated with the glyphs). + * + * utf8text will point to a buffer of size textByteCount bytes. + * + * clusters (if not NULL) will point to an array of size count. + * For each glyph, give the byte-offset into the text for the + * first byte in the first character in that glyph's cluster. + * Each value in the array should be an integer less than + * textByteCount. Values in the array should either be + * monotonically increasing (left-to-right text) or monotonically + * decreasing (right-to-left text). This definiton is conviently + * the same as used by Harfbuzz's hb_glyph_info_t::cluster field, + * except that Harfbuzz interleaves glyphs and clusters. */ struct RunBuffer { SkGlyphID* glyphs; SkScalar* pos; + char* utf8text; + uint32_t* clusters; }; /** @@ -126,14 +145,27 @@ public: * @param font The font to be used for this run. * @param count Number of glyphs. * @param x,y Position within the blob. + * @param textByteCount length of the original UTF-8 text that + * corresponds to this sequence of glyphs. If 0, + * text will not be included in the textblob. + * @param lang Language code, currently unimplemented. * @param bounds Optional run bounding box. If known in advance (!= NULL), it will * be used when computing the blob bounds, to avoid re-measuring. * * @return A writable glyph buffer, valid until the next allocRun() or * build() call. The buffer is guaranteed to hold @count@ glyphs. */ + const RunBuffer& allocRunText(const SkPaint& font, + int count, + SkScalar x, + SkScalar y, + int textByteCount, + SkString lang, + const SkRect* bounds = NULL); const RunBuffer& allocRun(const SkPaint& font, int count, SkScalar x, SkScalar y, - const SkRect* bounds = NULL); + const SkRect* bounds = NULL) { + return this->allocRunText(font, count, x, y, 0, SkString(), bounds); + } /** * Allocates a new horizontally-positioned run and returns its writable glyph and position @@ -142,14 +174,23 @@ public: * @param font The font to be used for this run. * @param count Number of glyphs. * @param y Vertical offset within the blob. + * @param textByteCount length of the original UTF-8 text that + * corresponds to this sequence of glyphs. If 0, + * text will not be included in the textblob. + * @param lang Language code, currently unimplemented. * @param bounds Optional run bounding box. If known in advance (!= NULL), it will * be used when computing the blob bounds, to avoid re-measuring. * * @return Writable glyph and position buffers, valid until the next allocRun() * or build() call. The buffers are guaranteed to hold @count@ elements. */ + const RunBuffer& allocRunTextPosH(const SkPaint& font, int count, SkScalar y, + int textByteCount, SkString lang, + const SkRect* bounds = NULL); const RunBuffer& allocRunPosH(const SkPaint& font, int count, SkScalar y, - const SkRect* bounds = NULL); + const SkRect* bounds = NULL) { + return this->allocRunTextPosH(font, count, y, 0, SkString(), bounds); + } /** * Allocates a new fully-positioned run and returns its writable glyph and position @@ -157,6 +198,10 @@ public: * * @param font The font to be used for this run. * @param count Number of glyphs. + * @param textByteCount length of the original UTF-8 text that + * corresponds to this sequence of glyphs. If 0, + * text will not be included in the textblob. + * @param lang Language code, currently unimplemented. * @param bounds Optional run bounding box. If known in advance (!= NULL), it will * be used when computing the blob bounds, to avoid re-measuring. * @@ -164,12 +209,18 @@ public: * or build() call. The glyph buffer and position buffer are * guaranteed to hold @count@ and 2 * @count@ elements, respectively. */ - const RunBuffer& allocRunPos(const SkPaint& font, int count, const SkRect* bounds = NULL); + const RunBuffer& allocRunTextPos(const SkPaint& font, int count, + int textByteCount, SkString lang, + const SkRect* bounds = NULL); + const RunBuffer& allocRunPos(const SkPaint& font, int count, + const SkRect* bounds = NULL) { + return this->allocRunTextPos(font, count, 0, SkString(), bounds); + } private: void reserve(size_t size); void allocInternal(const SkPaint& font, SkTextBlob::GlyphPositioning positioning, - int count, SkPoint offset, const SkRect* bounds); + int count, int textBytes, SkPoint offset, const SkRect* bounds); bool mergeRun(const SkPaint& font, SkTextBlob::GlyphPositioning positioning, int count, SkPoint offset); void updateDeferredBounds(); |