8000 Merge pull request #2783 from jdeblese/master · matplotlib/matplotlib@e508f4e · GitHub
[go: up one dir, main page]

Skip to content

Commit e508f4e

Browse files
committed
Merge pull request #2783 from jdeblese/master
FIX: Use metric identifiers to parse an AFM character metric line Don't make assumptions about order.
2 parents e73142b + 5fc9809 commit e508f4e

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lib/matplotlib/afm.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,19 @@ def _parse_char_metrics(fh):
194194
line = fh.readline()
195195
if not line:
196196
break
197-
line = line.rstrip()
198-
if line.startswith(b'EndCharMetrics'):
197+
line = line.rstrip().decode('ascii') # Convert from byte-literal
198+
if line.startswith('EndCharMetrics'):
199199
return ascii_d, name_d
200-
vals = line.split(b';')[:4]
201-
if len(vals) != 4:
200+
# Split the metric line into a dictonary, keyed by metric identifiers
201+
vals = filter(lambda s: len(s) > 0, line.split(';'))
202+
vals = dict(map(lambda s: tuple(s.strip().split(' ', 1)), vals))
203+
# There may be other metrics present, but only these are needed
204+
if any([id not in vals.keys() for id in ('C', 'WX', 'N', 'B')]):
202205
raise RuntimeError('Bad char metrics line: %s' % line)
203-
num = _to_int(vals[0].split()[1])
204-
wx = _to_float(vals[1].split()[1])
205-
name = vals[2].split()[1]
206-
name = name.decode('ascii')
207-
bbox = _to_list_of_floats(vals[3][2:])
206+
num = _to_int(vals['C'])
207+
wx = _to_float(vals['WX'])
208+
name = vals['N']
209+
bbox = _to_list_of_floats(vals['B'])
208210
bbox = list(map(int, bbox))
209211
# Workaround: If the character name is 'Euro', give it the
210212
# corresponding character code, according to WinAnsiEncoding (see PDF

0 commit comments

Comments
 (0)
0