Skip to content

Improve font weight guessing. #14483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2019
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions doc/api/next_api_changes/2019-06-09-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Changes in font weight guessing
```````````````````````````````

Font weight guessing now first checks for the presence of the FT_STYLE_BOLD_FLAG
before trying to match substrings in the font name. In particular, this means
that Times New Roman Bold is now correctly detected as bold, not normal weight.
10 changes: 4 additions & 6 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,10 @@ def ttfFontProperty(font):
else:
variant = 'normal'

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 = 400
if font.style_flags & ft2font.BOLD:
weight = 700
else:
weight = next((w for w in weight_dict if w in sfnt4), 400)

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