10000 Support for vector hrule rendering by devRD · Pull Request #26337 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Support for vector hrule rendering #26337

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

devRD
Copy link
Contributor
@devRD devRD commented Jul 17, 2023

PR summary

Fixes #23763

The current generated images are:

[PNG]
Hrule_at_bottom

[SVG]
Hrule_at_bottom

PR checklist

@QuLogic
Copy link
Member
QuLogic commented Jul 26, 2023

After some discussion in our GSoC meeting, this is probably the reverse of the way to fix the issue. It appears that the raster output is shifted up when it shouldn't be (i.e., if it's a regular fraction, then all text is on the baseline, but with the test case from #23763, all text is moved up (disregarding the missing shift for the patched fraction.)) The vector output remains on the baseline for both versions.

@devRD
Copy link
Contributor Author
devRD commented Jul 28, 2023

Possibly, the raster output needs the correct width, height, and depth to view a similar output to the vector image. The current dimensions for vector are given as:

w, h, d = map(
np.ceil, [self.box.width, self.box.height, self.box.depth])

Applying the same calculations to the raster gives the following output, which is still shifted upwards and cuts off the end of the denominator text.

Hrule.png Hrule.svg
Hrule_at_bottom Hrule_at_bottom

A few pointers from the above images:

  1. The fraction appears to be askew as well compared to the usetex=True version and could be related to issue #18389
  2. The thickness of the Hrule seems to be different than the TeX version.
  3. The fraction gets misaligned from the center of the = sign.

The raster output being cut off might be caused due to the shifted calculation:

# Ideally, we could just use self.glyphs and self.rects here, shifting
# their coordinates by (-xmin, -ymin), but this yields slightly
< 8000 span class="pl-c"># different results due to floating point slop; shipping twice is the
# old approach and keeps baseline images backcompat.
shifted = ship(self.box, (-xmin, -ymin))
antialiased = mpl.rcParams['text.antialiased']
for ox, oy, info in shifted.glyphs:

So updating for ox, oy, info in shifted.glyphs: to fetch ox, oy from self.glyphs kind of fixes the issue here.

Hrule.png Hrule.svg
Hrule_at_bottom Hrule_at_bottom

I also tinkered around with the _genfrac function to check whether removing additional spacing improves the alignment of the images when rendering fractions.

Vbox(0, thickness * 2.0), # space

which does improve the fraction spacing a bit, but the output shift between png and svg seems to stay put.

Hrule.png Hrule.svg
Hrule_at_bottom Hrule_at_bottom

@devRD
Copy link
Contributor Author
devRD commented Jul 28, 2023

@anntzer @oscargus Any insights on how to proceed with this?

@devRD
Copy link
Contributor Author
devRD commented Jul 28, 2023

Additionally, with the above edits the #23763 example of hrule rendering, the Hrule seems to disappear completely in the raster output.

Hrule.png Hrule.svg
Hrule_at_bottom Hrule_at_bottom

@anntzer
Copy link
Contributor
anntzer commented Jul 30, 2023

I'll have limited access to a dev machine for a few days, but can look into it after.

@anntzer
Copy link
Contributor
anntzer commented Aug 7, 2023

I haven't looked in depth into what's happening here, but 1) skipping the int-casting (via np.ceil) for vector output would seem normal, but can (likely?) cause shifts wrt. raster output; 2) perhaps #15339 (comment) and (the last part of) #15339 (comment) may be relevant?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Inconsistent rendering between backends when rendering Mathtext horizontal rule
4 participants
0