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
17 changes: 12 additions & 5 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 @@ -1039,8 +1039,12 @@ def __init__(self, size=None, weight='normal'):
timer.start()
try:
for fontext in ["afm", "ttf"]:
for path in [*findSystemFonts(paths, fontext=fontext),
*findSystemFonts(fontext=fontext)]:
found_fonts = set()
# collect fonts from explicit paths first
found_fonts.update(findSystemFonts(paths, fontext=fontext))
# collect system-wide fonts (avoiding duplicates)
found_fonts.update(findSystemFonts(fontext=fontext))
for path in found_fonts:
try:
self.addfont(path)
except OSError as exc:
Expand Down Expand Up @@ -1108,9 +1112,12 @@ def set_default_weight(self, weight):

@staticmethod
def _expand_aliases(family):
if family in ('sans', 'sans serif'):
# Optimization: localize frequently used values
rcParams = mpl.rcParams
if family == 'sans' or family == 'sans serif':
# Avoid creating a tuple and using the in operator, since there are only two values
family = 'sans-serif'
return mpl.rcParams['font.' + family]
return rcParams['font.' + family]

# Each of the scoring functions below should return a value between
# 0.0 (perfect match) and 1.0 (terrible match)
Expand Down