Skip to content
Closed
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
17 changes: 14 additions & 3 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,25 @@
'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,
'demibold' : 600,
'demi' : 600,
'bold' : 700,
'heavy' : 800,
'extrabold' : 800,
'extra bold' : 800,
'ultrabold' : 800,
'black' : 900}

font_family_aliases = {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down