@@ -206,8 +206,8 @@ def _font_to_ps_type42(font_path, chars, fh):
206206 # https://github.com/matplotlib/matplotlib/issues/3135#issuecomment-571085541
207207 if font_path .endswith ('.ttc' ):
208208 kw ['fontNumber' ] = 0
209- with fontTools .ttLib .TTFont (font_path , ** kw ) as font , \
210- _backend_pdf_ps .get_glyphs_subset (font_path , subset_str ) as subset :
209+ with ( fontTools .ttLib .TTFont (font_path , ** kw ) as font ,
210+ _backend_pdf_ps .get_glyphs_subset (font_path , subset_str ) as subset ) :
211211 fontdata = _backend_pdf_ps .font_as_file (subset ).getvalue ()
212212 _log .debug (
213213 "SUBSET %s %d -> %d" , font_path , os .stat (font_path ).st_size ,
@@ -216,8 +216,8 @@ def _font_to_ps_type42(font_path, chars, fh):
216216 fh .write (_serialize_type42 (font , subset , fontdata ))
217217 except RuntimeError :
218218 _log .warning (
219- "The PostScript backend does not currently "
220- "support the selected font (%s)." , font_path )
219+ "The PostScript backend does not currently support the selected font (%s)." ,
220+ font_path )
221221 raise
222222
223223
@@ -240,32 +240,33 @@ def _serialize_type42(font, subset, fontdata):
240240 The Type-42 formatted font
241241 """
242242 version , breakpoints = _version_and_breakpoints (font .get ('loca' ), fontdata )
243- post , name = font ['post' ], font ['name' ]
244- fmt = textwrap .dedent (f"""
245- %%!PS-TrueTypeFont-{ version [0 ]} .{ version [1 ]} -{ font ['head' ].fontRevision :.7f}
246- 10 dict begin
247- /FontType 42 def
248- /FontMatrix [1 0 0 1 0 0] def
249- /FontName /{ name .getDebugName (6 )} def
250- /FontInfo 7 dict dup begin
251- /FullName ({ name .getDebugName (4 )} ) def
252- /FamilyName ({ name .getDebugName (1 )} ) def
253- /Version ({ name .getDebugName (5 )} ) def
254- /ItalicAngle { post .italicAngle } def
255- /isFixedPitch { 'true' if post .isFixedPitch else 'false' } def
256- /UnderlinePosition { post .underlinePosition } def
257- /UnderlineThickness { post .underlineThickness } def
258- end readonly def
259- /Encoding StandardEncoding def
260- /FontBBox [{ ' ' .join (str (x ) for x in _bounds (font ))} ] def
261- /PaintType 0 def
262- /CIDMap 0 def
263- %s
264- %s
265- FontName currentdict end definefont pop
266- """ )
267-
268- return fmt % (_charstrings (subset ), _sfnts (fontdata , subset , breakpoints ))
243+ post = font ['post' ]
244+ name = font ['name' ]
245+ chars = _generate_charstrings (subset )
246+ sfnts = _generate_sfnts (fontdata , subset , breakpoints )
247+ return textwrap .dedent (f"""
248+ %%!PS-TrueTypeFont-{ version [0 ]} .{ version [1 ]} -{ font ['head' ].fontRevision :.7f}
249+ 10 dict begin
250+ /FontType 42 def
251+ /FontMatrix [1 0 0 1 0 0] def
252+ /FontName /{ name .getDebugName (6 )} def
253+ /FontInfo 7 dict dup begin
254+ /FullName ({ name .getDebugName (4 )} ) def
255+ /FamilyName ({ name .getDebugName (1 )} ) def
256+ /Version ({ name .getDebugName (5 )} ) def
257+ /ItalicAngle { post .italicAngle } def
258+ /isFixedPitch { 'true' if post .isFixedPitch else 'false' } def
259+ /UnderlinePosition { post .underlinePosition } def
260+ /UnderlineThickness { post .underlineThickness } def
261+ end readonly def
262+ /Encoding StandardEncoding def
263+ /FontBBox [{ _nums_to_str (* _bounds (font ))} ] def
264+ /PaintType 0 def
265+ /CIDMap 0 def
266+ { chars }
267+ { sfnts }
268+ FontName currentdict end definefont pop
269+ """ )
269270
270271
271272def _version_and_breakpoints (loca , fontdata ):
@@ -336,7 +337,7 @@ def _bounds(font):
336337 return pen .bounds or (0 , 0 , 0 , 0 )
337338
338339
339- def _charstrings (font ):
340+ def _generate_charstrings (font ):
340341 """
341342 Transform font glyphs into CharStrings
342343
@@ -360,7 +361,7 @@ def _charstrings(font):
360361 return s
361362
362363
363- def _sfnts (fontdata , font , breakpoints ):
364+ def _generate_sfnts (fontdata , font , breakpoints ):
364365 """
365366 Transform font data into PostScript sfnts format.
366367
0 commit comments