Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
dstansby merged 1 commit intomatplotlib:mainfromQuLogic:font-weight-warning
Jul 15, 2025

Conversation

QuLogic
Copy link
Member

PR summary

This is a rebase of the orphaned#15615, but with@anntzer's comments handled.

PR checklist

@@ -19,6 +18,7 @@ MSUserFontDirectories: list[str]
X11FontDirectories:list[str]
OSXFontDirectories:list[str]

def_normalize_weight(weight:str|Number)->Number: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Typical font weights are multiples of 100. Can / should this be any Number or can we specialize to int?

Suggested change
def_normalize_weight(weight:str|Number)->Number: ...
def_normalize_weight(weight:str|int)->int: ...

If we want a general Number, there should be a test case for it.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looking at the OpenType spec, it does appear to be integral only:https://learn.microsoft.com/en-us/typography/opentype/spec/os2#usweightclass

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Also, I think the original PR just usedNumber because it was already imported infont_manager.py.

Comment on lines 413 to 415
def test_map_weights():
assert _normalize_weight('ultralight') == 100
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Let's reframe this to test the helper instead of the mapping, so that we can also test the passthrough behavior

Suggested change
deftest_map_weights():
assert_normalize_weight('ultralight')==100
deftest_normalize_weight():
assert_normalize_weight(300)==300# passthough
assert_normalize_weight('ultralight')==100

Maybe also add an error case e.g. "italic"

Comment on lines 1487 to 1489
if best_font is not None:
if (_normalize_weight(prop.get_weight()) !=
_normalize_weight(best_font.weight)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why are these nested ifs instead ofif A and B ?

@QuLogicQuLogic added this to thev3.11.0 milestoneJul 10, 2025
Copy link
Member

@dstansbydstansby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

One minor suggestion to improve the changelog - take it or leave it, and feel free to self merge.

Comment on lines +1 to +2
``font_manager.findfont`` logs if selected font weight does not match requested
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
``font_manager.findfont``logs if selected font weight does not match requested
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``font_manager.findfont``warns if selected the font weight does not match requested
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copy link
MemberAuthor

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.

dstansby reacted with thumbs up emoji
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
Copy link
Member

Choose a reason for hiding this comment

The 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 apytest.warns context?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Same reason as above.

dstansby reacted with thumbs up emoji
@dstansbydstansby merged commitd2050cb intomatplotlib:mainJul 15, 2025
44 checks passed
@QuLogicQuLogic deleted the font-weight-warning branchJuly 15, 2025 10:53
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@timhoffmtimhoffmtimhoffm approved these changes

@dstansbydstansbydstansby approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.11.0
Development

Successfully merging this pull request may close these issues.

Chinese font can`t change the weight
3 participants
@QuLogic@timhoffm@dstansby

[8]ページ先頭

©2009-2025 Movatter.jp