TextBlob
- class TextBlob
TextBlobcombines multiple text runs into an immutable container.Each text run consists of glyphs,
Paint, and position. Only parts ofPaintrelated to fonts and text rendering are used by run.Example:
textblob = skia.TextBlob('text', skia.Font()) for run in textblob: print(run.fGlyphIndices)
Classes
Iterator for
Run.Methods
Deserialize(data: Buffer) -> skia.TextBlob
MakeFromPosText(text: str, pos: list[skia.Point], font: skia.Font, encoding: skia.TextEncoding = skia.TextEncoding.kUTF8) -> skia.TextBlob
MakeFromPosTextH(text: str, xpos: Iterable, constY: float, font: skia.Font, encoding: skia.TextEncoding = skia.TextEncoding.kUTF8) -> skia.TextBlob
MakeFromRSXform(text: str, xform: list[skia.RSXform], font: skia.Font, encoding: skia.TextEncoding = skia.TextEncoding.kUTF8) -> skia.TextBlob
MakeFromShapedText(utf8text: str, font: skia.Font, leftToRight: bool = True) -> skia.TextBlob
MakeFromString(string: str, font: skia.Font, encoding: skia.TextEncoding = skia.TextEncoding.kUTF8) -> skia.TextBlob
MakeFromText(text: str, font: skia.Font, encoding: skia.TextEncoding = skia.TextEncoding.kUTF8) -> skia.TextBlob
__init__(self: skia.TextBlob, text: str, font: skia.Font, positions: object = None, encoding: skia.TextEncoding = skia.TextEncoding.kUTF8) -> None
bounds(self: skia.TextBlob) -> skia.Rect
deref(self: skia.TextBlob) -> None
getIntercepts(self: skia.TextBlob, bounds: Iterable, paint: skia.Paint = None) -> list[float]
ref(self: skia.TextBlob) -> None
refCntGreaterThan(self: skia.TextBlob, count: int) -> bool
serialize(self: skia.TextBlob) -> skia.Data
unique(self: skia.TextBlob) -> bool
uniqueID(self: skia.TextBlob) -> int
unref(self: skia.TextBlob) -> None
Methods
- static TextBlob.Deserialize(data: Buffer) skia.TextBlob
Recreates
TextBlobthat was serialized into data.Returns constructed
TextBlobif successful; otherwise, returns nullptr. Fails if size is smaller than required data length, or if data does not permit constructing validTextBlob.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 toTypefacedata, data byte length, and user context.- Parameters:
data (Union[bytes,bytearray,memoryview]) – serial data
- Returns:
TextBlobconstructed 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
TextBlobBuilderand callingTextBlobBuilder.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.
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
TextBlobBuilderand callingTextBlobBuilder.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.
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
TextBlobin a single run, with shaping, for a text-run direction.
- static TextBlob.MakeFromString(string: str, font: skia.Font, encoding: skia.TextEncoding = skia.TextEncoding.kUTF8) skia.TextBlob
Creates
TextBlobwith 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, orTextEncoding.kUTF32, this function uses the default character-to-glyph mapping from theTypefacein font. It does not perform typeface fallback for characters not found in theTypeface. 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:
TextBlobconstructed from one run
- static TextBlob.MakeFromText(text: str, font: skia.Font, encoding: skia.TextEncoding = skia.TextEncoding.kUTF8) skia.TextBlob
Creates
TextBlobwith a single run.font contains attributes used to define the run text.
When encoding is
TextEncoding.kUTF8,TextEncoding.kUTF16, orTextEncoding.kUTF32, this function uses the default character-to-glyph mapping from theTypefacein font. It does not perform typeface fallback for characters not found in theTypeface. 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:
TextBlobconstructed from one run
- TextBlob.__init__(self: skia.TextBlob, text: str, font: skia.Font, positions: object = None, encoding: skia.TextEncoding = skia.TextEncoding.kUTF8) None
Creates
TextBlobwith a single run.font contains attributes used to define the run text.
This function uses the default character-to-glyph mapping from the
Typefacein font. It does not perform typeface fallback for characters not found in theTypeface. 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
Paintassociated 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
RSXformare ignored when computing intercepts.- Parameters:
bounds (List[skia.Scalar]) – lower and upper line parallel to the advance
paint (skia.Paint) – specifies stroking,
PathEffectthat 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
DatadescribingTextBlob, 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 toTypefaceand 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