@@ -194,17 +194,19 @@ def _parse_char_metrics(fh):
194
194
line = fh .readline ()
195
195
if not line :
196
196
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' ):
199
199
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' )]):
202
205
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' ])
208
210
bbox = list (map (int , bbox ))
209
211
# Workaround: If the character name is 'Euro', give it the
210
212
# corresponding character code, according to WinAnsiEncoding (see PDF
0 commit comments