GlyphCache

Two-level cache for glyph SVG paths.

Level 1: In-memory LRU cache (fast, per-session) Level 2: Disk cache in ~/.cache/svan2d/fonts/ (persistent) Cache files are named by font file hash, so cache invalidates automatically when the font file changes.

Methods

clear_disk_cache

clear_disk_cache(font_path: Optional[str] = None) -> None

Clear disk cache.

Parameters

font_path
If provided, clear only this font's cache. If None, clear all cached fonts.

clear_memory_cache

clear_memory_cache()

Clear the in-memory cache (disk cache remains).

get_glyph

get_glyph(
    font_path: str,
    char: str,
    font: Optional[object] = None
) -> CachedGlyph

Get glyph SVG path, using cache if available.

Parameters

font_path
Path to the font file
char
Single character to get
font
Optional pre-loaded TTFont object (for performance)

Returns

CachedGlyph with path and advance_width

preload_characters

preload_characters(font_path: str, characters: str) -> None

Preload a set of characters into cache.

Parameters

font_path
Path to the font file
characters
String of characters to preload