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
type1font.py fixes and test case #4522
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f796024
Streamline type1font.py
jkseppan f6d6c7a
Add test for type1font.py
jkseppan dcc2f40
Fixes to type1font.py
jkseppan 3b4b79d
PEP8
jkseppan 66d974a
Improve test, fix an off-by-one and simplify the code
jkseppan 372b402
Fix bytes/str handling all over type1font and its test
jkseppan 301986a
Attempt to document the _whitespace etc objects a bit
jkseppan edae4ea
License for cmr10.pfb
jkseppan ce7d782
PEP8
jkseppan 2e421be
Skip end-of-lines before block of zeros
jkseppan File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
Why use
is
test instead of==
? That seems to be betting heavily on some cpython internals working as expected.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 introduced these sentinel objects to replace string comparisons, which were hard to get right across Python versions. The idea would be to use them like None. Perhaps this needs better comments, or one of the other enum patterns.
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, sorry 🐑 makes sense now.
Was this the stuff that was a long time broken do to
token
no longer being a string?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.
Yes, the confusion between strings and bytes was exactly the problem.