Skip to content
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

Fix positioning of mathtext glyphs #15339

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Sep 25, 2019

PR Summary

Fixes #15313 by porting mplcairo's mathtext backend to matplotlib. Also breaks all mathtext image comparison tests due to subpixel positioning issues :( Some of them should be fixed on this PR, but others are issues with the old mathtext code.

Will do some more detailed writeup at some later time...

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@QuLogic
Copy link
Member

QuLogic commented Sep 25, 2019

So would this fix the weird uneven baseline that seems to happen in some (all?) mathtext test images?

@anntzer
Copy link
Contributor Author

anntzer commented Sep 25, 2019

Not right now, but I have a plan...

Basically the origin of the uneven baselines, I think, is that draw_glyph_to_bitmap specifies the top right corner of the glyph, but that can be a fractional value (FreeType gives glyph sizes in (1/64)px) and then there is some roundoff when actually copying the glyph outline to the FT2Image which leads to the baseline being unaligned.

I think best would be to fix the mathtext logic to position glyphs by baseline/right position and adjust draw_glyph_to_bitmap accordingly; alternatively we can "reverse-engineer" the values that need to be sent to draw_glyph_to_bitmap to fix that roundoff.

for x1, y1, x2, y2 in self._rects:
x1 += dxmin
x2 += dymin
y1 += dxmin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct?

@jklymak
Copy link
Member

jklymak commented Sep 25, 2019

I was just digging through this code in an attempt to understand #15313. If you are thinking about it all and understand it, can you add a few comments for posterity?

@anntzer
Copy link
Contributor Author

anntzer commented Sep 25, 2019

Yes, I need to write up something...

@anntzer
Copy link
Contributor Author

anntzer commented Nov 5, 2020

This also mostly fixes #18899, but the example at #18899 actually shows that the glyphs are also cut in the horizontal direction:
hdpi
The bottom left corner of the x and the right edges of the digits (using mathtext) are clearly cut with this PR :/

I think another problem is that draw_text_to_bitmap doesn't support subpixel positioning, there seems to be some story related to sub_offset at the C level and old commits from @mdboom mentioning links with the wiggly baseline problem...

@github-actions
Copy link

Since this Pull Request has not been updated in 60 days, it has been marked "inactive." This does not mean that it will be closed, though it may be moved to a "Draft" state. This helps maintainers prioritize their reviewing efforts. You can pick the PR back up anytime - please ping us if you need a review or guidance to move the PR forward! If you do not plan on continuing the work, please let us know so that we can either find someone to take the PR over, or close it.

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jun 26, 2023
@anntzer
Copy link
Contributor Author

anntzer commented Jun 26, 2023

Should likely be kept and put in in some form once the baseline image machinery is revamped.

@anntzer anntzer added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action labels Jun 26, 2023
@anntzer anntzer mentioned this pull request Aug 7, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep Items to be ignored by the “Stale” Github Action status: needs rebase topic: text/mathtext
Projects
None yet
Development

Successfully merging this pull request may close these issues.

star (*) symbol in text box cuts off bottom of text when saved
3 participants