Skip to content

Create tiny mathtext baseline images using svg with non-embedded fonts. #19201

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

Closed
wants to merge 3 commits into from

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Dec 30, 2020

... and using non-integer bases sqrt as example use case.

See #19186 (comment).

While I was at it I also fixed/shortened the font attribute used to specify the font (first commit).

PR Summary

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@anntzer anntzer force-pushed the mathtextsvgtests branch 6 times, most recently from 84adc51 to 78df724 Compare December 31, 2020 18:55
@timhoffm
Copy link
Member

timhoffm commented Jan 1, 2021

Generally 👍 on the concept.

Questions:

  • SVG is harder to compare visually than PNG. I assume it's smaller though. Is the added complexity worth the savings compared to just using PNG?
  • Is it reasonable/necessary to check all fonts?

@anntzer
Copy link
Contributor Author

anntzer commented Jan 1, 2021

I agree pngs would be simpler, but...
From a quick test (on the single test case used here): the current svg baseline is 2.8K (and git should internally gzip it down, which results in a file just below 1K). "Naively" switching to png results in a much larger (7K) file. Somewhat surprisingly, even passing pil_kwargs={"optimize": True} (https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#png) only reduces it to 6.3K; passing the file through optipng does crush it down to 3.5K though. But git shouldn't be able to further compress down the resulting file via gzip.
Also, I expect svgs to diff much more efficiently if we change e.g. precise glyph positionings.

Checking all fonts is likely mostly relevant for test_mathfont_rendering only, I guess?

@timhoffm
Copy link
Member

timhoffm commented Jan 3, 2021

OK, so only removing SVG and PS wouldn't gain us much because PNG uses the most space anyway.

I'm very hesitant to use optipng for testing. First that'd make it a hard dependency for testing. And second more importantly, we'd bake the compression algorithm into our tests. If optipng changes somehow it could break all our tests.

It likely has to be SVG if we want to save space.

@QuLogic
Copy link
Member

QuLogic commented Jan 5, 2021

If the sqrt code itself needs to change (as opposed to its test), it should at least be in a separate commit. I'm not sure why those changes are happening as there's no context for it.

This replaces e.g.
`"font-family:DejaVu Sans;font-size:12px;font-style:book;font-weight:book;"`
by `"font: 400 12px 'DejaVu Sans'"`.
Note that the previous font weight was plain wrong...
@anntzer
Copy link
Contributor Author

anntzer commented Jan 5, 2021

Done.
The changes to sqrt were mostly to make sure that the new machinery works in a concrete use case.

@timhoffm
Copy link
Member

timhoffm commented Jan 5, 2021

Conclusion from the dev call today:

  • Take font spec improvement (first commit); it's independent anyway
  • Limit baseline images to SVG
  • Don't use fonts in the SVG but keep the fonts being converted to paths.
    Concern is on the added complexity; and the production code uses converted paths, so testing these is closer to the production case. We live with the larger SVG size due to paths in test images for now. Tom is planning to prioritize the separate repo for test images, so image size is a little less critical.

@anntzer
Copy link
Contributor Author

anntzer commented Jan 6, 2021

Don't use fonts in the SVG but keep the fonts being converted to paths.

I don't have hard numbers right now but IIRC embedding the paths makes the SVGs much larger, defeating the purpose of the PR... in that case we may just as well stick to png only for ease of use.

@timhoffm
Copy link
Member

timhoffm commented Jan 7, 2021

You're right. The existing svgs under test_mathtext are roughly 2x the size of the corresponding png. Given that, the pragmatic solution is to stick to png only. So let's

  • Take font spec improvement (first commit); it's independent anyway
  • Limit baseline images to PNG

@anntzer
Copy link
Contributor Author

anntzer commented Jan 15, 2021

milestoning as 3.4 as a dependency for #18916

@QuLogic
Copy link
Member

QuLogic commented Jan 16, 2021

Aren't we doing #19261 instead?

@anntzer
Copy link
Contributor Author

anntzer commented Jan 16, 2021

Yup, milestoned the wrong one :p

@anntzer anntzer closed this Jan 16, 2021
@anntzer anntzer deleted the mathtextsvgtests branch January 16, 2021 20:51
@QuLogic QuLogic removed this from the v3.4.0 milestone Mar 16, 2021
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.

3 participants