-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Improve font weight guessing #8551
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
Conversation
I do not think we can change the mapping between string as integer weights as we take both as input. I am mostly 👎 on no longer picking up fonts that we used to pick up (even if the weights are a bit off). #7931 is likely related, but does not fully fix this problem? |
I tested it using HEAD (a9a8634) with Fira Sans and each run I seem to get a random choice of:
Tested using: # while rm -fr ~/.cache/matplotlib && python foo.py; do :; done
import matplotlib
matplotlib.use("Agg")
matplotlib.rcParams["font.sans-serif"] = "Fira Sans"
matplotlib.rcParams["font.weight"] = "regular"
import matplotlib.pyplot as plt
print(matplotlib.font_manager.findfont("Fira Sans"))
plt.plot([1, 2], [3, 4])
plt.savefig("foo.png") |
OK I've restored them and pushed "Thin" down to 50 instead of 100.
Perhaps we could deprioritize them and mark their weights as “uncertain”. They should still get picked up as if their weight is Regular, but if a “definitely” Regular font is found, then it takes precedence. |
@Rufflewind I could not reproduce your results. |
I re-reproduced my results on a clean Arch container:
|
@Rufflewind Thank you for re-reproducing the results.
Ref: #8587 |
'powercycled' PR to re-trigger CI |
xref #5574 |
I made three modification in #8607. In my opinion, the first and third are not improving, but bug fix. |
Superseded by #16203; thanks for the pr. |
PR Summary
Bandaid-ish fix for #8550. Would like some feedback on whether these are good/bad ideas.
Add more font weights
and change some existing ones to better fit Mozzila's developer wiki:Added:
10050)200100)Changed:ultralight from 100 to 200light from 200 to 300roman from 500 to 400heavy from 800 to 900Improve the font-weight guessing logic. In particular, rather than trusting
style_flags
(which is very limited and inexpressive), the code now inspectsstyle_name
for keywords. Some limited testing this on the fonts of my system indicates that most sensible cases are covered. Otherwise, just bail withKeyError
so that the font won’t get registered (mitigates Matplotlib chooses the wrong font for unrecognized weights #8550).The few fonts where the new logic fails have really exotic subfamilies like “Retina” or “Four Italic”, which don’t really map well to the existing font system anyway so I don’t think it’s much of a loss. We could still check for
style_flags & BOLD
, but testing revealed only one font where this mattered (Latin Modern Sans Quotation
, which is actually not bold despite the bold flag being set!).PR Checklist