Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

FIX: correctly handle generic font families in svg text-as-text mode#23638

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tacaswell merged 3 commits intomatplotlib:mainfromtacaswell:svg_generic_fonts
Sep 30, 2022

Conversation

tacaswell
Copy link
Member

PR Summary

This:

  • expands the generic fonts families to the user configured specific fonts
    in the svg output
  • ensures that each font family only appears once per text element in the svg output
  • ensures that generic families are unquoted and specific families are

closes#22528
closes#23492

I still need to write a test for this, but interactively this gives things like

 <textstyle="font:10px'DejaVu Sans','WenQuanYi Zen Hei','DejaVu Sans','Bitstream Vera Sans','Computer Modern Sans Serif','Lucida Grande','Verdana','Geneva','Lucid','Arial','Helvetica','Avant Garde',sans-serif;text-anchor:start"x="236.16"y="174.528"transform="rotate(-0 236.16 174.528)">There are 几个汉字 in between!</text>

PR Checklist

Tests and Styling

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (installflake8-docstrings and runflake8 --docstring-convention=all).

@tacaswell
Copy link
MemberAuthor

This might require some changes to sort out if CI has the fonts (or just just the "wrong" kind of font to exercise the code).

@tacaswell
Copy link
MemberAuthor

I appear to have introduced a memory leak as the runners are getting OOM'd and running the tests with a single worker is using ~2G of ram.

@tacaswell
Copy link
MemberAuthor

This seems to cause an 8x increase in memory usage and a 10x slow down in the test suite.

@tacaswelltacaswell marked this pull request as draftAugust 17, 2022 14:23
family,
", ".join(self._expand_aliases(family))
if family in font_family_aliases:
# deal with the sans/san-serif/sans serif issue
Copy link
Contributor

Choose a reason for hiding this comment

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

This and the following line (the start of the for loop) can be just

forfaminself._expand_aliases(family):iffaminfont_family_aliases:continue# is that even possible?    ...

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This will go into another PR, this change seems to be causing a 10x memory increase and I do not understand why yet.

@tacaswelltacaswell modified the milestones:v3.6.0,v3.7.0Aug 19, 2022
@tacaswell
Copy link
MemberAuthor

This is not ready yet and I do not want to hold 3.6 on it. It is possible that the changes will be small enough to backport to a 3.6.x, but I am not optimistic.

@tacaswelltacaswellforce-pushed thesvg_generic_fonts branch 2 times, most recently from36725ed toaf2cc4fCompareSeptember 1, 2022 01:51
@tacaswelltacaswell modified the milestones:v3.7.0,v3.6.1Sep 1, 2022
@tacaswell
Copy link
MemberAuthor

I think this may now be small enough to backport to v3.6.x but I do not think we should block 3.6.0 over it.

@tacaswelltacaswell marked this pull request as ready for reviewSeptember 1, 2022 02:07
@@ -1151,10 +1151,56 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):
weight = fm.weight_dict[prop.get_weight()]
if weight != 400:
font_parts.append(f'{weight}')

def unique_iter(inp):
Copy link
Contributor

@anntzeranntzerSep 1, 2022
edited
Loading

Choose a reason for hiding this comment

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

That's actually[*dict.fromkeys(inp)] (or even without the conversion to list which is not needed in this case, iterating over the keys is fine); this is so short that it could even be inlined with a comment, something likedict.fromkeys(s for fam in prop.get_family() for s in _format_font_name(fam)) (ordict.fromkeys(itertools.chain(*map(_format_font_name, prop.get_family()))) for itertools aficionados)

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

oh, nice!

Copy link
Member

Choose a reason for hiding this comment

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

I replacedunique_iter, but didn't do anything fancier.

This tests:1. all of the fonts from the generic lists Matplotlib maintains ends up in the   svg2. the generic family is included and un-escaped3. the specific fonts are escaped4. glyph fallback will happen in fonts found via generic family names
This:- expands the generic fonts families to the user configured specific fonts  in the svg output- ensures that each font family only appears once per text element in the svg output- ensures that generic families are unquoted and specific families areclosesmatplotlib#22528closesmatplotlib#23492
If the cached function raises it will not be cached and we will continuouslypay for cache misses.
@QuLogic
Copy link
Member

I pushed some minor corrections to the comments directly.

@tacaswell
Copy link
MemberAuthor

I'm going to merge this on@QuLogic 's review via working on it and@anntzer 's review.

@tacaswelltacaswell merged commit8f6616c intomatplotlib:mainSep 30, 2022
@tacaswelltacaswell deleted the svg_generic_fonts branchSeptember 30, 2022 22:27
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull requestSep 30, 2022
oscargus added a commit that referenced this pull requestOct 1, 2022
…638-on-v3.6.xBackport PR#23638 on branch v3.6.x (FIX: correctly handle generic font families in svg text-as-text mode)
@ksundenksunden mentioned this pull requestFeb 20, 2023
6 tasks
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@QuLogicQuLogicQuLogic left review comments

@oscargusoscargusoscargus left review comments

@anntzeranntzeranntzer approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.6.1
Development

Successfully merging this pull request may close these issues.

[Bug]: svg backend does not use configured generic family lists [Bug]: problem with font property in text elements of svg figures
4 participants
@tacaswell@QuLogic@anntzer@oscargus

[8]ページ先頭

©2009-2025 Movatter.jp