[font] cleanly handle font file format exception (Bugfix) (#7970)

This commit is contained in:
Clyde Stubbs 2024-12-17 12:07:43 +11:00 committed by GitHub
parent 663e18310d
commit 9f6c64afa6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -51,8 +51,11 @@ CONF_IGNORE_MISSING_GLYPHS = "ignore_missing_glyphs"
# Cache loaded freetype fonts
class FontCache(dict):
def __missing__(self, key):
try:
res = self[key] = freetype.Face(key)
return res
except freetype.FT_Exception as e:
raise cv.Invalid(f"Could not load Font file {key}: {e}") from e
FONT_CACHE = FontCache()