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

Font weight warning if found font sufficiently different#15615

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

Closed
colt-1 wants to merge6 commits intomatplotlib:masterfromcolt-1:master
Closed

Conversation

colt-1
Copy link

PR Summary

#15529

We check if the chosen font is +-100 from the desired user outcome. If so, we log a warning documenting the desired and the actual used.

Test is added to make sure new function for string mappings are correct.

PR Checklist

  • Has Pytest style unit tests
  • Code isFlake 8 compliant
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@@ -1275,6 +1279,12 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default,
best_font = font
if score == 0:
break

if best_font is not None:
if abs(map_weight_name_to_score(prop.get_weight())
Copy link
Member

Choose a reason for hiding this comment

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

pep8 is pretty unhappy about the formatting here.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks! This should be better.

@tacaswelltacaswell added this to thev3.3.0 milestoneNov 6, 2019
@tacaswell
Copy link
Member

Could you also add a test that warnings are actually raised when we miss a weight? We will always have dejavu installed so maybe one of the very high or low weights?

@tacaswell
Copy link
Member

Thanks @colathro ! It was great working with you today!

colt-1 reacted with hooray emoji

@anntzer
Copy link
Contributor

I think we should warn anytime there's no exact match, rather than with a threshold of 100.

@@ -86,6 +86,10 @@
'extra bold': 800,
'black': 900,
}

def map_weight_name_to_score(weight):
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be private

Copy link
Author

Choose a reason for hiding this comment

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

When you say private, I think of other language access modifiers. In Python would that be just making this a class method?

Copy link
Contributor

Choose a reason for hiding this comment

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

Just prepend an underscore to its name.

@colt-1
Copy link
Author

Could you also add a test that warnings are actually raised when we miss a weight? We will always have dejavu installed so maybe one of the very high or low weights?

I'm not quite able to figure out the best way to do this. I can't quite get the output to appear in the warnings no matter what I try. Is this due to the logger not actually implementing Warnings?

@zufuliu
Copy link

The font weight dict looks incomplete, tested some fonts on Win10:

fontweightweightremarks
Source Code ProExtraLight200missing
Segoe UILight300normal
Segoe UISemilight350missing
(Simplified Chinese) Microsoft YaHeiLight290CJK
(Simplified Chinese) Microsoft YaHei UILight290CJK
(Traditional Chinese) Microsoft JhengHeiLight290CJK
(Traditional Chinese) Microsoft JhengHei UILight290CJK

CJK fonts may not have same weight value compared to Latin fonts

@anntzer
Copy link
Contributor

anntzer commentedNov 14, 2019
edited
Loading

The CSS font weight names are mentioned inhttps://www.w3.org/TR/css-fonts-4/#font-weight-prophttps://developer.mozilla.org/en-US/docs/Web/CSS/font-weight#Common_weight_name_mapping so the intermediate values shouldnot be included, Windows likely just maps them to the closest name.

It actually looks like our weights name table is wrong... The full table in the CSS spec is

100 thin (aka hairline in MozDev)
200 extralight/ultralight (we currently map ultralight to 100)
300 light (we currently map light to 200)
400 normal (aka regular in MozDev, fontconfig, Windows)
500 medium
600 semibold/demibold
700 bold
800 extrabold/ultrabold
900 black/heavy (we currently map heavy to 800)

plus the vendor-specific ones

fontconfig (https://gitlab.freedesktop.org/fontconfig/fontconfig/blob/master/src/fcweight.c)
350 demilight
380 book (we currently map book to 400)
1000 extrablack

MozDev, and Windows (https://docs.microsoft.com/en-us/dotnet/api/system.windows.fontweights?view=netframework-4.8#remarks)
950 extrablack/ultrablack

@QuLogic
Copy link
Member

Are those font weight inconsistencies handled by#16203? Where would this PR stand after that one?

@anntzer
Copy link
Contributor

Users can still request e.g. Foobar Thin font and if that doesn't exist but Foobar Regular does then we will return that, and I think it still makes sense to warn in that case?

@tacaswell
Copy link
Member

I'm pushing this to 3.4 as there seems to be some discussion about when we should warn (on a non-perfect match or any miss-match).

@jklymakjklymak marked this pull request as draftSeptember 10, 2020 15:41
@QuLogicQuLogic modified the milestones:v3.4.0,v3.5.0Jan 21, 2021
@QuLogicQuLogic modified the milestones:v3.5.0,v3.6.0Aug 23, 2021
@tacaswelltacaswell deleted the branchmatplotlib:masterOctober 20, 2021 19:53
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell left review comments

@anntzeranntzeranntzer left review comments

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@colt-1@tacaswell@anntzer@zufuliu@QuLogic@story645

[8]ページ先頭

©2009-2025 Movatter.jp