Phase 2: Pure Rust Font Engine#
Improve font loading to enumerate available system fonts and support loading by family name, rather than hardcoding paths to Geneva/Monaco.
Font discovery#
- Scan
/System/Library/Fonts/and/Library/Fonts/directories - Read font files and extract name table metadata (family name, subfamily)
- Build a font registry mapping family names to file paths
- Support
.ttfand.otffile extensions - Handle font collections (
.ttcfiles) — parse the TTC header to extract individual font offsets
Font selection API#
FontRegistry::new() -> FontRegistry— scans system font directoriesFontRegistry::find_font(family: &str) -> Option<Font>— load by family nameFontRegistry::find_font_with_style(family: &str, bold: bool, italic: bool) -> Option<Font>— load with style preferenceFontRegistry::list_families() -> Vec<String>— list available font families
Fallback#
- Default fallback font if requested family not found
- Maintain a prioritized list: requested font -> system default -> any available font
Acceptance criteria#
- System font directories are scanned on initialization
- Fonts can be loaded by family name (e.g., "Helvetica", "Times New Roman")
- TTC collections are handled (extract individual fonts)
- Font registry lists available families
- Fallback works when requested font is not found
- All existing tests continue to pass
-
cargo clippy --workspace -- -D warningspasses -
cargo fmt --all --checkpasses