FontGlyphs

Load a font and extract glyph vertices for morphing.

Constructor

FontGlyphs(font_path: str)

Load a font file.

Parameters

font_path
Path to TTF or OTF font file

Methods

close

close()

Close the font file.

get_advance_width

get_advance_width(char: str) -> float

Get the advance width for a character in font units.

get_letters

get_letters(
    text: str,
    num_vertices: int | None = None,
    height: float | None = None,
    scale: float | None = None,
    letter_spacing: float = 1.0,
    pos: Point2D | None = None,
    fill_color: Color | None = None,
    stroke_color: Color | None = None,
    stroke_width: float = 0.0
) -> list[StateCollectionState]

Get individually-animatable letter states with shared baseline alignment.

Parameters

text
String to convert
num_vertices
Vertex count per contour
height
Desired letter height in scene units (preferred over scale)
scale
Direct scale factor (use height instead for intuitive sizing)
letter_spacing
Multiplier for space between letters (1.0 = normal)
pos
Center position of the whole word (default: origin)
fill_color
Fill color
stroke_color
Stroke color
stroke_width
Stroke width

Returns

List of StateCollectionState, one per non-space character. Spaces affect layout but are not included in the output.

get_state

get_state(
    char: str,
    num_vertices: int | None = None,
    height: float | None = None,
    scale: float | None = None,
    pos: Point2D | None = None,
    fill_color: Color | None = None,
    stroke_color: Color | None = None,
    stroke_width: float = 0.0,
    _center: bool = True,
    _cursor_x: float = 0.0
) -> StateCollectionState

Get a StateCollectionState for a single character.

Parameters

char
Single character to extract
num_vertices
Vertex count per contour
height
Desired height in scene units (preferred over scale)
scale
Direct scale factor (use height instead for intuitive sizing)
pos
Position offset (default: origin) - applied during rendering
fill_color
Fill color (default: white)
stroke_color
Stroke color (default: none)
stroke_width
Stroke width (default: 0)
_center
Internal - if True center at origin, if False for text layout
_cursor_x
Internal - cursor X position for text layout

Returns

StateCollectionState containing one GlyphState per disconnected component

get_word

get_word(
    text: str,
    num_vertices: int | None = None,
    height: float | None = None,
    scale: float | None = None,
    letter_spacing: float = 1.0,
    pos: Point2D | None = None,
    fill_color: Color | None = None,
    stroke_color: Color | None = None,
    stroke_width: float = 0.0
) -> StateCollectionState

Get a StateCollectionState for a word.

Parameters

text
String to convert
num_vertices
Vertex count per contour
height
Desired letter height in scene units (preferred over scale)
scale
Direct scale factor (use height instead for intuitive sizing)
letter_spacing
Multiplier for space between letters (1.0 = normal, 0.5 = tight)
pos
Center position (default: origin)
fill_color
Fill color
stroke_color
Stroke color
stroke_width
Stroke width

Returns

StateCollectionState containing all glyph states