Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c546627

Browse filesBrowse files
committed
Improve font weight guessing.
Previously, we would guess that "Times New Roman Bold" is a regular weight font because its name contains the substring "Roman", even though the font correctly sets the BOLD flag (FT_STYLE_FLAG_BOLD). Invert the logic to give priority to the flag, as its presence is clearly more robust than a substring check. `s.find(w) >= 0` is just an obfuscated way to write `w in s`, so change that.
1 parent 1c06de3 commit c546627
Copy full SHA for c546627

File tree

Expand file treeCollapse file tree

2 files changed

+10
-6
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-6
lines changed
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Changes in font weight guessing
2+
```````````````````````````````
3+
4+
Font weight guessing now first checks for the presence of the FT_STYLE_BOLD_FLAG
5+
before trying to match substrings in the font name. In particular, this means
6+
that Times New Roman Bold is now correctly detected as bold, not normal weight.

‎lib/matplotlib/font_manager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/font_manager.py
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,10 @@ def ttfFontProperty(font):
395395
else:
396396
variant = 'normal'
397397

398-
weight = next((w for w in weight_dict if sfnt4.find(w) >= 0), None)
399-
if not weight:
400-
if font.style_flags & ft2font.BOLD:
401-
weight = 700
402-
else:
403-
weight = 400
398+
if font.style_flags & ft2font.BOLD:
399+
weight = 700
400+
else:
401+
weight = next((w for w in weight_dict if w in sfnt4), 400)
404402

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.