register_font_dir ¶
register_font_dir(path: str | PathLike[str]) -> list[str]
Register every font file under a directory, searched recursively.
Files ending in .ttf, .otf, .ttc or .otc (any case) are
registered in sorted path order with their own family names, as
register_font does. Files that are not usable fonts are skipped with a
GgrustWarning each.
Parameters:
-
path(str or PathLike) –The directory, for example an unpacked font family.
Returns:
-
list of str–The family names registered, each once, in order.
Raises:
-
FontNotFoundError–If the directory does not exist or holds no font files.
-
FontError–If
pathis not a directory or none of its font files is usable.
Examples:
>>> from ggrust import register_font_dir
>>> from ggrust.errors import FontNotFoundError
>>> register_font_dir("fonts/Source Serif")
['Source Serif 4']
>>> try:
... register_font_dir("missing/fonts")
... except FontNotFoundError:
... print("no such directory")
no such directory