TextBlob

class TextBlob

TextBlob 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.

Example:

textblob = skia.TextBlob('text', skia.Font())
for run in textblob:
    print(run.fGlyphIndices)

Classes

Iter

Iterator for Run.

Methods

Deserialize

Recreates TextBlob that was serialized into data.

MakeFromPosText

Returns a textblob built from a single run of text with x-positions and a single y value.

MakeFromPosTextH

Returns a textblob built from a single run of text with x-positions and a single y value.

MakeFromRSXform

MakeFromShapedText

Creates TextBlob in a single run, with shaping, for a text-run direction.

MakeFromString

Creates TextBlob with a single run.

MakeFromText

Creates TextBlob with a single run.

__init__

Creates TextBlob with a single run.

bounds

Returns conservative bounding box.

deref

getIntercepts

Returns the number of intervals that intersect bounds.

ref

refCntGreaterThan

serialize

Returns storage containing Data describing TextBlob, using optional custom encoders.

unique

uniqueID

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

unref

Methods

static TextBlob.Deserialize(data: Buffer) skia.TextBlob

Recreates TextBlob that was serialized into data.

Returns constructed TextBlob if successful; otherwise, returns nullptr. Fails if size is smaller than required data length, or if data does not permit constructing valid TextBlob.

procs.fTypefaceProc permits supplying a custom function to decode Typeface. 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 Typeface data, data byte length, and user context.

Parameters:

data (Union[bytes,bytearray,memoryview]) – serial data

Returns:

TextBlob constructed from data in memory

static TextBlob.MakeFromPosText(text: str, pos: list[skia.Point], font: skia.Font, encoding: skia.TextEncoding = skia.TextEncoding.kUTF8) skia.TextBlob

Returns a textblob built from a single run of text with x-positions and a single y value.

This is equivalent to using TextBlobBuilder and calling TextBlobBuilder.allocRunPosH().

Parameters:
  • text (str) – character code points or glyphs drawn (based on encoding)

  • pos (List[skia.Point]) – array of positions, must contain values for all of the character points.

  • font (skia.Font) – Font used for this run

  • encoding (skia.TextEncoding) – specifies the encoding of the text array.

Returns:

new textblob or nullptr

static TextBlob.MakeFromPosTextH(text: str, xpos: Iterable, constY: float, font: skia.Font, encoding: skia.TextEncoding = skia.TextEncoding.kUTF8) skia.TextBlob

Returns a textblob built from a single run of text with x-positions and a single y value.

This is equivalent to using TextBlobBuilder and calling TextBlobBuilder.allocRunPosH().

Parameters:
  • text (str) – character code points or glyphs drawn (based on encoding)

  • xpos (List[float]) – array of x-positions, must contain values for all of the character points.

  • constY (float) – shared y-position for each character point, to be paired with each xpos.

  • font (skia.Font) – Font used for this run

  • encoding (skia.TextEncoding) – specifies the encoding of the text array.

Returns:

new textblob or nullptr

static TextBlob.MakeFromRSXform(text: str, xform: list[skia.RSXform], font: skia.Font, encoding: skia.TextEncoding = skia.TextEncoding.kUTF8) skia.TextBlob
static TextBlob.MakeFromShapedText(utf8text: str, font: skia.Font, leftToRight: bool = True) skia.TextBlob

Creates TextBlob in a single run, with shaping, for a text-run direction.

Parameters:
  • utf8text (str) – character code points drawn

  • font (skia.Font) – text size, typeface, text scale, and so on, used to draw

  • bool (leftToRight) – text-run direction

Returns:

TextBlob constructed from one run

static TextBlob.MakeFromString(string: str, font: skia.Font, encoding: skia.TextEncoding = skia.TextEncoding.kUTF8) skia.TextBlob

Creates TextBlob with a single run.

string meaning depends on TextEncoding; by default, string is encoded as UTF-8.

font contains attributes used to define the run text.

When encoding is TextEncoding.kUTF8, TextEncoding.kUTF16, or TextEncoding.kUTF32, this function uses the default character-to-glyph mapping from the Typeface in font. It does not perform typeface fallback for characters not found in the Typeface. It does not perform kerning or other complex shaping; glyphs are positioned based on their default advances.

Parameters:
  • string (str) – character code points or glyphs drawn

  • font (skia.Font) – text size, typeface, text scale, and so on, used to draw

  • encoding (skia.TextEncoding) – text encoding used in the text array

Returns:

TextBlob constructed from one run

static TextBlob.MakeFromText(text: str, font: skia.Font, encoding: skia.TextEncoding = skia.TextEncoding.kUTF8) skia.TextBlob

Creates TextBlob with a single run.

font contains attributes used to define the run text.

When encoding is TextEncoding.kUTF8, TextEncoding.kUTF16, or TextEncoding.kUTF32, this function uses the default character-to-glyph mapping from the Typeface in font. It does not perform typeface fallback for characters not found in the Typeface. It does not perform kerning or other complex shaping; glyphs are positioned based on their default advances.

Parameters:
  • text (str) – character code points or glyphs drawn

  • font (skia.Font) – text size, typeface, text scale, and so on, used to draw

  • encoding (skia.TextEncoding) – text encoding used in the text array

Returns:

TextBlob constructed from one run

TextBlob.__init__(self: skia.TextBlob, text: str, font: skia.Font, positions: object = None, encoding: skia.TextEncoding = skia.TextEncoding.kUTF8) None

Creates TextBlob with a single run.

font contains attributes used to define the run text.

This function uses the default character-to-glyph mapping from the Typeface in font. It does not perform typeface fallback for characters not found in the Typeface. It does not perform kerning or other complex shaping; glyphs are positioned based on their default advances.

Parameters:
  • text (str) – character code points or glyphs drawn

  • font (skia.Font) – text size, typeface, text scale, and so on, used to draw

  • positions (List[skia.Point]) – array of positions, must contain values for all of the character points.

  • encoding (skia.TextEncoding) – text encoding used in the text array

TextBlob.bounds(self: skia.TextBlob) skia.Rect

Returns conservative bounding box.

Uses Paint 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.

Returns:

conservative bounding box

TextBlob.deref(self: skia.TextBlob) None
TextBlob.getIntercepts(self: skia.TextBlob, bounds: Iterable, paint: skia.Paint = None) list[float]

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 RSXform are ignored when computing intercepts.

Parameters:
  • bounds (List[skia.Scalar]) – lower and upper line parallel to the advance

  • paint (skia.Paint) – specifies stroking, PathEffect that affects the result; may be nullptr

Returns:

intersections; may be empty

TextBlob.ref(self: skia.TextBlob) None
TextBlob.refCntGreaterThan(self: skia.TextBlob, count: int) bool
TextBlob.serialize(self: skia.TextBlob) skia.Data

Returns storage containing Data describing TextBlob, using optional custom encoders.

procs.fTypefaceProc permits supplying a custom function to encode Typeface. 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 Typeface and user context.

Returns:

storage containing serialized TextBlob

TextBlob.unique(self: skia.TextBlob) bool
TextBlob.uniqueID(self: skia.TextBlob) int

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

Returns:

identifier for TextBlob

TextBlob.unref(self: skia.TextBlob) None