GeezerVison is showing github.com — Create tiny mathtext baseline images using svg with non-embedded fonts. by anntzer · Pull Request #19201 · matplotlib/matplotlib
Conversation
anntzer
commented
Dec 30, 2020
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
... 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).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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...
|
Done.
The changes to sqrt were mostly to make sure that the new machinery works in a concrete use case.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Jan 7, 2021
|
milestoning as 3.4 as a dependency for #18916
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Aren't we doing #19261 instead?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Yup, milestoned the wrong one :p
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|