Enhance | use os.walk in font loading
This commit is contained in:
parent
385c072881
commit
f5ff410951
@ -119,19 +119,18 @@ def pyglet_load_fonts_folder(folder) -> None:
|
||||
if not font_path.exists():
|
||||
font_path.mkdir(parents=True)
|
||||
return None
|
||||
file_folder_list = os.listdir(folder)
|
||||
for obj in file_folder_list:
|
||||
if os.path.isfile(os.path.join(folder, obj)):
|
||||
if obj[-4:] == '.ttf' or obj[-4:] == '.otf':
|
||||
logger.debug(f'loading font {os.path.join(folder, obj)}')
|
||||
logger.info(f'loading font folder {font_path}')
|
||||
for dir_path, dir_names, file_names in os.walk(font_path):
|
||||
dir_path = Path(dir_path)
|
||||
for file_name in file_names:
|
||||
file_name = Path(file_name)
|
||||
if file_name.suffix in ('.ttf', '.otf'):
|
||||
logger.debug(f'loading font {dir_path / file_name}')
|
||||
try:
|
||||
pyglet.font.add_file(os.path.join(folder, obj))
|
||||
pyglet.font.add_file(str(dir_path / file_name))
|
||||
except Exception:
|
||||
logger.error(traceback.format_exc())
|
||||
logger.error(f'loading font {os.path.join(folder, obj)} failed')
|
||||
else:
|
||||
logger.info(f'loading font folder {os.path.join(folder, obj)}')
|
||||
pyglet_load_fonts_folder(os.path.join(folder, obj))
|
||||
logger.error(f'loading font {str(dir_path / file_name)} failed')
|
||||
|
||||
|
||||
def _call_back(call_back: Callable) -> Callable:
|
||||
|
Loading…
Reference in New Issue
Block a user