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

Skip to content

Improve font spec for SVG font referencing. #19253

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
May 22, 2021

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jan 7, 2021

The 'font: ...' shorthand is much more concise than setting each
property separately: 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...

Also this revealed a bug in generate_css (we shouldn't run it through
escape_attrib, as quotes (e.g. around the font family name) get
mangled); and we don't need to load the font at all (we should just
report whatever font the user actually requested).

Split out of #19201, but also including the non-mathtext case.

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).

@QuLogic
Copy link
Member

QuLogic commented Jan 7, 2021

Also this revealed a bug in generate_css (we shouldn't run it through
escape_attrib, as quotes (e.g. around the font family name) get
mangled); and we don't need to load the font at all (we should just
report whatever font the user actually requested).

But shouldn't they? The CSS goes in a <element style="..."> and thus a double quote must be escaped.

@anntzer
Copy link
Contributor Author

anntzer commented Jan 8, 2021

But the double quote would get escaped by XMLWriter.start when the XML is actually emitted; the point is that previously we were escaping it twice, both in generate_css and in XMLWriter.start.

@QuLogic
Copy link
Member

QuLogic commented Jan 14, 2021

Yes, I didn't realize that start was in XMLWriter.

The 'font: ...' shorthand is much more concise than setting each
property separately: 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...

Also this revealed a bug in generate_css (we shouldn't run it through
escape_attrib, as quotes (e.g. around the font family name) get
mangled); and we don't need to load the font at all (we should just
report whatever font the user actually requested).
@jklymak jklymak merged commit ed32a04 into matplotlib:master May 22, 2021
@anntzer anntzer deleted the svgfontspec branch May 22, 2021 16:21
@QuLogic QuLogic added this to the v3.5.0 milestone May 25, 2021
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Mar 28, 2024
We currently special-case the SVG converter depending on if it used
fonttype='none', and use one that has our base fonts available. However,
this is not based on the rcParam setting (because we don't have that at
conversion time), but on whether the SVG text contains the font styling
[1]. This check for styling uses the _current_ version, which was
changed way back in matplotlib#19253.

These files were never re-generated though, and used the old version of
the style, meaning the expected images never triggered the special
converter. The result images are written with the current style, and
_do_ trigger the special conveter.

Evidentally, this never was a problem for most developers, because
everyone had DejaVu Sans installed globally, so the expected images
matched. However, on the clean macOS CI, it's not installed globally, so
the expected images get converted with the wrong font, and the test
fails.

[1] https://github.com/matplotlib/matplotlib/blob/de1102668dbc0694e98653bd17641e9d99394e57/lib/matplotlib/testing/compare.py#L303
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Mar 28, 2024
We currently special-case the SVG converter depending on if it used
fonttype='none', and use one that has our base fonts available. However,
this is not based on the rcParam setting (because we don't have that at
conversion time), but on whether the SVG text contains the font styling
[1]. This check for styling uses the _current_ version, which was
changed way back in matplotlib#19253.

These files were never re-generated though, and used the old version of
the style, meaning the expected images never triggered the special
converter. The result images are written with the current style, and
_do_ trigger the special conveter.

Evidentally, this never was a problem for most developers, because
everyone had DejaVu Sans installed globally, so the expected images
matched. However, on the clean macOS CI, it's not installed globally, so
the expected images get converted with the wrong font, and the test
fails.

[1] https://github.com/matplotlib/matplotlib/blob/de1102668dbc0694e98653bd17641e9d99394e57/lib/matplotlib/testing/compare.py#L303
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Mar 28, 2024
We currently special-case the SVG converter depending on if it used
fonttype='none', and use one that has our base fonts available. However,
this is not based on the rcParam setting (because we don't have that at
conversion time), but on whether the SVG text contains the font styling
[1]. This check for styling uses the _current_ version, which was
changed way back in matplotlib#19253.

These files were never re-generated though, and used the old version of
the style, meaning the expected images never triggered the special
converter. The result images are written with the current style, and
_do_ trigger the special conveter.

Evidentally, this never was a problem for most developers, because
everyone had DejaVu Sans installed globally, so the expected images
matched. However, on the clean macOS CI, it's not installed globally, so
the expected images get converted with the wrong font, and the test
fails.

[1] https://github.com/matplotlib/matplotlib/blob/de1102668dbc0694e98653bd17641e9d99394e57/lib/matplotlib/testing/compare.py#L303
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Mar 29, 2024
We currently special-case the SVG converter depending on if it used
fonttype='none', and use one that has our base fonts available. However,
this is not based on the rcParam setting (because we don't have that at
conversion time), but on whether the SVG text contains the font styling
[1]. This check for styling uses the _current_ version, which was
changed way back in matplotlib#19253.

These files were never re-generated though, and used the old version of
the style, meaning the expected images never triggered the special
converter. The result images are written with the current style, and
_do_ trigger the special conveter.

Evidentally, this never was a problem for most developers, because
everyone had DejaVu Sans installed globally, so the expected images
matched. However, on the clean macOS CI, it's not installed globally, so
the expected images get converted with the wrong font, and the test
fails.

[1] https://github.com/matplotlib/matplotlib/blob/de1102668dbc0694e98653bd17641e9d99394e57/lib/matplotlib/testing/compare.py#L303
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