@@ -164,7 +164,7 @@ def _tokens(cls, text):
164164 if match :
165165 yield (cls ._whitespace , match .group ())
166166 pos += match .end ()
167- elif text [pos ] == '(' :
167+ elif text [pos ] == b '(' :
168168 start = pos
169169 pos += 1
170170 depth = 1
@@ -173,19 +173,19 @@ def _tokens(cls, text):
173173 if match is None :
174174 return
175175 pos += match .end ()
176- if match .group () == '(' :
176+ if match .group () == b '(' :
177177 depth += 1
178- elif match .group () == ')' :
178+ elif match .group () == b ')' :
179179 depth -= 1
180180 else : # a backslash - skip the next character
181181 pos += 1
182182 yield (cls ._string , text [start :pos ])
183- elif text [pos :pos + 2 ] in ('<<' , '>>' ):
183+ elif text [pos :pos + 2 ] in (b '<<' , b '>>' ):
184184 yield (cls ._delimiter , text [pos :pos + 2 ])
185185 pos += 2
186- elif text [pos ] == '<' :
186+ elif text [pos ] == b '<' :
187187 start = pos
188- pos += text [pos :].index ('>' )
188+ pos += text [pos :].index (b '>' )
189189 yield (cls ._string , text [start :pos ])
190190 else :
191191 match = cls ._token_re .match (text [pos :])
@@ -254,16 +254,16 @@ def _transformer(cls, tokens, slant, extend):
254254 def fontname (name ):
255255 result = name
256256 if slant :
257- result += b'_Slant_' + bytes (int (1000 * slant ))
257+ result += b'_Slant_' + str (int (1000 * slant )). encode ( 'latin-1' )
258258 if extend != 1.0 :
259- result += b'_Extend_' + bytes (int (1000 * extend ))
259+ result += b'_Extend_' + str (int (1000 * extend )). encode ( 'latin-1' )
260260 return result
261261
262262 def italicangle (angle ):
263- return bytes (float (angle ) - np .arctan (slant ) / np .pi * 180 )
263+ return str (float (angle ) - np .arctan (slant ) / np .pi * 180 ). encode ( 'latin-1' )
264264
265265 def fontmatrix (array ):
266- array = array .lstrip ('[' ).rstrip (']' ).strip ().split ()
266+ array = array .lstrip (b '[' ).rstrip (b ']' ).strip ().split ()
267267 array = [float (x ) for x in array ]
268268 oldmatrix = np .eye (3 , 3 )
269269 oldmatrix [0 :3 , 0 ] = array [::2 ]
@@ -274,7 +274,8 @@ def fontmatrix(array):
274274 newmatrix = np .dot (modifier , oldmatrix )
275275 array [::2 ] = newmatrix [0 :3 , 0 ]
276276 array [1 ::2 ] = newmatrix [0 :3 , 1 ]
277- return b'[' + ' ' .join (bytes (x ) for x in array ) + b']'
277+ as_string = u'[' + u' ' .join (str (x ) for x in array ) + u']'
278+ return as_string .encode ('latin-1' )
278279
279280 def replace (fun ):
280281 def replacer (tokens ):
@@ -284,26 +285,26 @@ def replacer(tokens):
284285 while token is cls ._whitespace :
285286 yield bytes (value )
286287 token , value = next (tokens )
287- if value != '[' : # name/number/etc.
288+ if value != b '[' : # name/number/etc.
288289 yield bytes (fun (value ))
289- else : # array, e.g., [1 2 3]
290- array = []
291- while value != ']' :
292- array += value
290+ else : # array, e.g., [1 2 3]
291+ result = b''
292+ while value != b ']' :
293+ result += value
293294 token , value = next (tokens )
294- array += value
295- yield bytes ( fun ('' . join ( array )) )
295+ result += value
296+ yield fun (result )
296297 return replacer
297298
298299 def suppress (tokens ):
299- for x in itertools .takewhile (lambda x : x [1 ] != 'def' , tokens ):
300+ for x in itertools .takewhile (lambda x : x [1 ] != b 'def' , tokens ):
300301 pass
301302 yield b''
302303
303- table = {'/FontName' : replace (fontname ),
304- '/ItalicAngle' : replace (italicangle ),
305- '/FontMatrix' : replace (fontmatrix ),
306- '/UniqueID' : suppress }
304+ table = {b '/FontName' : replace (fontname ),
305+ b '/ItalicAngle' : replace (italicangle ),
306+ b '/FontMatrix' : replace (fontmatrix ),
307+ b '/UniqueID' : suppress }
307308
308309 while True :
309310 token , value = next (tokens )
@@ -328,5 +329,5 @@ def transform(self, effects):
328329 transformed = self ._transformer (tokenizer ,
329330 slant = effects .get ('slant' , 0.0 ),
330331 extend = effects .get ('extend' , 1.0 ))
331- map (buffer .write , transformed )
332+ list ( map (buffer .write , transformed ) )
332333 return Type1Font ((buffer .getvalue (), self .parts [1 ], self .parts [2 ]))
0 commit comments