Font
- class Font
Font
controls options applied when drawing and measuring text.Classes
Whether edge pixels draw opaque or with partial transparency.
Methods
Overloaded function.
Returns number of glyphs represented by text.
Dumps fields of the font to SkDebugf.
Retrieves the bounds for each glyph in glyphs.
Whether edge pixels draw opaque or with partial transparency.
Returns level of glyph outline adjustment.
Returns
FontMetrics
associated withTypeface
.Modifies path to be the outline of the glyph.
Returns path corresponding to glyph array.
Retrieves the positions for each glyph, beginning at the specified origin.
Returns text scale on x-axis.
Returns text size in points.
Returns text skew on x-axis.
Returns the recommended spacing between lines: the sum of metrics descent, ascent, and leading.
Returns
Typeface
if set, or nullptr.Retrieves the advance and bounds for each glyph in glyphs.
Retrieves the advance and bounds for each glyph in glyphs.
Retrieves the x-positions for each glyph, beginning at the specified origin.
Returns true if baselines will be snapped to pixel positions when the current transformation matrix is axis aligned.
Returns true if font engine may return glyphs from font bitmaps instead of from outlines.
Returns true if bold is approximated by increasing the stroke width when creating glyph bitmaps from outlines.
If true, instructs the font manager to always hint glyphs.
Returns true if font and glyph metrics are requested to be linearly scalable.
Returns true if glyphs may be drawn at sub-pixel offsets.
Returns a font with the same attributes of this font, but with the specified size.
Returns the advance width of text.
Requests that baselines be snapped to pixels when the current transformation matrix is axis aligned.
Requests, but does not require, that edge pixels draw opaque or with partial transparency.
Requests, but does not require, to use bitmaps in fonts instead of outlines.
Increases stroke width when creating glyph bitmaps to approximate a bold typeface.
Sets whether to always hint glyphs.
Sets level of glyph outline adjustment.
Requests, but does not require, linearly scalable font and glyph metrics.
Sets text scale on x-axis.
Sets text size in points.
Sets text skew on x-axis.
Requests, but does not require, that glyphs respect sub-pixel positioning.
Sets
Typeface
to typeface, decreasingRefCnt
of the previousTypeface
.Converts text into glyph indices.
Returns glyph index for Unicode character.
Attributes
Methods
- Font.__init__(*args, **kwargs)
Overloaded function.
__init__(self: skia.Font) -> None
Constructs
Font
with default values.__init__(self: skia.Font, typeface: object, size: float) -> None
__init__(self: skia.Font, typeface: object) -> None
__init__(self: skia.Font, typeface: object, size: float, scaleX: float, skewX: float) -> None
Constructs
Font
with default values withTypeface
and size in points, horizontal scale, and horizontal skew.Horizontal scale emulates condensed and expanded fonts. Horizontal skew emulates oblique fonts.
- typeface:
font and style used to draw and measure text
- size:
typographic height of text
- scaleX:
text horizontal scale
- skewX:
additional shear on x-axis relative to y-axis
- Font.countText(self: skia.Font, text: str, encoding: skia.TextEncoding = skia.TextEncoding.kUTF8) int
Returns number of glyphs represented by text.
If encoding is
TextEncoding.kUTF8
,TextEncoding.kUTF16
, orTextEncoding.kUTF32
; then each Unicode codepoint is mapped to a single glyph.- Parameters:
text (str) – character storage encoded with
TextEncoding
encoding (skia.TextEncoding) – text encoding
- Font.dump(self: skia.Font) None
Dumps fields of the font to SkDebugf.
May change its output over time, so clients should not rely on this for anything specific. Used to aid in debugging.
- Font.getBounds(self: skia.Font, glyphs: list[int], paint: SkPaint = None) list[skia.Rect]
Retrieves the bounds for each glyph in glyphs.
If paint is not nullptr, its stroking,
PathEffect
, andMaskFilter
fields are respected.- Parameters:
glyphs (List[int]) – array of glyph indices to be measured
paint (skia.Paint) – optional, specifies stroking,
PathEffect
, andMaskFilter
- Returns:
bounds for each glyph relative to (0, 0)
- Return type:
List[skia.Rect]
- Font.getEdging(self: skia.Font) skia.Font.Edging
Whether edge pixels draw opaque or with partial transparency.
- Font.getHinting(self: skia.Font) skia.FontHinting
Returns level of glyph outline adjustment.
- Font.getMetrics(self: skia.Font) SkFontMetrics
Returns
FontMetrics
associated withTypeface
.Results are scaled by text size but does not take into account dimensions required by text scale, text skew, fake bold, style stroke, and
PathEffect
.- Return type:
- Font.getPath(self: skia.Font, glyphID: int) object
Modifies path to be the outline of the glyph.
If the glyph has an outline, modifies path to be the glyph’s outline and returns true. The glyph outline may be empty. Degenerate contours in the glyph outline will be skipped. If glyph is described by a bitmap, returns false and ignores path parameter.
- Parameters:
glyphID (int) – index of glyph
- Returns:
true if glyphID is described by path
- Font.getPaths(self: skia.Font, glyphIDs: list[int]) object
Returns path corresponding to glyph array.
- Parameters:
glyphIDs – array of glyph indices
- Returns:
list of
Path
- Font.getPos(self: skia.Font, glyphs: list[int], origin: skia.Point = skia.Point(0, 0)) list[skia.Point]
Retrieves the positions for each glyph, beginning at the specified origin.
- Parameters:
glyphs (List[int]) – array of glyph indices to be positioned
origin (skia.Point) – location of the first glyph. Defaults to (0, 0).
- Returns:
glyphs positions
- Font.getScaleX(self: skia.Font) float
Returns text scale on x-axis.
Default value is 1.
- Returns:
text horizontal scale
- Font.getSize(self: skia.Font) float
Returns text size in points.
- Returns:
typographic height of text
- Font.getSkewX(self: skia.Font) float
Returns text skew on x-axis.
Default value is zero.
- Returns:
additional shear on x-axis relative to y-axis
- Font.getSpacing(self: skia.Font) float
Returns the recommended spacing between lines: the sum of metrics descent, ascent, and leading.
Result is scaled by text size but does not take into account dimensions required by stroking and
PathEffect
. Returns the same result asgetMetrics()
.- Returns:
recommended spacing between lines
- Font.getTypeface(self: skia.Font) skia.Typeface
Returns
Typeface
if set, or nullptr.- Returns:
Typeface
if previously set, nullptr otherwise
- Font.getWidths(self: skia.Font, glyphs: list[int]) list[float]
Retrieves the advance and bounds for each glyph in glyphs.
- Parameters:
glyphs (List[int]) – array of glyph indices to be measured
- Return type:
List[float]
- Font.getWidthsBounds(self: skia.Font, glyphs: list[int], paint: SkPaint = None) tuple
Retrieves the advance and bounds for each glyph in glyphs.
- Parameters:
glyphs (List[int]) – array of glyph indices to be measured
paint (skia.Paint) – optional, specifies stroking,
PathEffect
andMaskFilter
- Returns:
Widths and bounds array
- Return type:
Tuple[List[float],List[skia.Rect]]
- Font.getXPos(self: skia.Font, glyphs: list[int], origin: float = 0) list[float]
Retrieves the x-positions for each glyph, beginning at the specified origin.
- Parameters:
glyphs (List[int]) – array of glyph indices to be positioned
origin (skia.Point) – location of the first glyph. Defaults to 0.
- Returns:
glyphs x-positions
- Font.isBaselineSnap(self: skia.Font) bool
Returns true if baselines will be snapped to pixel positions when the current transformation matrix is axis aligned.
- Returns:
baselines may be snapped to pixels
- Font.isEmbeddedBitmaps(self: skia.Font) bool
Returns true if font engine may return glyphs from font bitmaps instead of from outlines.
- Returns:
true if glyphs may be font bitmaps
- Font.isEmbolden(self: skia.Font) bool
Returns true if bold is approximated by increasing the stroke width when creating glyph bitmaps from outlines.
- Returns:
bold is approximated through stroke width
- Font.isForceAutoHinting(self: skia.Font) bool
If true, instructs the font manager to always hint glyphs.
Returned value is only meaningful if platform uses FreeType as the font manager.
- Returns:
true if all glyphs are hinted
- Font.isLinearMetrics(self: skia.Font) bool
Returns true if font and glyph metrics are requested to be linearly scalable.
- Returns:
true if font and glyph metrics are requested to be linearly scalable.
- Font.isSubpixel(self: skia.Font) bool
Returns true if glyphs may be drawn at sub-pixel offsets.
- Returns:
true if glyphs may be drawn at sub-pixel offsets.
- Font.makeWithSize(self: skia.Font, size: float) skia.Font
Returns a font with the same attributes of this font, but with the specified size.
Returns nullptr if size is less than zero, infinite, or NaN.
- Parameters:
size (float) – typographic height of text
- Font.measureText(self: skia.Font, text: str, encoding: skia.TextEncoding = skia.TextEncoding.kUTF8, bounds: skia.Rect = None, paint: SkPaint = None) float
Returns the advance width of text.
The advance is the normal distance to move before drawing additional text. Returns the bounding box of text if bounds is not nullptr. paint stroke width or
PathEffect
may modify the advance with.- Parameters:
text (str) – character storage encoded with
TextEncoding
encoding (skia.TextEncoding) – text encoding
bounds (skia.Rect) – returns bounding box relative to (0, 0) if not nullptr
paint (skia.Paint) – optional; may be nullptr
- Returns:
the advance width of text
- Font.refTypeface(self: skia.Font) skia.Typeface
Increases
Typeface
RefCnt
by one.- Returns:
Typeface
if previously set, nullptr otherwise
- Font.setBaselineSnap(self: skia.Font, baselineSnap: bool) None
Requests that baselines be snapped to pixels when the current transformation matrix is axis aligned.
- Parameters:
baselineSnap (bool) – setting for baseline snapping to pixels
- Font.setEdging(self: skia.Font, edging: skia.Font.Edging) None
Requests, but does not require, that edge pixels draw opaque or with partial transparency.
- Font.setEmbeddedBitmaps(self: skia.Font, embeddedBitmaps: bool) None
Requests, but does not require, to use bitmaps in fonts instead of outlines.
:param bool embeddedBitmaps setting to use bitmaps in fonts
- Font.setEmbolden(self: skia.Font, embolden: bool) None
Increases stroke width when creating glyph bitmaps to approximate a bold typeface.
- Parameters:
embolden (bool) – setting for bold approximation
- Font.setForceAutoHinting(self: skia.Font, forceAutoHinting: bool) None
Sets whether to always hint glyphs.
If forceAutoHinting is set, instructs the font manager to always hint glyphs.
Only affects platforms that use FreeType as the font manager.
- Parameters:
forceAutoHinting (bool) – setting to always hint glyphs
- Font.setHinting(self: skia.Font, hintingLevel: skia.FontHinting) None
Sets level of glyph outline adjustment.
Does not check for valid values of hintingLevel.
- Font.setLinearMetrics(self: skia.Font, linearMetrics: bool) None
Requests, but does not require, linearly scalable font and glyph metrics.
For outline fonts ‘true’ means font and glyph metrics should ignore hinting and rounding. Note that some bitmap formats may not be able to scale linearly and will ignore this flag.
- Parameters:
linearMetrics (bool) – setting for linearly scalable font and glyph metrics.
- Font.setScaleX(self: skia.Font, scaleX: float) None
Sets text scale on x-axis.
Default value is 1.
- Parameters:
scaleX (float) – text horizontal scale
- Font.setSize(self: skia.Font, textSize: float) None
Sets text size in points.
Has no effect if textSize is not greater than or equal to zero.
- Parameters:
textSize (float) – typographic height of text
- Font.setSkewX(self: skia.Font, skewX: float) None
Sets text skew on x-axis.
Default value is zero.
- Parameters:
skewX (float) – additional shear on x-axis relative to y-axis
- Font.setSubpixel(self: skia.Font, subpixel: bool) None
Requests, but does not require, that glyphs respect sub-pixel positioning.
- Parameters:
subpixel (bool) – setting for sub-pixel positioning
- Font.setTypeface(self: skia.Font, typeface: skia.Typeface) None
Sets
Typeface
to typeface, decreasingRefCnt
of the previousTypeface
.Pass nullptr to clear
Typeface
and use the default typeface. Increments tfRefCnt
by one.- Parameters:
typeface – font and style used to draw text
- Font.textToGlyphs(self: skia.Font, text: str, encoding: skia.TextEncoding = skia.TextEncoding.kUTF8) list[int]
Converts text into glyph indices.
Returns the number of glyph indices represented by text.
TextEncoding
specifies how text represents characters or glyphs.Does not check text for valid character codes or valid glyph indices.
If encoding is
TextEncoding.kUTF8
and text contains an invalid UTF-8 sequence, empty array is returned.When encoding is
TextEncoding.kUTF8
,TextEncoding.kUTF16
, orTextEncoding.kUTF32
; then each Unicode codepoint is mapped to a single glyph. This function uses the default character-to-glyph mapping from theTypeface
and maps characters not found in theTypeface
to zero.- Parameters:
text (str) – character storage encoded with
TextEncoding
encoding (skia.TextEncoding) – text encoding
- Returns:
glyphs represented by text
Attributes
- Font.kAlias = <Edging.kAlias: 0>
- Font.kAntiAlias = <Edging.kAntiAlias: 1>
- Font.kSubpixelAntiAlias = <Edging.kSubpixelAntiAlias: 2>