Skip to content

Make FontManager.defaultFont a property, to avoid hardcoding the prefix. #12472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 2, 2019
Merged
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
15 changes: 8 additions & 7 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ class FontManager(object):
# Increment this version number whenever the font cache data
# format or behavior has changed and requires a existing font
# cache files to be rebuilt.
__version__ = 300
__version__ = 310

def __init__(self, size=None, weight='normal'):
self._version = self.__version__
Expand Down Expand Up @@ -975,19 +975,13 @@ def __init__(self, size=None, weight='normal'):
self.defaultFamily = {
'ttf': 'DejaVu Sans',
'afm': 'Helvetica'}
self.defaultFont = {}

ttffiles = findSystemFonts(paths) + findSystemFonts()
self.defaultFont['ttf'] = next(
(fname for fname in ttffiles
if fname.lower().endswith("dejavusans.ttf")),
ttffiles[0])
self.ttflist = createFontList(ttffiles)

afmfiles = (findSystemFonts(paths, fontext='afm')
+ findSystemFonts(fontext='afm'))
self.afmlist = createFontList(afmfiles, fontext='afm')
self.defaultFont['afm'] = afmfiles[0] if afmfiles else None

@cbook.deprecated("3.0")
@property
Expand All @@ -999,6 +993,13 @@ def ttffiles(self):
def afmfiles(self):
return [font.fname for font in self.afmlist]

@property
def defaultFont(self):
# Lazily evaluated (findfont then caches the result) to avoid including
# the venv path in the json serialization.
return {ext: self.findfont(family, fontext=ext)
for ext, family in self.defaultFamily.items()}

def get_default_weight(self):
"""
Return the default font weight.
Expand Down