-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Log a warning if selected font weight differs from requested #30272
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
+46
−9
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
``font_manager.findfont`` logs if selected font weight does not match requested | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,8 @@ | |
from matplotlib.font_manager import ( | ||
findfont, findSystemFonts, FontEntry, FontProperties, fontManager, | ||
json_dump, json_load, get_font, is_opentype_cff_font, | ||
MSUserFontDirectories, _get_fontconfig_fonts, ttfFontProperty) | ||
MSUserFontDirectories, ttfFontProperty, | ||
_get_fontconfig_fonts, _normalize_weight) | ||
from matplotlib import cbook, ft2font, pyplot as plt, rc_context, figure as mfigure | ||
from matplotlib.testing import subprocess_run_helper, subprocess_run_for_testing | ||
|
||
|
@@ -407,3 +408,29 @@ def test_fontproperties_init_deprecation(): | |
# Since this case is not covered by docs, I've refrained from jumping | ||
# extra hoops to detect this possible API misuse. | ||
FontProperties(family="serif-24:style=oblique:weight=bold") | ||
|
||
|
||
def test_normalize_weights(): | ||
assert _normalize_weight(300) == 300 # passthrough | ||
assert _normalize_weight('ultralight') == 100 | ||
assert _normalize_weight('light') == 200 | ||
assert _normalize_weight('normal') == 400 | ||
assert _normalize_weight('regular') == 400 | ||
assert _normalize_weight('book') == 400 | ||
assert _normalize_weight('medium') == 500 | ||
assert _normalize_weight('roman') == 500 | ||
assert _normalize_weight('semibold') == 600 | ||
assert _normalize_weight('demibold') == 600 | ||
assert _normalize_weight('demi') == 600 | ||
assert _normalize_weight('bold') == 700 | ||
assert _normalize_weight('heavy') == 800 | ||
assert _normalize_weight('extra bold') == 800 | ||
assert _normalize_weight('black') == 900 | ||
with pytest.raises(KeyError): | ||
_normalize_weight('invalid') | ||
|
||
|
||
def test_font_match_warning(caplog): | ||
findfont(FontProperties(family=["DejaVu Sans"], weight=750)) | ||
logs = [rec.message for rec in caplog.records] | ||
assert 'findfont: Failed to find font weight 750, now using 700.' in logs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for my own interest, is there a reason to check the logs, instead of using a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same reason as above. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's not a warning.