skia2/site/user/api/SkTextBlobBuilder_Reference.md
Cary Clark 09d80c0337 docs with more pop
Replace a hunk of documentation in docs/*.bmh
with #Populate, which instructs bookmaker to
retrieve the documentation from include/core.

Check spelling for all documentation retrieved
from include/core against Skia declarations
and a list of words in spelling.txt.

TBR=caryclark@google.com
Docs-Preview: https://skia.org/?cl=163491
Bug: skia:
Change-Id: If057c3a1336e312ad59c084a3a130f0276802496
Reviewed-on: https://skia-review.googlesource.com/c/163491
Commit-Queue: Cary Clark <caryclark@skia.org>
Reviewed-by: Cary Clark <caryclark@skia.org>
Auto-Submit: Cary Clark <caryclark@skia.org>
2018-10-31 16:45:32 +00:00

34 KiB

SkTextBlobBuilder Reference


class SkTextBlobBuilder {
public:
    SkTextBlobBuilder();
    ~SkTextBlobBuilder();
    sk_sp<SkTextBlob> make();

    struct RunBuffer {
        SkGlyphID* glyphs;
        SkScalar* pos;
        char* utf8text;
        uint32_t* clusters;
    };

    const RunBuffer& allocRun(const SkPaint& font, int count, SkScalar x, SkScalar y,
                              const SkRect* bounds = nullptr);
    const RunBuffer& allocRunPosH(const SkPaint& font, int count, SkScalar y,
                                  const SkRect* bounds = nullptr);
    const RunBuffer& allocRunPos(const SkPaint& font, int count,
                                 const SkRect* bounds = nullptr);
    const RunBuffer& allocRun(const SkFont& font, int count, SkScalar x, SkScalar y,
                              const SkRect* bounds = nullptr);
    const RunBuffer& allocRunPosH(const SkFont& font, int count, SkScalar y,
                                  const SkRect* bounds = nullptr);
    const RunBuffer& allocRunPos(const SkFont& font, int count,
                                 const SkRect* bounds = nullptr);
};

Helper class for constructing SkTextBlob.


    struct RunBuffer {
        SkGlyphID* glyphs;
        SkScalar* pos;
        char* utf8text;
        uint32_t* clusters;
    };

RunBuffer supplies storage for Glyphs and positions within a run.

A run is a sequence of Glyphs sharing Paint Font Metrics and positioning. Each run may position its Glyphs in one of three ways: by specifying where the first Glyph is drawn, and allowing Paint Font Metrics to determine the advance to subsequent Glyphs; by specifying a baseline, and the position on that baseline for each Glyph in run; or by providing Point array, one per Glyph.

Type Member Description
SkGlyphID* glyphs glyphs points to memory for one or more Glyphs. glyphs memory must be written to by the caller.
SkScalar* pos pos points to memory for Glyph positions. Depending on how RunBuffer is allocated, pos may point to zero bytes per Glyph, one Scalar per Glyph, or one Point per Glyph.
char* utf8text Reserved for future use. utf8text should not be read or written.
uint32_t* clusters Reserved for future use. clusters should not be read or written.

See Also

allocRun[2] allocRunPos[2] allocRunPosH[2]


SkTextBlobBuilder()

Constructs empty SkTextBlobBuilder. By default, SkTextBlobBuilder has no runs.

Return Value

empty SkTextBlobBuilder

Example

Example Output

blob equals nullptr

See Also

make SkTextBlob::MakeFromText


~SkTextBlobBuilder()

Deletes data allocated internally by SkTextBlobBuilder.

See Also

SkTextBlobBuilder()


sk sp<SkTextBlob> make()

Returns SkTextBlob built from runs of glyphs added by builder. Returned SkTextBlob is immutable; it may be copied, but its contents may not be altered. Returns nullptr if no runs of glyphs were added by builder.

Resets SkTextBlobBuilder to its initial empty state, allowing it to be reused to build a new set of runs.

Return Value

SkTextBlob or nullptr

Example

Example Output

blob equals nullptr
blob does not equal nullptr
blob equals nullptr

See Also

SkTextBlob::MakeFromText


const RunBuffer& allocRun(const SkPaint& font, int count, SkScalar x, SkScalar y,
                          const SkRect* bounds = nullptr)

Returns run with storage for Glyphs. Caller must write count Glyphs to RunBuffer.glyphs before next call to FontBlobBuilder.

RunBuffer.utf8text, and RunBuffer.clusters should be ignored.

Glyphs share Paint Font Metrics in font, including: Typeface, Paint Text Size, Paint Text Scale X, Paint Text Skew X, Paint Text Align, Paint Hinting, Anti Alias, Paint Fake Bold, Font Embedded Bitmaps, Full Hinting Spacing, LCD Text, Linear Text, and Subpixel Text.

Glyphs are positioned on a baseline at (x, y), using font Paint Font Metrics to determine their relative placement.

bounds defines an optional bounding box, used to suppress drawing when Text Blob bounds does not intersect Surface bounds. If bounds is nullptr, Text Blob bounds is computed from (x, y) and RunBuffer.glyphs Paint Font Metrics.

Parameters

font Paint used for this run
count number of glyphs
x horizontal offset within the blob
y vertical offset within the blob
bounds optional run bounding box

Return Value

writable glyph buffer

Example

See Also

allocRunPosH[2] allocRunPos[2]


const RunBuffer& allocRun(const SkFont& font, int count, SkScalar x, SkScalar y,
                          const SkRect* bounds = nullptr)

Returns run with storage for Glyphs. Caller must write count Glyphs to RunBuffer.glyphs before next call to FontBlobBuilder.

RunBuffer.utf8text, and RunBuffer.clusters should be ignored.

Glyphs share Paint Font Metrics in font, including: Typeface, Paint Text Size, Paint Text Scale X, Paint Text Skew X, Paint Text Align, Paint Hinting, Anti Alias, Paint Fake Bold, Font Embedded Bitmaps, Full Hinting Spacing, LCD Text, Linear Text, and Subpixel Text.

Glyphs are positioned on a baseline at (x, y), using font Paint Font Metrics to determine their relative placement.

bounds defines an optional bounding box, used to suppress drawing when Text Blob bounds does not intersect Surface bounds. If bounds is nullptr, Text Blob bounds is computed from (x, y) and RunBuffer.glyphs Paint Font Metrics.

Parameters

font Font used for this run
count number of glyphs
x horizontal offset within the blob
y vertical offset within the blob
bounds optional run bounding box

Return Value

writable glyph buffer

Example

See Also

allocRunPosH[2] allocRunPos[2]


const RunBuffer& allocRunPosH(const SkPaint& font, int count, SkScalar y,
                              const SkRect* bounds = nullptr)

Returns run with storage for Glyphs and positions along baseline. Caller must write count Glyphs to RunBuffer.glyphs, and count Scalars to RunBuffer.pos; before next call to FontBlobBuilder.

RunBuffer.utf8text, and RunBuffer.clusters should be ignored.

Glyphs share Paint Font Metrics in font, including: Typeface, Paint Text Size, Paint Text Scale X, Paint Text Skew X, Paint Text Align, Paint Hinting, Anti Alias, Paint Fake Bold, Font Embedded Bitmaps, Full Hinting Spacing, LCD Text, Linear Text, and Subpixel Text.

Glyphs are positioned on a baseline at y, using x-axis positions written by caller to RunBuffer.pos.

bounds defines an optional bounding box, used to suppress drawing when Text Blob bounds does not intersect Surface bounds. If bounds is nullptr, Text Blob bounds is computed from y, RunBuffer.pos, and RunBuffer.glyphs Paint Font Metrics.

Parameters

font Paint used for this run
count number of Glyphs
y vertical offset within the blob
bounds optional run bounding box

Return Value

writable glyph buffer and x-axis position buffer

Example

See Also

allocRunPos[2] allocRun[2]


const RunBuffer& allocRunPosH(const SkFont& font, int count, SkScalar y,
                              const SkRect* bounds = nullptr)

Returns run with storage for Glyphs and positions along baseline. Caller must write count Glyphs to RunBuffer.glyphs, and count Scalars to RunBuffer.pos; before next call to FontBlobBuilder.

RunBuffer.utf8text, and RunBuffer.clusters should be ignored.

Glyphs share Paint Font Metrics in font, including: Typeface, Paint Text Size, Paint Text Scale X, Paint Text Skew X, Paint Text Align, Paint Hinting, Anti Alias, Paint Fake Bold, Font Embedded Bitmaps, Full Hinting Spacing, LCD Text, Linear Text, and Subpixel Text.

Glyphs are positioned on a baseline at y, using x-axis positions written by caller to RunBuffer.pos.

bounds defines an optional bounding box, used to suppress drawing when Text Blob bounds does not intersect Surface bounds. If bounds is nullptr, Text Blob bounds is computed from y, RunBuffer.pos, and RunBuffer.glyphs Paint Font Metrics.

Parameters

font Font used for this run
count number of Glyphs
y vertical offset within the blob
bounds optional run bounding box

Return Value

writable glyph buffer and x-axis position buffer

Example

See Also

allocRunPos[2] allocRun[2]


const RunBuffer& allocRunPos(const SkPaint& font, int count, const SkRect* bounds = nullptr)

Returns run with storage for Glyphs and Point positions. Caller must write count Glyphs to RunBuffer.glyphs, and count Points to RunBuffer.pos; before next call to FontBlobBuilder.

RunBuffer.utf8text, and RunBuffer.clusters should be ignored.

Glyphs share Paint Font Metrics in font, including: Typeface, Paint Text Size, Paint Text Scale X, Paint Text Skew X, Paint Text Align, Paint Hinting, Anti Alias, Paint Fake Bold, Font Embedded Bitmaps, Full Hinting Spacing, LCD Text, Linear Text, and Subpixel Text.

Glyphs are positioned using Points written by caller to RunBuffer.pos, using two Scalar values for each Point.

bounds defines an optional bounding box, used to suppress drawing when Text Blob bounds does not intersect Surface bounds. If bounds is nullptr, Text Blob bounds is computed from RunBuffer.pos, and RunBuffer.glyphs Paint Font Metrics.

Parameters

font Paint used for this run
count number of Glyphs
bounds optional run bounding box

Return Value

writable glyph buffer and Point buffer

Example

See Also

allocRunPosH[2] allocRun[2]


const RunBuffer& allocRunPos(const SkFont& font, int count, const SkRect* bounds = nullptr)

Returns run with storage for Glyphs and Point positions. Caller must write count Glyphs to RunBuffer.glyphs, and count Points to RunBuffer.pos; before next call to FontBlobBuilder.

RunBuffer.utf8text, and RunBuffer.clusters should be ignored.

Glyphs share Paint Font Metrics in font, including: Typeface, Paint Text Size, Paint Text Scale X, Paint Text Skew X, Paint Text Align, Paint Hinting, Anti Alias, Paint Fake Bold, Font Embedded Bitmaps, Full Hinting Spacing, LCD Text, Linear Text, and Subpixel Text.

Glyphs are positioned using Points written by caller to RunBuffer.pos, using two Scalar values for each Point.

bounds defines an optional bounding box, used to suppress drawing when Text Blob bounds does not intersect Surface bounds. If bounds is nullptr, Text Blob bounds is computed from RunBuffer.pos, and RunBuffer.glyphs Paint Font Metrics.

Parameters

font Font used for this run
count number of Glyphs
bounds optional run bounding box

Return Value

writable glyph buffer and Point buffer

Example

See Also

allocRunPosH[2] allocRun[2]