Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Changes in SVG backend to improve compatibility with Affinity designer #28504

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

Merged
merged 1 commit into from
Jul 22, 2024

Conversation

LorenzoPeri17
Copy link
Contributor

Separate font attributes && use translate(x y) in RendererSVG._draw_text_as_path

PR summary

Closes #20910

Two small changes in the SVG backend:

  • xlink:href tags' position is specified via transform=translate(x y) rather than with x and y attributes
  • text tags separate font attribute into its separate constituent properties

PR checklist

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

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.

You can also join us on gitter 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.

@ksunden
Copy link
Member

ksunden commented Jul 3, 2024

Did you mean to close this?

I noticed that tests were not passing, but were all failing in the same way, so not sure what the fix is, but it may be relatively easy to do, and we can do it within the same PR.

@LorenzoPeri17 LorenzoPeri17 reopened this Jul 4, 2024
@LorenzoPeri17
Copy link
Contributor Author

Hi! Thanks for the message. I realized I read about the issue I was having in lib/matplotlib/testing/compare.py::convert so I figured I would close the PR because it was failing to do some debugging.
I have chased down one issue which was described in this commit. I'm more than happy to iron out the remaining issues within this PR if that works best :)

@LorenzoPeri17 LorenzoPeri17 changed the title Changes in SV backend to improve compatibility with Affinity designer Changes in SVG backend to improve compatibility with Affinity designer Jul 7, 2024
@@ -433,7 +432,7 @@ def test_mathtext_fallback_invalid():
@pytest.mark.parametrize(
"fallback,fontlist",
[("cm", ['DejaVu Sans', 'mpltest', 'STIXGeneral', 'cmr10', 'STIXGeneral']),
("stix", ['DejaVu Sans', 'mpltest', 'STIXGeneral'])])
("stix", ['DejaVu Sans', 'mpltest', 'STIXGeneral', 'STIXGeneral', 'STIXGeneral'])])
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need the additional 'STIXGeneral' entries here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have slightly changed the logic for how the tspans inside a text tag are separated (backend_svg.py::_draw_text_as_text line 1224 onwards).
During some testing I found poor compatibility with specifying multiple x and y in the same tspan (from reading the docs maybe dx would be better if the old way was to be preferred?)
My new solution is cleaner code-wise and seems to resolve the compatibility issues. However, it causes more tspans to be generates, hence why the repetition in the tests.

@tacaswell
Copy link
Member

To check we need to regenerate the svg files to make keep them in sync with our compare code, not because rendered output (in compliant viewers) actually changed?

@tacaswell tacaswell added this to the v3.10.0 milestone Jul 8, 2024
@LorenzoPeri17
Copy link
Contributor Author

To check we need to regenerate the svg files to make keep them in sync with our compare code, not because rendered output (in compliant viewers) actually changed?

Exactly. That and because on the appveyor tests (and only there, azure and github were passung just fine) for some reason a few tests would fail with a very small RMS (~0.001) because of a few pixels in long ticklabels being slightly off when rendering (see attached example)

axvspan_epoch_svg
axvspan_epoch-expected_svg

Falied diff
axvspan_epoch_svg-failed-diff

@tacaswell
Copy link
Member

The appeveyor failures look related and real.

@LorenzoPeri17
Copy link
Contributor Author

I had some time to debug the failing tests. It seems that the baseline images were specifying certain coordinates for xlink:href elements beyond 6 digits of precision, causing inkscape to render some text half a pizel off. I have changed this and I can't see any failure.
However, some tests seem to fail now for unrelated reasons. I assume this is because of changes to the workflows. I assume this is because of this fork being behind with respect to main?

@tacaswell
Copy link
Member

Can you please rebase on main and squash all of the image updating into one commit?

@tacaswell
Copy link
Member

At some point we change from outputting a lot of digits to rounding to a smaller number of digits but did not bulk re-generate the test images because they were still passing.

@LorenzoPeri17
Copy link
Contributor Author

Should be done :)

@@ -266,8 +266,11 @@ def _get_fontconfig_fonts():
@lru_cache
def _get_macos_fonts():
"""Cache and list the font paths known to ``system_profiler SPFontsDataType``."""
d, = plistlib.loads(
subprocess.check_output(["system_profiler", "-xml", "SPFontsDataType"]))
try:
Copy link
Member

Choose a reason for hiding this comment

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

Was this change supposed to be included?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apologies, that slipped in when squasing. Fixed now

@tacaswell
Copy link
Member

It looks like there is still a merge from main in here?

@LorenzoPeri17 LorenzoPeri17 force-pushed the main branch 3 times, most recently from 1f1b6e0 to 0e7f73d Compare July 18, 2024 21:00
@LorenzoPeri17
Copy link
Contributor Author

Is this OK now?

@tacaswell
Copy link
Member

no, still a rouge merge from main...is your local main not equal to upstream main?

…SVG._draw_text_as_path

fixed linting (flake8 test failing)

Fixed checks in testing for svg.fonttype = none

fixed flake8 && failing tests

linting

modified tspans && fix to svg tests

Updated baseline images for svg tests

Update lib/matplotlib/testing/compare.py

nicer regex to check if font syling in svg is specified

Co-authored-by: Tim Hoffmann <[email protected]>

Apply suggestions from code review

More concise font testing in test_backend_svg.py

Co-authored-by: Tim Hoffmann <[email protected]>

Update lib/matplotlib/tests/test_mathtext.py

Co-authored-by: Tim Hoffmann <[email protected]>

Update backend_svg.py

inlining `style`

restored test images

update to baseline images

Fix to regex for testing/compare.py::compare

forgot one baseline image
@LorenzoPeri17
Copy link
Contributor Author

Gotcha! It is done now, I didn't realize I had to rebase, not merge upstream main. I was doing it though the nice green button on the github page, but that only offers the option to do a merge.

@tacaswell tacaswell merged commit bcfecca into matplotlib:main Jul 22, 2024
40 checks passed
@tacaswell
Copy link
Member

Thank you for your work on this @LorenzoPeri17 .

Congratulations on your first merged Matplotlib PR 🎉 I hope we hear from you again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for author
Development

Successfully merging this pull request may close these issues.

[Bug]: Exported SVG files are no longer imported Affinity Designer correctly
4 participants