Updated
On this page
Font loading and glyph extraction for text-to-paths conversion.
#predraw.fonts
#predraw.fonts
Font loading and glyph extraction for text-to-paths conversion.
Uses fonttools to read .ttf/.otf files and extract SVG path data for each glyph.
#_font_directories
python
def _font_directories() -> list[Path]Return platform-appropriate font search directories.
#find_font
python
def find_font(family: str, weight: int=400, project_dir: str | None=None) -> str | NoneFind a font file path for the given family and weight.
Searches font directories for .ttf/.otf files matching the family name and weight. Returns the path to the font file, or None if not found.
Search order:
- {project_dir}/fonts/ (if project_dir is provided and exists)
- System font directories
#get_glyph_paths
python
def get_glyph_paths(font_path: str, text: str, font_size: float, letter_spacing: float=0) -> list[dict]Extract SVG path data for each character in text.
Returns a list of dicts, one per character: {"char": "A", "d": "M10 20 L...", "advance": 33.12}
Each glyph's path data is scaled to the requested font_size and positioned at its correct horizontal offset. Font Y-axis is flipped for SVG.