8000 Improve font weight guesser · matplotlib/matplotlib@0789e75 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0789e75

Browse files
Rufflewindtacaswell
authored andcommitted
Improve font weight guesser
1 parent 765fd78 commit 0789e75

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/matplotlib/font_manager.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ def ttfFontProperty(font):
411411
*font* is a :class:`FT2Font` instance.
412412
"""
413413
name = font.family_name
414+
style_name = font.style_name.lower().strip()
414415

415416
# Styles are: italic, oblique, and normal (default)
416417

@@ -455,10 +456,14 @@ def ttfFontProperty(font):
455456
reverse=True)
456457
weight = next((w for w in sorted_weights if sfnt4.find(w) >= 0), None)
457458
if not weight:
458-
if font.style_flags & ft2font.BOLD:
459-
weight = 700
460-
else:
459+
weight = next((w for w in weight_dict if style_name.find(w) >= 0), None)
460+
if weight:
461+
pass
462+
elif style_name in ["italic", "oblique", "condensed"]:
461463
weight = 400
464+
else:
465+
# give up rather than risk making mistakes (reason: #8550)
466+
raise KeyError("unknown weight: {!r}".format(font.family_name))
462467

463468
# Stretch can be absolute and relative
464469
# Absolute stretches are: ultra-condensed, extra-condensed, condensed,

0 commit comments

Comments
 (0)
0