diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index df954b691c58..239549e98657 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -93,11 +93,15 @@ 'ultra-expanded' : 900} weight_dict = { + 'hair' : 50, + 'thin' : 50, + 'extralight' : 100, 'ultralight' : 100, 'light' : 200, 'normal' : 400, 'regular' : 400, 'book' : 400, + 'plain' : 400, 'medium' : 500, 'roman' : 500, 'semibold' : 600, @@ -105,7 +109,9 @@ 'demi' : 600, 'bold' : 700, 'heavy' : 800, + 'extrabold' : 800, 'extra bold' : 800, + 'ultrabold' : 800, 'black' : 900} font_family_aliases = { @@ -402,6 +408,7 @@ def ttfFontProperty(font): *font* is a :class:`FT2Font` instance. """ name = font.family_name + style_name = font.style_name.lower().strip() # Styles are: italic, oblique, and normal (default) @@ -437,10 +444,14 @@ def ttfFontProperty(font): weight = next((w for w in weight_dict if sfnt4.find(w) >= 0), None) if not weight: - if font.style_flags & ft2font.BOLD: - weight = 700 - else: + weight = next((w for w in weight_dict if style_name.find(w) >= 0), None) + if weight: + pass + elif style_name in ["italic", "oblique", "condensed"]: weight = 400 + else: + # give up rather than risk making mistakes (reason: #8550) + raise KeyError("unknown weight: {!r}".format(font.family_name)) # Stretch can be absolute and relative # Absolute stretches are: ultra-condensed, extra-condensed, condensed,