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
13 changes: 12 additions & 1 deletion lib/matplotlib/font_manager.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
weight_dict = {
'ultralight' : 100,
'light' : 200,
'thin' : 200,
'demilight' : 300,
'normal' : 400,
'regular' : 400,
'book' : 400,
Expand Down Expand Up @@ -407,13 +409,20 @@ def ttfFontProperty(font):

sfnt = font.get_sfnt()
sfnt2 = sfnt.get((1,0,0,2))
sfnt2_3 = sfnt.get((3,1,1033,2))
sfnt4 = sfnt.get((1,0,0,4))
sfnt4_3 = sfnt.get((3,1,1033,4))
if sfnt2:
sfnt2 = sfnt2.decode('macroman').lower()
elif sfnt2_3:
sfnt2 = sfnt2_3.decode('utf_16_be').lower()
else:
sfnt2 = ''

if sfnt4:
sfnt4 = sfnt4.decode('macroman').lower()
elif sfnt4_3:
sfnt4 = sfnt4_3.decode('utf_16_be').lower()
else:
sfnt4 = ''
if sfnt4.find('oblique') >= 0:
Expand All @@ -435,7 +444,9 @@ def ttfFontProperty(font):
else:
variant = 'normal'

weight = next((w for w in weight_dict if sfnt4.find(w) >= 0), None)
sorted_weights = sorted(weight_dict.keys(), key=lambda k: len(k),
reverse=True)
weight = next((w for w in sorted_weights if sfnt4.find(w) >= 0), None)
if not weight:
if font.style_flags & ft2font.BOLD:
weight = 700
Expand Down