@@ -191,8 +191,8 @@ def _font_to_ps_type42(font_path, chars, fh):
191191 # https://github.com/matplotlib/matplotlib/issues/3135#issuecomment-571085541
192192 if font_path .endswith ('.ttc' ):
193193 kw ['fontNumber' ] = 0
194- with fontTools .ttLib .TTFont (font_path , ** kw ) as font , \
195- _backend_pdf_ps .get_glyphs_subset (font_path , subset_str ) as subset :
194+ with ( fontTools .ttLib .TTFont (font_path , ** kw ) as font ,
195+ _backend_pdf_ps .get_glyphs_subset (font_path , subset_str ) as subset ) :
196196 fontdata = _backend_pdf_ps .font_as_file (subset ).getvalue ()
197197 _log .debug (
198198 "SUBSET %s %d -> %d" , font_path , os .stat (font_path ).st_size ,
@@ -201,8 +201,8 @@ def _font_to_ps_type42(font_path, chars, fh):
201201 fh .write (_serialize_type42 (font , subset , fontdata ))
202202 except RuntimeError :
203203 _log .warning (
204- "The PostScript backend does not currently "
205- "support the selected font (%s)." , font_path )
204+ "The PostScript backend does not currently support the selected font (%s)." ,
205+ font_path )
206206 raise
207207
208208
@@ -225,32 +225,33 @@ def _serialize_type42(font, subset, fontdata):
225225 The Type-42 formatted font
226226 """
227227 version , breakpoints = _version_and_breakpoints (font .get ('loca' ), fontdata )
228- post , name = font ['post' ], font ['name' ]
229- fmt = textwrap .dedent (f"""
230- %%!PS-TrueTypeFont-{ version [0 ]} .{ version [1 ]} -{ font ['head' ].fontRevision :.7f}
231- 10 dict begin
232- /FontType 42 def
233- /FontMatrix [1 0 0 1 0 0] def
234- /FontName /{ name .getDebugName (6 )} def
235- /FontInfo 7 dict dup begin
236- /FullName ({ name .getDebugName (4 )} ) def
237- /FamilyName ({ name .getDebugName (1 )} ) def
238- /Version ({ name .getDebugName (5 )} ) def
239- /ItalicAngle { post .italicAngle } def
240- /isFixedPitch { 'true' if post .isFixedPitch else 'false' } def
241- /UnderlinePosition { post .underlinePosition } def
242- /UnderlineThickness { post .underlineThickness } def
243- end readonly def
244- /Encoding StandardEncoding def
245- /FontBBox [{ ' ' .join (str (x ) for x in _bounds (font ))} ] def
246- /PaintType 0 def
247- /CIDMap 0 def
248- %s
249- %s
250- FontName currentdict end definefont pop
251- """ )
252-
253- return fmt % (_charstrings (subset ), _sfnts (fontdata , subset , breakpoints ))
228+ post = font ['post' ]
229+ name = font ['name' ]
230+ chars = _generate_charstrings (subset )
231+ sfnts = _generate_sfnts (fontdata , subset , breakpoints )
232+ return textwrap .dedent (f"""
233+ %%!PS-TrueTypeFont-{ version [0 ]} .{ version [1 ]} -{ font ['head' ].fontRevision :.7f}
234+ 10 dict begin
235+ /FontType 42 def
236+ /FontMatrix [1 0 0 1 0 0] def
237+ /FontName /{ name .getDebugName (6 )} def
238+ /FontInfo 7 dict dup begin
239+ /FullName ({ name .getDebugName (4 )} ) def
240+ /FamilyName ({ name .getDebugName (1 )} ) def
241+ /Version ({ name .getDebugName (5 )} ) def
242+ /ItalicAngle { post .italicAngle } def
243+ /isFixedPitch { 'true' if post .isFixedPitch else 'false' } def
244+ /UnderlinePosition { post .underlinePosition } def
245+ /UnderlineThickness { post .underlineThickness } def
246+ end readonly def
247+ /Encoding StandardEncoding def
248+ /FontBBox [{ _nums_to_str (* _bounds (font ))} ] def
249+ /PaintType 0 def
250+ /CIDMap 0 def
251+ { chars }
252+ { sfnts }
253+ FontName currentdict end definefont pop
254+ """ )
254255
255256
256257def _version_and_breakpoints (loca , fontdata ):
@@ -321,7 +322,7 @@ def _bounds(font):
321322 return pen .bounds or (0 , 0 , 0 , 0 )
322323
323324
324- def _charstrings (font ):
325+ def _generate_charstrings (font ):
325326 """
326327 Transform font glyphs into CharStrings
327328
@@ -345,7 +346,7 @@ def _charstrings(font):
345346 return s
346347
347348
348- def _sfnts (fontdata , font , breakpoints ):
349+ def _generate_sfnts (fontdata , font , breakpoints ):
349350 """
350351 Transform font data into PostScript sfnts format.
351352
0 commit comments