8000 type1font.py fixes and test case by jkseppan · Pull Request #4522 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

type1font.py fixes and test case #4522

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

Merged
merged 10 commits into from
Jul 3, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for type1font.py
  • Loading branch information
jkseppan committed Jun 14, 2015
commit f6d6c7ad9044168688ed5287572aa97744588e4d
Binary file added lib/matplotlib/tests/cmr10.pfb
Binary file not shown.
53 changes: 53 additions & 0 deletions lib/matplotlib/tests/test_type1font.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import six

from nose.tools import assert_equal, assert_in
import matplotlib.type1font as t1f
import os.path
import difflib
import hashlib

def sha1(data):
hash = hashlib.sha1()
hash.update(data)
return hash.hexdigest()

def test_Type1Font():
filename = os.path.join(os.path.dirname(__file__), 'cmr10.pfb')
font = t1f.Type1Font(filename)
slanted = font.transform({'slant': 1})
condensed = font.transform({'extend': 0.5})
assert_equal(map(sha1, font.parts),
['f4ce890d648e67d413a91b3109fe67a732ced96f',
'af46adb6c528956580c125c6abf3b5eb9983bbc1',
'e2538a88a810bc207cfa1194b658ee8967042db8'])
assert_equal(font.parts[1:], slanted.parts[1:])
assert_equal(font.parts[1:], condensed.parts[1:])

differ = difflib.Differ()
diff = set(differ.compare(font.parts[0].splitlines(),
slanted.parts[0].splitlines()))
for line in (
# Removes UniqueID
'- FontDirectory/CMR10 known{/CMR10 findfont dup/UniqueID known{dup',
'+ FontDirectory/CMR10 known{/CMR10 findfont dup',
# Alters FontMatrix
'- /FontMatrix [0.001 0 0 0.001 0 0 ]readonly def',
'+ /FontMatrix [0.001 0.0 0.001 0.001 0.0 0.0]readonly def',
# Alters ItalicAngle
'- /ItalicAngle 0 def',
'+ /ItalicAngle -45.0 def'):
assert_in(line, diff, 'diff to slanted font must contain %s' % line)

diff = set(differ.compare(font.parts[0].splitlines(),
condensed.parts[0].splitlines()))
for line in (
# Removes UniqueID
'- FontDirectory/CMR10 known{/CMR10 findfont dup/UniqueID known{dup',
'+ FontDirectory/CMR10 known{/CMR10 findfont dup',
# Alters FontMatrix
'- /FontMatrix [0.001 0 0 0.001 0 0 ]readonly def',
'+ /FontMatrix [0.0005 0.0 0.0 0.001 0.0 0.0]readonly def'):
assert_in(line, diff, 'diff to condensed font must contain %s' % line)
0