class SkTextBlob final : public SkNVRefCnt<SkTextBlob> { const SkRect& bounds() const; uint32_t uniqueID() const; int getIntercepts(const SkScalar bounds[2], SkScalar intervals[], const SkPaint* paint = nullptr) const; static sk_sp<SkTextBlob> MakeFromText(const void* text, size_t byteLength, const SkFont& font, SkTextEncoding encoding = SkTextEncoding::kUTF8); static sk_sp<SkTextBlob> MakeFromString(const char* string, const SkFont& font, SkTextEncoding encoding = SkTextEncoding::kUTF8); size_t serialize(const SkSerialProcs& procs, void* memory, size_t memory_size) const; sk_sp<SkData> serialize(const SkSerialProcs& procs) const; static sk_sp<SkTextBlob> Deserialize(const void* data, size_t size, const SkDeserialProcs& procs); };
SkTextBlob combines multiple text runs into an immutable container. Each text run consists of Glyphs, Paint, and position. Only parts of Paint related to fonts and text rendering are used by run.
const SkRect& bounds()const
Returns conservative bounding box. Uses SkPaint associated with each glyph to determine glyph bounds, and unions all bounds. Returned bounds may be larger than the bounds of all glyphs in runs.
conservative bounding box
uint32_t uniqueID()const
Returns a non-zero value unique among all text blobs.
identifier for SkTextBlob
Text_Intercepts describe the intersection of drawn text Glyphs with a pair of lines parallel to the text advance. Text_Intercepts permits creating a underline that skips Descenders.
int getIntercepts(const SkScalar bounds[2], SkScalar intervals[], const SkPaint* paint = nullptr) const;
Returns the number of intervals that intersect bounds. bounds describes a pair of lines parallel to the text advance. The return count is zero or a multiple of two, and is at most twice the number of glyphs in the the blob.
Pass nullptr for intervals to determine the size of the interval array.
Runs within the blob that contain SkRSXform are ignored when computing intercepts.
bounds |
lower and upper line parallel to the advance |
intervals |
returned intersections; may be nullptr |
paint |
specifies stroking, SkPathEffect that affects the result; may be nullptr |
number of intersections; may be zero
static sk_sp<SkTextBlob> MakeFromText(const void* text, size_t byteLength, const SkFont& font, SkTextEncoding encoding = SkTextEncoding::kUTF8)
Creates Text_Blob with a single run. text meaning depends on Text_Encoding; by default, text is encoded as UTF-8.
font contains attributes used to define the run text: Typeface, Font_Size, Font_Scale_X, Font_Skew_X, Font_Hinting, Paint_Anti_Alias, Font_Embolden, Font_Force_Hinting, Font_Embedded_Bitmaps, Font_Hinting_Spacing, Font_Anti_Alias, Font_Linear, and Font_Subpixel .
text |
character code points or Glyphs drawn |
byteLength |
byte length of text array |
font |
text size, typeface, text scale, and so on, used to draw |
encoding |
one of: SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, SkTextEncoding::kUTF32, SkTextEncoding::kGlyphID |
Text_Blob constructed from one run
MakeFromString SkTextBlobBuilder
static sk_sp<SkTextBlob> MakeFromString(const char* string, const SkFont& font, SkTextEncoding encoding = SkTextEncoding::kUTF8)
Creates Text_Blob with a single run. string meaning depends on Text_Encoding; by default, string is encoded as UTF-8.
font contains Font_Metrics used to define the run text: Typeface, Font_Size, Font_Scale_X, Font_Skew_X, Font_Hinting, Paint_Anti_Alias, Font_Embolden, Font_Force_Hinting, Font_Embedded_Bitmaps, Font_Hinting_Spacing, Font_Anti_Alias, Font_Linear, and Font_Subpixel .
string |
character code points or Glyphs drawn |
font |
text size, typeface, text scale, and so on, used to draw |
encoding |
one of: SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, SkTextEncoding::kUTF32, SkTextEncoding::kGlyphID |
Text_Blob constructed from one run
MakeFromText SkTextBlobBuilder
size_t serialize(const SkSerialProcs& procs, void* memory, size_t memory_size)const
Writes data to allow later reconstruction of SkTextBlob. memory points to storage to receive the encoded data, and memory_size describes the size of storage. Returns bytes used if provided storage is large enough to hold all data; otherwise, returns zero.
procs.fTypefaceProc permits supplying a custom function to encode SkTypeface. If procs.fTypefaceProc is nullptr, default encoding is used. procs.fTypefaceCtx may be used to provide user context to procs.fTypefaceProc; procs.fTypefaceProc is called with a pointer to SkTypeface and user context.
procs |
custom serial data encoders; may be nullptr |
memory |
storage for data |
memory_size |
size of storage |
bytes written, or zero if required storage is larger than memory_size
sk_sp<SkData> serialize(const SkSerialProcs& procs)const
Returns storage containing SkData describing SkTextBlob, using optional custom encoders.
procs.fTypefaceProc permits supplying a custom function to encode SkTypeface. If procs.fTypefaceProc is nullptr, default encoding is used. procs.fTypefaceCtx may be used to provide user context to procs.fTypefaceProc; procs.fTypefaceProc is called with a pointer to SkTypeface and user context.
procs |
custom serial data encoders; may be nullptr |
storage containing serialized SkTextBlob
Deserialize SkData SkSerialProcs
static sk_sp<SkTextBlob> Deserialize(const void* data, size_t size, const SkDeserialProcs& procs)
Recreates SkTextBlob that was serialized into data. Returns constructed SkTextBlob if successful; otherwise, returns nullptr. Fails if size is smaller than required data length, or if data does not permit constructing valid SkTextBlob.
procs.fTypefaceProc permits supplying a custom function to decode SkTypeface. If procs.fTypefaceProc is nullptr, default decoding is used. procs.fTypefaceCtx may be used to provide user context to procs.fTypefaceProc; procs.fTypefaceProc is called with a pointer to SkTypeface data, data byte length, and user context.
data |
pointer for serial data |
size |
size of data |
procs |
custom serial data decoders; may be nullptr |
SkTextBlob constructed from data in memory