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

Skip to content

Commit cece2d4

Browse files
authored
Merge pull request #9198 from tacaswell/fix_afm_unicode
FIX: always decode byte strings from AFM files as utf8 Self-merging due to approvals from @anntzer and @dopplershift
2 parents a1f635f + e3e78be commit cece2d4

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)