text_path
Mojo function 🡭
text_path
fn def text_path(x: Float64, y: Float64, text: String, size: Float64, family: String = "Sans", slant: FontSlant = FontSlant.NORMAL, weight: FontWeight = FontWeight.NORMAL, rotation: Float64 = 0, align: TextAlign = TextAlign.LEFT, kerning: Bool = True, ligatures: Bool = True, *, mut cache: FontCache) -> PathThe outline of text as one Path: every glyph’s contours, laid out exactly as draw_text lays them out (shaping, kerning, line breaking, alignment and rotation about the (x, y) anchor), in canvas coordinates. Cairo’s text_path. Fill it under FillRule.NONZERO, which is how a TrueType outline’s contours are wound, or stroke it; a backend with no text of its own (PdfCanvas) draws text through it. Color glyphs (emoji) have no outline and contribute nothing.
Args:
- x (
Float64): Anchor x – baseline left end for LEFT alignment. - y (
Float64): Anchor y – baseline. - text (
String): Text to outline, “\n”-separated lines. - size (
Float64): Font size in points. - family (
String): Font family name or generic alias. - slant (
FontSlant): Requested upright/italic/oblique style. - weight (
FontWeight): Requested normal/bold weight. - rotation (
Float64): Radians, rotating the whole block around the anchor. - align (
TextAlign): Horizontal alignment of each line. - kerning (
Bool): Apply the font’s pair kerning between adjacent glyphs. - ligatures (
Bool): Apply the font’sGSUBshaping. - cache (
FontCache): Shared cache for font resolution and parsed faces.
Returns:
Path: The outline, empty for empty text or text with no ink.
Raises:
Error: No font could be resolved for family.