-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,10 @@ | |
'extra bold': 800, | ||
'black': 900, | ||
} | ||
|
||
def map_weight_name_to_score(weight): | ||
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. this should be private 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. When you say private, I think of other language access modifiers. In Python would that be just making this a class method? 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 prepend an underscore to its name. |
||
return weight if isinstance(weight, Number) else weight_dict[weight] | ||
|
||
font_family_aliases = { | ||
'serif', | ||
'sans-serif', | ||
|
@@ -1147,8 +1151,8 @@ def score_weight(self, weight1, weight2): | |
# exact match of the weight names, e.g. weight1 == weight2 == "regular" | ||
if cbook._str_equal(weight1, weight2): | ||
return 0.0 | ||
w1 = weight1 if isinstance(weight1, Number) else weight_dict[weight1] | ||
w2 = weight2 if isinstance(weight2, Number) else weight_dict[weight2] | ||
w1 = map_weight_name_to_score(weight1) | ||
w2 = map_weight_name_to_score(weight2) | ||
return 0.95 * (abs(w1 - w2) / 1000) + 0.05 | ||
|
||
def score_size(self, size1, size2): | ||
|
@@ -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()) | ||
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. pep8 is pretty unhappy about the formatting here. 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. Thanks! This should be better. |
||
- map_weight_name_to_score(best_font.weight)) > 100: | ||
_log.warning('findfont: Failed to find font weight %s, ' | ||
8000 + 'now using %s.', prop.get_weight(), best_font.weight) | ||
|
||
if best_font is None or best_score >= 10.0: | ||
if fallback_to_default: | ||
|
Uh oh!
There was an error while loading. Please reload this page.