-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Handle dvi font names as ASCII bytestrings #6977
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
Changes from 1 commit
705b021
dbc8b9e
93fad55
4874e4e
a130ba7
0f0e41a
a7b5772
803a96e
ec5d80e
fe52808
aa8c4f6
9de07aa
c87b653
2e19a61
119934a
8fa303f
94587b1
254e3df
a8674b3
25a8fed
92e2c52
5ba21b0
10135bf
6de9813
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -906,38 +906,43 @@ def _register(self, words): | |
assert isinstance(word, bytes) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, the logic of this function may perhaps be more easily expressed using regexes. |
||
texname, psname = words[:2] | ||
words = words[2:] | ||
effects, encoding, filename = b'', None, None | ||
for word in words[2:]: | ||
if not word.startswith(b'<'): | ||
effects = word | ||
else: | ||
word = word.lstrip(b'<') | ||
if word.startswith(b'[') or word.endswith(b'.enc'): | ||
if encoding is not None: | ||
matplotlib.verbose.report( | ||
'Multiple encodings for %s = %s' | ||
% (texname, psname), 'debug') | ||
if word.startswith(b'['): | ||
encoding = word[1:] | ||
else: | ||
encoding = word | ||
else: | ||
assert filename is None | ||
filename = word | ||
|
||
eff = effects.split() | ||
effects = {} | ||
try: | ||
effects['slant'] = float(eff[eff.index(b'SlantFont')-1]) | ||
except ValueError: | ||
pass | ||
try: | ||
effects['extend'] = float(eff[eff.index(b'ExtendFont')-1]) | ||
except ValueError: | ||
pass | ||
# pick the last non-filename word for effects | ||
effects_words = [word for word in words if not word.startswith(b'<')] | ||
if effects_words: | ||
effects = effects_words[-1] | ||
|
||
encoding_re = br'<<?(\[.*|.*\.enc)' | ||
encoding_files = [word.lstrip(b'<').lstrip(b'[') | ||
for word in words | ||
if re.match(encoding_re, word)] | ||
if len(encoding_files) > 1: | ||
matplotlib.verbose.report( | ||
'Multiple encodings for %s = %s' % (texname, psname), 'debug') | ||
if encoding_files: | ||
encoding = encoding_files[-1] | ||
|
||
font_files = [word.lstrip(b'<') | ||
for word in words | ||
if word.startswith(b'<') | ||
and not re.match(encoding_re, word)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure that 3 list comprehensions over |
||
if font_files: | ||
filename = font_files[-1] | ||
|
||
eff = {} | ||
for psword, keyword in ((b'SlantFont', 'slant'), | ||
(b'ExtendFont', 'extend')): | ||
match = re.search(b'([^ ]+) +' + psword, effects) | ||
if match: | ||
try: | ||
eff[keyword] = float(match.group(1)) | ||
except ValueError: | ||
pass | ||
|
||
self._font[texname] = PsFont( | ||
texname=texname, psname=psname, effects=effects, | ||
texname=texname, psname=psname, effects=eff, | ||
encoding=encoding, filename=filename) | ||
|
||
|
||
|
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.
A while ago where was an effort to remove
assert
from all of the main code base and replace withif not ...: raise
blocks. Are these here for testing reasons or run-time checks?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.
This is a private function and should only be called from the same class, so if this triggers it's an internal error in the code. While writing this code I felt this was more obvious than the later errors you get from mixing bytestrings and strings, but perhaps this is not really needed.