S or /

SourceClass Font

from skia import Font
class Font:

Font controls options applied when drawing and measuring text.

Properties§

@property def baseline_snap(self, /) -> bool§
Source@baseline_snap.setter def baseline_snap(self, /, value: bool) -> None§

Requests that baselines be snapped to pixels when the current transformation matrix is axis aligned.

  • baseline_snap setting for baseline snapping to pixels
@property def embedded_bitmaps(self, /) -> bool§
Source@embedded_bitmaps.setter def embedded_bitmaps(self, /, value: bool) -> None§

Requests, but does not require, to use bitmaps in fonts instead of outlines.

  • embedded_bitmaps setting to use bitmaps in fonts
@property def embolden(self, /) -> bool§
Source@embolden.setter def embolden(self, /, value: bool) -> None§

Increases stroke width when creating glyph bitmaps to approximate a bold typeface.

  • embolden setting for bold approximation
@property def force_auto_hinting(self, /) -> bool§
Source@force_auto_hinting.setter def force_auto_hinting(self, /, value: bool) -> None§

Sets whether to always hint glyphs. If force_auto_hinting is set, instructs the font manager to always hint glyphs.

Only affects platforms that use FreeType as the font manager.

  • force_auto_hinting setting to always hint glyphs
@property def linear_metrics(self, /) -> bool§
Source@linear_metrics.setter def linear_metrics(self, /, value: 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.

  • linear_metrics setting for linearly scalable font and glyph metrics.
Source@property def scale_x(self, /) -> float§

Returns text scale on x-axis. Default value is 1.

Returns text horizontal scale.

Source@scale_x.setter def scale_x(self, /, value: float) -> None§

Sets text scale on x-axis. Default value is 1.

  • scale_x text horizontal scale
Source@property def size(self, /) -> float§

Return EM size in local coordinate units. See https://skia.org/docs/user/coordinates/#local-coordinates .

Returns EM size in local coordinate units.

Source@size.setter def size(self, /, value: float) -> None§

Sets the EM size in local coordinate units. See https://skia.org/docs/user/coordinates/#local-coordinates . Has no effect if size is not greater than or equal to zero.

  • size EM size in local coordinate units
Source@property def skew_x(self, /) -> float§

Returns text skew on x-axis. Default value is zero.

Returns additional shear on x-axis relative to y-axis.

Source@skew_x.setter def skew_x(self, /, value: float) -> None§

Sets text skew on x-axis. Default value is zero.

  • skew_x additional shear on x-axis relative to y-axis
@property def subpixel(self, /) -> bool§
Source@subpixel.setter def subpixel(self, /, value: bool) -> None§

Requests, but does not require, that glyphs respect sub-pixel positioning.

  • subpixel setting for sub-pixel positioning
Source@property def typeface(self, /) -> Typeface§

Does not alter Typeface SkRefCnt.

Returns non-null Typeface.

Source@typeface.setter def typeface(self, /, typeface: Any) -> None§

Sets Typeface to tf, decreasing SkRefCnt of the previous Typeface. Pass None to clear Typeface and use an empty typeface (which draws nothing). Increments tf SkRefCnt by one.

  • tf font and style used to draw text

Methods§

def break_text(self, /, text: str, max_width: float, *, paint: Paint |None = None) -> tuple[int, float]§
def clone(self, /) -> Font§
Source@classmethod def from_typeface(cls, /, typeface: Typeface, size: float) -> Font§

Constructs a font with default values with Typeface and size.

  • typeface font and style used to draw and measure text
  • size EM size in local coordinate units
def get_glyph_positions(self, /, glyphs: Sequence[int], origin: Any |None = None) -> list[Point2d]§
def get_glyphs(self, /, text: str) -> list[int]§
def get_line_height(self, /) -> float§
def get_metrics(self, /) -> tuple[float, FontMetrics]§
Sourcedef measure_text(self, /, text: str, paint: Paint |None = None) -> tuple[float, Rect]§

Returns the advance width of text. The advance is the normal distance to move before drawing additional text. Returns the bounding box of text relative to (0, 0). The paint stroke settings, mask filter, or path effect may modify the bounds.

Returns the sum of the default advance widths.

@classmethod def new_with_values(cls, /, typeface: Typeface, size: float, scale_x: float, skew_x: float) -> Font§