8000 FIX: always decode byte strings from AFM files as utf8 · matplotlib/matplotlib@e3e78be · GitHub
[go: up one dir, main page]

Skip to content

Commit e3e78be

Browse files
committed
FIX: always decode byte strings from AFM files as utf8
closes #9196
1 parent c7107cd commit e3e78be

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/matplotlib/afm.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ def _parse_char_metrics(fh):
189189
ascii_d = {}
190190
name_d = {}
191191
for line in fh:
192-
line = line.rstrip().decode('ascii') # Convert from byte-literal
192+
# We are defensively letting values be utf8. The spec requires
193+
# ascii, but there are non-compliant fonts in circulation
194+
line = _to_str(line.rstrip()) # Convert from byte-literal
193195
if line.startswith('EndCharMetrics'):
194196
return ascii_d, name_d
195197
# Split the metric line into a dictionary, keyed by metric identifiers
@@ -392,7 +394,7 @@ def get_str_bbox_and_descent(self, s):
392394
maxy = 0
393395
left = 0
394396
if not isinstance(s, six.text_type):
395-
s = s.decode('ascii')
397+
s = _to_str(s)
396398
for c in s:
397399
if c == '\n':
398400
continue

0 commit comments

Comments
 (0)
0