Skip to content

Commit 8ba0972

Browse files
authored
Merge pull request #12472 from anntzer/defaultfont
Make FontManager.defaultFont a property, to avoid hardcoding the prefix.
2 parents 083fefe + eaf1641 commit 8ba0972

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/matplotlib/font_manager.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -964,19 +964,13 @@ def __init__(self, size=None, weight='normal'):
964964
self.defaultFamily = {
965965
'ttf': 'DejaVu Sans',
966966
'afm': 'Helvetica'}
967-
self.defaultFont = {}
968967

969968
ttffiles = findSystemFonts(paths) + findSystemFonts()
970-
self.defaultFont['ttf'] = next(
971-
(fname for fname in ttffiles
972-
if fname.lower().endswith("dejavusans.ttf")),
973-
ttffiles[0])
974969
self.ttflist = createFontList(ttffiles)
975970

976971
afmfiles = (findSystemFonts(paths, fontext='afm')
977972
+ findSystemFonts(fontext='afm'))
978973
self.afmlist = createFontList(afmfiles, fontext='afm')
979-
self.defaultFont['afm'] = afmfiles[0] if afmfiles else None
980974

981975
@cbook.deprecated("3.0")
982976
@property
@@ -988,6 +982,13 @@ def ttffiles(self):
988982
def afmfiles(self):
989983
return [font.fname for font in self.afmlist]
990984

985+
@property
986+
def defaultFont(self):
987+
# Lazily evaluated (findfont then caches the result) to avoid including
988+
# the venv path in the json serialization.
989+
return {ext: self.findfont(family, fontext=ext)
990+
for ext, family in self.defaultFamily.items()}
991+
991992
def get_default_weight(self):
992993
"""
993994
Return the default font weight.

0 commit comments

Comments
 (0)