Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@

# OS Font paths
try:
_HOME = Path.home()
_HOME = Path(os.devnull)
except Exception: # Exceptions thrown by home() are not specified...
_HOME = Path(os.devnull) # Just an arbitrary path with no children.
MSFolders = \
Expand Down Expand Up @@ -1038,16 +1038,22 @@ def __init__(self, size=None, weight='normal'):
'Matplotlib is building the font cache; this may take a moment.'))
timer.start()
try:
for fontext in ["afm", "ttf"]:
for path in [*findSystemFonts(paths, fontext=fontext),
*findSystemFonts(fontext=fontext)]:
try:
self.addfont(path)
except OSError as exc:
_log.info("Failed to open font file %s: %s", path, exc)
except Exception as exc:
_log.info("Failed to extract font properties from %s: "
"%s", path, exc)
# Optimize: use set to avoid duplicate font paths,
# and combine all paths for both extensions in one go.
font_files = set()
for fontext in ("afm", "ttf"):
font_files.update(findSystemFonts(paths, fontext=fontext))
font_files.update(findSystemFonts(fontext=fontext))

# Now iterate just once over all found files.
for path in font_files:
try:
self.addfont(path)
except OSError as exc:
_log.info("Failed to open font file %s: %s", path, exc)
except Exception as exc:
_log.info("Failed to extract font properties from %s: "
"%s", path, exc)
finally:
timer.cancel()

Expand Down