Text antialiasing for mathtext (reopen)#26376
Conversation
| @check_figures_equal() | ||
| def test_text_math_antialiased_on_default_vs_manual(fig_test, fig_ref): | ||
| fig_test.text(0.5, 0.5, r"OutsideMath $I\'m \sqrt{2}$", antialiased=True) | ||
|
|
||
| mpl.rcParams['text.antialiased'] = True | ||
| fig_ref.text(0.5, 0.5, r"OutsideMath $I\'m \sqrt{2}$") | ||
|
|
||
|
|
||
| @check_figures_equal() | ||
| def test_text_math_antialiased_off_default_vs_manual(fig_test, fig_ref): | ||
| fig_test.text(0.5, 0.5, r"OutsideMath $I\'m \sqrt{2}$", antialiased=False) | ||
|
|
||
| mpl.rcParams['text.antialiased'] = False | ||
| fig_ref.text(0.5, 0.5, r"OutsideMath $I\'m \sqrt{2}$") |
There was a problem hiding this comment.
Unfortunately, neither of these tests fail without this PR, so I'm not sure if they are testing what you want?
There was a problem hiding this comment.
Yes.
Before this: For math text, whether we are using antialiasing is resolved when rendering (_mathtext.py::Output.to_raster()). Two test figures are saved after we executing theses codes, resulting two figures resolve to the same rcParams.
After this: When creating the text, antialiasing states are set by True or False if the user specifies the keyword argument. Otherwise, the state resolves to rcParams also at the creation time. That is, we no longer query rcParams when rendering.
|
flake 8 tests failing seems unrelated. |
|
flake8 issues are fixed in #26414. You can rebase onto |
|
|
||
| @functools.lru_cache(50) | ||
| def _parse_cached(self, s, dpi, prop): | ||
| def _parse_cached(self, s, dpi, prop, antialiased): |
There was a problem hiding this comment.
This also fixes a latent bug where we would incorrectly hit the cache if the rcparam was changed between the first and subsequent calls!
|
I squash-merged this to make the history a little cleaner. Thank you @stevezhang1999 for following up and getting aliasing fully sorted! I hope we continue to hear from you. |
Thanks! I'm really happy to be part of the community. |
Accidentally closed this by force pushing.
As mentioned in the previous PR, if the text contains math text, antialiasing will use
rcParams["text.antialiased"]and the parameterantialiasedfortext()will have no effect. Now this is fixed -antialiasedworks for mathtext. Note that only AGG backend support this. Using Cairo we cannot customize antialiasing for math text.