Skip to content

Commit f87f4be

Browse files
authored
Merge pull request #15963 from meeseeksmachine/auto-backport-of-pr-15937-on-v3.2.x
Backport PR #15937 on branch v3.2.x (Don't hide exceptions in FontManager.addfont.)
2 parents f725924 + 7ef342c commit f87f4be

File tree

1 file changed

+12
-29
lines changed

1 file changed

+12
-29
lines changed

lib/matplotlib/font_manager.py

+12-29
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,13 @@ def __init__(self, size=None, weight='normal'):
987987
for fontext in ["afm", "ttf"]:
988988
for path in [*findSystemFonts(paths, fontext=fontext),
989989
*findSystemFonts(fontext=fontext)]:
990-
self.addfont(path)
990+
try:
991+
self.addfont(path)
992+
except OSError as exc:
993+
_log.info("Failed to open font file %s: %s", path, exc)
994+
except Exception as exc:
995+
_log.info("Failed to extract font properties from %s: %s",
996+
path, exc)
991997

992998
def addfont(self, path):
993999
"""
@@ -999,36 +1005,13 @@ def addfont(self, path):
9991005
path : str or path-like
10001006
"""
10011007
if Path(path).suffix.lower() == ".afm":
1002-
try:
1003-
with open(path, "rb") as fh:
1004-
font = afm.AFM(fh)
1005-
except EnvironmentError:
1006-
_log.info("Could not open font file %s", path)
1007-
return
1008-
except RuntimeError:
1009-
_log.info("Could not parse font file %s", path)
1010-
return
1011-
try:
1012-
prop = afmFontProperty(path, font)
1013-
except KeyError as exc:
1014-
_log.info("Could not extract properties for %s: %s", path, exc)
1015-
return
1008+
with open(path, "rb") as fh:
1009+
font = afm.AFM(fh)
1010+
prop = afmFontProperty(path, font)
10161011
self.afmlist.append(prop)
10171012
else:
1018-
try:
1019-
font = ft2font.FT2Font(path)
1020-
except (OSError, RuntimeError) as exc:
1021-
_log.info("Could not open font file %s: %s", path, exc)
1022-
return
1023-
except UnicodeError:
1024-
_log.info("Cannot handle unicode filenames")
1025-
return
1026-
try:
1027-
prop = ttfFontProperty(font)
1028-
except (KeyError, RuntimeError, ValueError,
1029-
NotImplementedError) as exc:
1030-
_log.info("Could not extract properties for %s: %s", path, exc)
1031-
return
1013+
font = ft2font.FT2Font(path)
1014+
prop = ttfFontProperty(font)
10321015
self.ttflist.append(prop)
10331016

10341017
@property

0 commit comments

Comments
 (0)