Skip to content
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

Use selectfont instead of findfont + scalefont + setfont in PostScript. #18894

Merged
merged 1 commit into from Nov 21, 2020

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Nov 4, 2020

PR Summary

key scale selectfont is literally defined as key findfont scale scalefont setfont,
but "almost always more efficient" (according to the spec).

Also unify the AFM and non-AFM codepaths.

I decided to just change the behavior of set_font in the AFM case as
it seems unlikely people were relying on that; the alternative would be
to just completely deprecate set_font in favor of a new _set_font
with the new behavior, which in fact seems more disruptive...

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 changed the title Selectfont Use selectfont instead of findfont + scalefont + setfont in PostScript. Nov 4, 2020
`key scale selectfont` is literally defined as `key findfont scale
scalefont setfont`, but "almost always more efficient" (according to the
spec).

Also unify the AFM and non-AFM codepaths.

I decided to just change the behavior of `set_font` in the AFM case as
it seems unlikely people were relying on that; the alternative would be
to just completely deprecate `set_font` in favor of a new `_set_font`
with the new behavior, which in fact seems more disruptive...
self.set_color(*gc.get_rgb())
ps_name = (font.postscript_name
.encode("ascii", "replace").decode("ascii"))
self.set_font(ps_name, prop.get_size_in_points())
Copy link
Member

Choose a reason for hiding this comment

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

Putting this here means the font change will happen before the gsave, which is flipped from how it worked in the useafm case before this.

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 believe that's fine, and in fact that's how set_font is supposed to work (its save parameter basically assumes that it is setting the font globally (outside of any gsave block) so that it know when it needs to reset the font or not.

@tacaswell tacaswell added this to the v3.4.0 milestone Nov 21, 2020
@tacaswell
Copy link
Member

For future reference postscript spec: https://www.adobe.com/content/dam/acom/en/devnet/actionscript/articles/psrefman.pdf

One concern I had was that selectfont was a Level 2 feature which sent me down a rabbit hole of sorting out which level of postscript we currently emit. There is a module-level backend_version = 'Level II' (the spec always says 'Level 2'), I also found a Level 2 symbol that we are already using so that concern is moot.

@tacaswell tacaswell merged commit e079bd3 into matplotlib:master Nov 21, 2020
@anntzer anntzer deleted the selectfont branch November 21, 2020 20:25
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.

None yet

3 participants