Initial project baseline

This commit is contained in:
2026-07-04 02:40:45 +08:00
commit d5d8caef2f
86 changed files with 15590 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
from matplotlib.font_manager import FontProperties
from PIL import ImageFont
from . import config
_global_font_cache = {}
_font_properties_cache = {}
def get_cached_font(font_path, size):
key = (font_path, size)
if key not in _global_font_cache:
try:
_global_font_cache[key] = ImageFont.truetype(font_path, size)
except IOError as e:
config._warn(f"字体加载失败,回退默认字体: path={font_path}, size={size}, error={e}")
_global_font_cache[key] = ImageFont.load_default()
return _global_font_cache[key]
def get_font_properties(font_path, size):
key = (font_path, size)
if key not in _font_properties_cache:
_font_properties_cache[key] = FontProperties(fname=font_path, size=size)
return _font_properties_cache[key]