Skip to content

Commit

Permalink
fix: skip error when font load failed
Browse files Browse the repository at this point in the history
  • Loading branch information
NCBM committed Jul 10, 2024
1 parent 098925f commit a99fdb9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion fontra.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

import os
import sys
import warnings
from pathlib import Path
from traceback import print_exc
from typing import cast

import freetype
import freetype.ft_errors
from typing_extensions import NamedTuple, TypeAlias

FontFamilyName: TypeAlias = str
Expand Down Expand Up @@ -159,7 +162,15 @@ def update_fontrefs_index():
_indexed_fontrefs.clear()
_indexed_langnames.clear()
for fn in (*_indexed_fontfiles_system, *_indexed_fontfiles_custom):
face = _ft_open_face(fn)
try:
face = _ft_open_face(fn)
except freetype.ft_errors.FT_Exception:
warnings.warn(
f"Some error occurred when loading font {str(fn)!r}, "
"skipped.\n"
)
print_exc()
continue
_update_fontref_index(fn, face)
for i in range(1, face.num_faces):
face = _ft_open_face(fn, i)
Expand Down

0 comments on commit a99fdb9

Please sign in to comment.