Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 158cf33

Browse files
committed
Merge pull request #1604 from dmcdougall/fix_badfonts
Make font_manager ignore KeyErrors for bad fonts
2 parents 07fa831 + f6e086b commit 158cf33

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/matplotlib/font_manager.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,10 @@ def createFontList(fontfiles, fontext='ttf'):
565565
except RuntimeError:
566566
verbose.report("Could not parse font file %s"%fpath)
567567
continue
568-
prop = afmFontProperty(fpath, font)
568+
try:
569+
prop = afmFontProperty(fpath, font)
570+
except KeyError:
571+
continue
569572
else:
570573
try:
571574
font = ft2font.FT2Font(str(fpath))
@@ -576,7 +579,10 @@ def createFontList(fontfiles, fontext='ttf'):
576579
verbose.report("Cannot handle unicode filenames")
577580
#print >> sys.stderr, 'Bad file is', fpath
578581
continue
579-
prop = ttfFontProperty(font)
582+
try:
583+
prop = ttfFontProperty(font)
584+
except KeyError:
585+
continue
580586

581587
fontlist.append(prop)
582588
return fontlist

0 commit comments

Comments
 (0)