GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Reduce numerical precision in Type 1 fonts by jkseppan · Pull Request #18080 · matplotlib/matplotlib

Conversation

@jkseppan

@jkseppan jkseppan commented Jul 27, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Fixes #16087

PR Summary

Numbers such as

/ItalicAngle -9.48090361795083 def
/FontMatrix [0.001 0.0 0.00016700000000000002 0.001 0.0 0.0] readonly def

seem to confuse some PostScript parsers, so output fewer digits when changing the angle of a font.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/next_api_changes/* if API changed in a backward-incompatible way

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

2xmax reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@jkseppan
jkseppan requested a review from anntzer July 27, 2020 07:03
@jkseppan
Reduce numerical precision in Type 1 fonts
013d508
Fixes matplotlib#16087
@jkseppan
jkseppan force-pushed the type1-rounding branch from bcaafca to 013d508 Compare July 27, 2020 07:12
@jkseppan jkseppan mentioned this pull request Jul 27, 2020
Python3 matplotlib 2.0.2 with Times New Roman misses unicode minus sign in pdf #9139
Closed
anntzer
anntzer reviewed Jul 27, 2020
View reviewed changes
Comment thread lib/matplotlib/type1font.py Outdated
as_string = '[' + ' '.join(str(x) for x in array) + ']'
return as_string.encode('latin-1')
return (
'[' + ' '.join(f'{x:.5g}' for x in array) + ']'

@anntzer anntzer Jul 27, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

perhaps .5f instead?
(I'm currently away from doing real reviewing so don't wait for me, but the PR certainly looks reasonable.)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@timhoffm timhoffm Jul 27, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I cannot comment on g vs. f, but I would prefer

Suggested change
'[' + ' '.join(f'{x:.5g}' for x in array) + ']'
'[%s]' % ' '.join(f'{x:.5g}' for x in array)

which is slightly more readable IMHO. But I won't block over this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@anntzer anntzer Jul 27, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

(the problem with 'g' is exponent notation: does postscript actually support notation such as '1e4'? (I don't know))

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@timhoffm timhoffm Jul 27, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Postscript supports exponent notation:

NumbersNumbers in the PostScript language include signed integers, such as
123 –98 43445 0 +17
reals, such as
–.002 34.5 –3.62 123.6e10 1E–5 –1. 0.0
and radix numbers, such as
8#1777 16#FFFE 2#1000

https://www.adobe.com/content/dam/acom/en/devnet/actionscript/articles/psrefman.pdf page 27

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@anntzer anntzer Jul 27, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Ah, that's fine then.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jkseppan jkseppan Jul 27, 2020

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yeah, I thought we should keep a small number of significant digits instead of just rounding to a fixed number of decimals. But on second thought there is little point, since the scale is fixed: fonts are written in terms of 1000 or 1024 units as the side of the design square, so the values on the diagonal are around 0.001. The off-diagonal values are either zero or of similar magnitude as 0.001, otherwise there is no visible effect. We can as well use %f.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tacaswell tacaswell added this to the v3.4.0 milestone Jul 27, 2020
@jkseppan
Make the formatting more explicit
9225aec
This avoids exponential notation (which is supported by PS but who
knows how all the different parsers react to it) and trailing zeros,
so we don't unnecessarily increase the size of fonts that have a
nice [0.001 0 0 0.001] matrix.

Encapsulate the formatting operation in a cbook function and give
it a unit test.
@jkseppan jkseppan added backend: pdf topic: text/fonts topic: text/usetex labels Jul 27, 2020
timhoffm
timhoffm approved these changes Jul 27, 2020
View reviewed changes
tacaswell
tacaswell approved these changes Jul 28, 2020
View reviewed changes
@tacaswell
tacaswell merged commit b5eca56 into matplotlib:master Jul 28, 2020
@tacaswell

tacaswell commented Jul 28, 2020

Copy link
Copy Markdown
Member

Thanks @jkseppan !

Have not heard from you in a while, I hope you and your family are doing well.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic QuLogic mentioned this pull request Jul 28, 2020
Privatize cbook.format_approx. #18090
Merged
2 tasks done
@jkseppan
jkseppan deleted the type1-rounding branch July 28, 2020 06:19
@jkseppan jkseppan mentioned this pull request Jul 28, 2020
Symbols appear as streaks with usetex=True, times font and PDF backend #11259
Closed
@andreas-brugger andreas-brugger mentioned this pull request Nov 30, 2021
[Bug]: Math fonts (Type 3) incorrectly embedded in PDF? #21797
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@anntzer anntzer anntzer left review comments
@tacaswell tacaswell tacaswell approved these changes
@timhoffm timhoffm timhoffm approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

backend: pdf topic: text/fonts topic: text/usetex

Projects

None yet

Milestone

v3.4.0

Development

Successfully merging this pull request may close these issues.

Error with greek letters in pdf export when using usetex=True and mathptmx

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@jkseppan @tacaswell @anntzer @timhoffm
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.