-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Bad font hinting / quality with Agg renderer #719
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
The hinting factor is the amount of softness in hinting is applied in the horizontal direction. For years, matplotlib has hinted to 1/8 pixels in the horizontal direction and whole pixels in the vertical direction. This results in text that is often more legible (particularly at smaller sizes) than standard 1:1 hinting. This is based on idea from this paper from the author of Agg: http://www.antigrain.com/research/font_rasterization/ However, sometimes the user may want full-on hinting, so this value is now tweakable using the `text.hinting_factor` rcParam.
What you're seeing is the effect of "soft hinting" where it hints to subpixels in the x direction. Years ago we did a sort of survey on the mailing list of which kind of hinting looked best and that's what we determined. Of course, it doesn't have to be hardcoded, so I've attached some changes that make the amount of softness tweakable with an rcParam. Can you try this out (setting "text.hinting_factor" to 1) and let me know if this resolves your issue? I'm hesitant to change the default as many users (and the testing framework) are relying on the present behavior.
|
Thanks for the patch! It does improve things, but the hinting still leaves a bit to be desired, at least compared to the Cairo backend. I've updated the images at http://jim.sh/~jim/tmp/matplotlib-font to show how the Regarding the default, I agree that the present behavior shouldn't be changed at this point. I'm fine with setting a variable in my own scripts. |
I think I figured it out: currently, Maybe {
False: LOAD_NO_HINTING,
True: LOAD_FORCE_AUTOHINT,
"auto": LOAD_FORCE_AUTOHINT,
"native": LOAD_NO_AUTOHINT,
"either": LOAD_DEFAULT,
} |
Ok. I've incorporated this. |
Works perfectly. Now |
Great! Merging... |
Bad font hinting / quality with Agg renderer
When using the
agg
backend to create PNGs, fonts are poorly hinted, and always look blurry. Settingtext.hinting = True
has no effect.The below script creates two images that demonstrate the problem. It generates some text in multiple sizes, with both the
agg
and thecairo
backends. While the progression of sizes generally looks smoother with theagg
backend, there seems to be no way to replicate the crispness of thecairo
backend, particularly around sizes 9, 10, 11, and 12.I have copies of the images, and zoomed-in versions for comparision, available at
http://jim.sh/~jim/tmp/matplotlib-font