skia2/site/user/api/SkTextBlob_Reference.md
Cary Clark cb6bef0ad5 Update bookmaker
- This update includes font documentation.
SkFont_Reference.bmh was generated by running:

  bookmaker -b docs -i include/core/SkFont.h -t

This creates a placeholder
for examples and additional documentation.

- More work done to exclude experimental/private
symbols.

Symbols that include "experimental_", "legacy_",
"private_", "temporary_", "deprecated_" as part
of their name (case-insensitive) are not
referenced by the on-line docs and don't need
comments.

Tables built for online only include public symbols.

- Better links for constructors, destructors, operators
- Fixed some minor public interfaces
- Removed _const crutch on operators
- Keep includes inside 100 columns

TBR=reed@google.com

Docs-Preview: https://skia.org/?cl=171900
Bug: skia:
Change-Id: I93b229c6625d800604671e05b82a14c06cb906d2
Reviewed-on: https://skia-review.googlesource.com/c/171900
Reviewed-by: Cary Clark <caryclark@skia.org>
Commit-Queue: Cary Clark <caryclark@skia.org>
2018-11-29 18:17:30 +00:00

18 KiB

SkTextBlob Reference


class SkTextBlob final : public SkNVRefCnt<SkTextBlob> {

    const SkRect& bounds() const;
    uint32_t uniqueID() const;
    static sk_sp<SkTextBlob> MakeFromText(const void* text, size_t byteLength, const SkFont& font,
                                      SkPaint::TextEncoding encoding = SkPaint::kUTF8_TextEncoding);
    static sk_sp<SkTextBlob> MakeFromString(const char* string, const SkFont& font,
                                    SkPaint::TextEncoding encoding = SkPaint::kUTF8_TextEncoding);
    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.

Return Value

conservative bounding box

Example

See Also

SkPath::getBounds


uint32_t uniqueID()const

Returns a non-zero value unique among all text blobs.

Return Value

identifier for SkTextBlob

Example

See Also

SkRefCnt


static sk_sp<SkTextBlob> MakeFromText(const void* text, size_t byteLength, const SkFont& font,
                                      SkPaint::TextEncoding encoding = SkPaint::kUTF8_TextEncoding)

Creates Text_Blob with a single run. text meaning depends on Paint_Text_Encoding; by default, text is encoded as UTF-8.

font contains attributes used to define the run text: Typeface, Paint_Text_Size, Paint_Text_Scale_X, Paint_Text_Skew_X, Paint_Hinting, Anti_Alias, Paint_Fake_Bold, Font_Embedded_Bitmaps, Full_Hinting_Spacing, LCD_Text, Linear_Text, and Subpixel_Text .

Parameters

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: kUTF8_SkTextEncoding, kUTF16_SkTextEncoding, kUTF32_SkTextEncoding, kGlyphID_SkTextEncoding

Return Value

Text_Blob constructed from one run

Example

See Also

MakeFromString SkTextBlobBuilder


static sk_sp<SkTextBlob> MakeFromString(const char* string, const SkFont& font,
                                       SkPaint::TextEncoding encoding = SkPaint::kUTF8_TextEncoding)

Creates Text_Blob with a single run. string meaning depends on Paint_Text_Encoding; by default, string is encoded as UTF-8.

font contains Paint_Font_Metrics used to define the run text: Typeface, Paint_Text_Size, Paint_Text_Scale_X, Paint_Text_Skew_X, Paint_Hinting, Anti_Alias, Paint_Fake_Bold, Font_Embedded_Bitmaps, Full_Hinting_Spacing, LCD_Text, Linear_Text, and Subpixel_Text .

Parameters

string character code points or Glyphs drawn
font text size, typeface, text scale, and so on, used to draw
encoding one of: kUTF8_SkTextEncoding, kUTF16_SkTextEncoding, kUTF32_SkTextEncoding, kGlyphID_SkTextEncoding

Return Value

Text_Blob constructed from one run

Example

See Also

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.

Parameters

procs custom serial data encoders; may be nullptr
memory storage for data
memory_size size of storage

Return Value

bytes written, or zero if required storage is larger than memory_size

Example

See Also

Deserialize SkSerialProcs


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.

Parameters

procs custom serial data encoders; may be nullptr

Return Value

storage containing serialized SkTextBlob

Example

See Also

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.

Parameters

data pointer for serial data
size size of data
procs custom serial data decoders; may be nullptr

Return Value

SkTextBlob constructed from data in memory

Example

Text "Hacker" replaces "World!", but does not update its metrics. When drawn, "Hacker" uses the spacing computed for "World!".

See Also

serialize SkDeserialProcs