From e3e78be47488f302f23c3e0742b351c3c4913b86 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 18 Sep 2017 14:58:45 -0400 Subject: [PATCH] FIX: always decode byte strings from AFM files as utf8 closes #9196 --- lib/matplotlib/afm.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/afm.py b/lib/matplotlib/afm.py index 30d335879888..90215ab8c2e9 100644 --- a/lib/matplotlib/afm.py +++ b/lib/matplotlib/afm.py @@ -189,7 +189,9 @@ def _parse_char_metrics(fh): ascii_d = {} name_d = {} for line in fh: - line = line.rstrip().decode('ascii') # Convert from byte-literal + # We are defensively letting values be utf8. The spec requires + # ascii, but there are non-compliant fonts in circulation + line = _to_str(line.rstrip()) # Convert from byte-literal if line.startswith('EndCharMetrics'): return ascii_d, name_d # Split the metric line into a dictionary, keyed by metric identifiers @@ -392,7 +394,7 @@ def get_str_bbox_and_descent(self, s): maxy = 0 left = 0 if not isinstance(s, six.text_type): - s = s.decode('ascii') + s = _to_str(s) for c in s: if c == '\n': continue