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

Commit013d508

Browse files
committed
Reduce numerical precision in Type 1 fonts
Fixes#16087
1 parent3e439a4 commit013d508

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

‎lib/matplotlib/tests/test_type1font.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_Type1Font():
2929
'+ /FontName /CMR10_Slant_1000 def',
3030
# Alters FontMatrix
3131
'- /FontMatrix [0.001 0 0 0.001 0 0 ]readonly def',
32-
'+ /FontMatrix [0.001 0.0 0.001 0.001 0.0 0.0]readonly def',
32+
'+ /FontMatrix [0.001 0 0.001 0.001 00]readonly def',
3333
# Alters ItalicAngle
3434
'- /ItalicAngle 0 def',
3535
'+ /ItalicAngle -45.0 def'):
@@ -47,5 +47,23 @@ def test_Type1Font():
4747
'+ /FontName /CMR10_Extend_500 def',
4848
# Alters FontMatrix
4949
'- /FontMatrix [0.001 0 0 0.001 0 0 ]readonly def',
50-
'+ /FontMatrix [0.0005 0.0 0.0 0.001 0.0 0.0]readonly def'):
50+
'+ /FontMatrix [0.0005 0 0 0.001 00]readonly def'):
5151
assertlineindiff,'diff to condensed font must contain %s'%line
52+
53+
54+
deftest_overprecision():
55+
# We used to output too many digits in FontMatrix entries and
56+
# ItalicAngle, which could make Type-1 parsers unhappy.
57+
filename=os.path.join(os.path.dirname(__file__),'cmr10.pfb')
58+
font=t1f.Type1Font(filename)
59+
slanted=font.transform({'slant':.167})
60+
lines=slanted.parts[0].decode('ascii').splitlines()
61+
matrix,= [line[line.index('[')+1:line.index(']')]
62+
forlineinlinesif'/FontMatrix'inline]
63+
angle,= [word
64+
forlineinlinesif'/ItalicAngle'inline
65+
forwordinline.split()ifword[0]in'-0123456789']
66+
# the following used to include 0.00016700000000000002
67+
assertmatrix=='0.001 0 0.000167 0.001 0 0'
68+
# and here we had -9.48090361795083
69+
assertangle=='-9.4809'

‎lib/matplotlib/type1font.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ def fontname(name):
251251
returnresult
252252

253253
defitalicangle(angle):
254-
returnb'%a'% (float(angle)-np.arctan(slant)/np.pi*180)
254+
returnb'%a'%round(
255+
float(angle)-np.arctan(slant)/np.pi*180,
256+
5
257+
)
255258

256259
deffontmatrix(array):
257260
array=array.lstrip(b'[').rstrip(b']').split()
@@ -265,10 +268,9 @@ def fontmatrix(array):
265268
newmatrix=np.dot(modifier,oldmatrix)
266269
array[::2]=newmatrix[0:3,0]
267270
array[1::2]=newmatrix[0:3,1]
268-
# Not directly using `b'%a' % x for x in array` for now as that
269-
# produces longer reprs on numpy<1.14, causing test failures.
270-
as_string='['+' '.join(str(x)forxinarray)+']'
271-
returnas_string.encode('latin-1')
271+
return (
272+
'['+' '.join(f'{x:.5g}'forxinarray)+']'
273+
).encode('ascii')
272274

273275
defreplace(fun):
274276
defreplacer(tokens):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp