-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Apply hinting factor rcParam in all cases. #9481
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
This is only explicitly used in Agg, so any other users get the default in the C++ code. Thus if you modify this setting and use some other backend, you get very weird behaviour. Positioning sometimes breaks and glyphs are shrunk or cropped.
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.
conditional on CI
Hmm, something might still be cached somewhere as changing the hinting factor in the middle of a script causes all text to be the wrong width. for hinting_factor in map(int, sys.argv[1:]):
plt.rcParams['text.hinting_factor'] = hinting_factor
fig, ax = plt.subplots()
ax.text(0.5, 0.5, 'text')
plt.show() Opens figures with progressively smaller text (or wider depending on what you specify), but it's fine if you specify anything other than 8 in a separate run. As an example of something this PR does fix, if you add a |
@QuLogic but I guess that caching was already present before, in which case this PR does not really make things worse, does it? |
@anntzer True, it just makes it more difficult to write a test. |
Static initializers are only applied the first time, so any subsequent calls with alternate hinting_factor would use the first value. FreeType copies the matrix values into an internal structure, so these do not really need to be static.
I think that should fix the caching issue, and it even fixes the SVG+Agg save from above, without the first change. I guess the first change can still go in for consistency. But thinking about it, SVG and PDF render text externally, so it may be better to have those use |
Ah, the static was tricky... |
test failures look real though |
b61fbd7
to
df5558c
Compare
df5558c
to
6a685d2
Compare
Not sure why I needed the |
def get_font(filename, hinting_factor=None): | ||
if hinting_factor is None: | ||
hinting_factor = rcParams['text.hinting_factor'] | ||
return _get_font(filename, hinting_factor) |
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.
Is not it equals to?
@lru_cache(64)
def get_font(filename, hinting_factor=None):
if hinting_factor is None:
hinting_factor = rcParams['text.hinting_factor']
return ft2font.FT2Font(filename, hinting_factor)
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.
That would cache hinting_factor=None
with whatever the value of the rcParam was at first call.
thanks |
This is only explicitly used in Agg, so any other users get the default in the C++ code. Thus if you modify this setting and use some other backend, you get very weird behaviour. Positioning sometimes breaks and glyphs are shrunk or cropped.
@anntzer this is why just changing a random
hinting_factor
produced super-weird results yesterday.Don't know if it's worth backporting; I guess no-one ever tried modifying this setting or they would have complained. Also, trying to see if a simple test of some sort can be done.
PR Checklist