Repository navigation
Reduce numerical precision in Type 1 fonts - #18080
Conversation
| as_string = '[' + ' '.join(str(x) for x in array) + ']' | ||
| return as_string.encode('latin-1') | ||
| return ( | ||
| '[' + ' '.join(f'{x:.5g}' for x in array) + ']' |
There was a problem hiding this comment.
perhaps .5f instead?
(I'm currently away from doing real reviewing so don't wait for me, but the PR certainly looks reasonable.)
There was a problem hiding this comment.
I cannot comment on g vs. f, but I would prefer
| '[' + ' '.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.
There was a problem hiding this comment.
(the problem with 'g' is exponent notation: does postscript actually support notation such as '1e4'? (I don't know))
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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.
|
Thanks @jkseppan ! Have not heard from you in a while, I hope you and your family are doing well. |
Fixes #16087
PR Summary
Numbers such as
seem to confuse some PostScript parsers, so output fewer digits when changing the angle of a font.
PR Checklist