Only scan font dirs recursively if the font is not found in any top level dir

This commit is contained in:
Kovid Goyal 2026-01-31 08:26:57 +05:30
parent ed85f177b6
commit 0a01f41996
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -923,17 +923,21 @@ def add_builtin_fonts(args: Options) -> None:
continue
font_file = ''
if is_macos:
for candidate in (os.path.expanduser('~/Library/Fonts'), '/Library/Fonts', '/System/Library/Fonts', '/Network/Library/Fonts'):
candidates = (
os.path.expanduser('~/Library/Fonts'), '/Library/Fonts', '/System/Library/Fonts', '/Network/Library/Fonts')
for candidate in candidates:
q = os.path.join(candidate, filename)
if os.path.exists(q):
font_file = q
break
for root, _, files in os.walk(candidate, onerror=lambda _: None):
if filename in files:
font_file = os.path.join(root, filename)
else:
for candidate in candidates:
for root, _, files in os.walk(candidate, onerror=lambda _: None):
if filename in files:
font_file = os.path.join(root, filename)
break
if font_file:
break
if font_file:
break
elif is_windows:
for candidate in (
os.path.expandvars(r'%userprofile%\AppData\Local\Microsoft\Windows\Fonts'),