Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6d6c7a

Browse files
committed
Add test for type1font.py
1 parent f796024 commit f6d6c7a

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

lib/matplotlib/tests/cmr10.pfb

34.9 KB
Binary file not shown.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
3+
4+
import six
5+
6+
from nose.tools import assert_equal, assert_in
7+
import matplotlib.type1font as t1f
8+
import os.path
9+
import difflib
10+
import hashlib
11+
12+
def sha1(data):
13+
hash = hashlib.sha1()
14+
hash.update(data)
15+
return hash.hexdigest()
16+
17+
def test_Type1Font():
18+
filename = os.path.join(os.path.dirname(__file__), 'cmr10.pfb')
19+
font = t1f.Type1Font(filename)
20+
slanted = font.transform({'slant': 1})
21+
condensed = font.transform({'extend': 0.5})
22+
assert_equal(map(sha1, font.parts),
23+
['f4ce890d648e67d413a91b3109fe67a732ced96f',
24+
'af46adb6c528956580c125c6abf3b5eb9983bbc1',
25+
'e2538a88a810bc207cfa1194b658ee8967042db8'])
26+
assert_equal(font.parts[1:], slanted.parts[1:])
27+
assert_equal(font.parts[1:], condensed.parts[1:])
28+
29+
differ = difflib.Differ()
30+
diff = set(differ.compare(font.parts[0].splitlines(),
31+
slanted.parts[0].splitlines()))
32+
for line in (
33+
# Removes UniqueID
34+
'- FontDirectory/CMR10 known{/CMR10 findfont dup/UniqueID known{dup',
35+
'+ FontDirectory/CMR10 known{/CMR10 findfont dup',
36+
# Alters FontMatrix
37+
'- /FontMatrix [0.001 0 0 0.001 0 0 ]readonly def',
38+
'+ /FontMatrix [0.001 0.0 0.001 0.001 0.0 0.0]readonly def',
39+
# Alters ItalicAngle
40+
'- /ItalicAngle 0 def',
41+
'+ /ItalicAngle -45.0 def'):
42+
assert_in(line, diff, 'diff to slanted font must contain %s' % line)
43+
44+
diff = set(differ.compare(font.parts[0].splitlines(),
45+
condensed.parts[0].splitlines()))
46+
for line in (
47+
# Removes UniqueID
48+
'- FontDirectory/CMR10 known{/CMR10 findfont dup/UniqueID known{dup',
49+
'+ FontDirectory/CMR10 known{/CMR10 findfont dup',
50+
# Alters FontMatrix
51+
'- /FontMatrix [0.001 0 0 0.001 0 0 ]readonly def',
52+
'+ /FontMatrix [0.0005 0.0 0.0 0.001 0.0 0.0]readonly def'):
53+
assert_in(line, diff, 'diff to condensed font must contain %s' % line)

0 commit comments

Comments
 (0)