Fix usetex path optical sizing - #32392
krishsinghhura wants to merge 2 commits into
Conversation
|
Thank you for opening your first PR into Matplotlib! If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process. You can also join us on discourse chat for real-time discussion. For details on testing, writing docs, and our review process, please see the developer guide. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
|
Hello, please review our AI policy and fill out the AI Disclosure section from the original Pull Request Template. Thank you! |
|
Hey @iccir I’ve added the AI disclosure. I also investigated the CI failures: every failed matrix job is the same expected-image mismatch in |
|
@iccir I updated the |
|
The AppVeyor job frequently times out and should hopefully be fixed by #32395. |
PR summary
Closes #32389
Problem
In
usetexmode,TextToPath.get_glyphs_texhardcoded LaTeX compilation to a fixedFONT_SCALE = 100 pt. Because TeX fonts have size-specific optical designs, TeX selected the large 17 pt design (CMSS17) and scaled it down, while layout measurement (TexManager.get_text_width_height_descent) typeset at the actual text size (e.g.CMSS8for 6–8 pt).This caused:
CMSS17while PDF output usedCMSS8.path_effectswas narrower than its layout box and ended short of the alignment boundary.TextPath(size=...)issue:TextPathacceptedsizeseparately without propagating it toprop.Solution
TextToPath.get_glyphs_texto typeset at the requested font size (fontsize = prop.get_size_in_points()) and rescale DVI coordinates and boxes back toFONT_SCALEunits viascale = self.FONT_SCALE / fontsize.propviaFontProperties._from_any(prop)for defensive input handling.sizeinTextPath.__init__to a copy ofprop.test_usetex.pycovering optical font selection andTextPathsize propagation.Reproduction & Verification
Click to view reproduction code
Expected Results with this PR:
['CMSS17'])usetex_path_effects.png, both lines of text align flush with the red guide line.Tests Run:
pytest lib/matplotlib/tests/test_usetex.py -k "optical_sizing or textpath_size"(Passed)test_mathdefault,test_multiline_eqnarray,test_usetex_with_underscore,test_usetex_fallback,test_rotation,test_unicode_sizing(All passed)git diff --checkpassed, no trailing whitespace or lint issues.AI Disclosure
I used AI assistance to investigate the issue, trace relevant rendering paths, draft the implementation and tests, and help analyze test output. I reviewed the resulting changes, ran verification steps, and am responsible for the final contribution.
PR quality check
Fix usetex path font optical sizing and alignment)