@@ -191,8 +191,8 @@ def _font_to_ps_type42(font_path, chars, fh):
191
191
# https://github.com/matplotlib/matplotlib/issues/3135#issuecomment-571085541
192
192
if font_path .endswith ('.ttc' ):
193
193
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 ) :
196
196
fontdata = _backend_pdf_ps .font_as_file (subset ).getvalue ()
197
197
_log .debug (
198
198
"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):
201
201
fh .write (_serialize_type42 (font , subset , fontdata ))
202
202
except RuntimeError :
203
203
_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 )
206
206
raise
207
207
208
208
@@ -225,32 +225,33 @@ def _serialize_type42(font, subset, fontdata):
225
225
The Type-42 formatted font
226
226
"""
227
227
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
+ """ )
254
255
255
256
256
257
def _version_and_breakpoints (loca , fontdata ):
@@ -321,7 +322,7 @@ def _bounds(font):
321
322
return pen .bounds or (0 , 0 , 0 , 0 )
322
323
323
324
324
- def _charstrings (font ):
325
+ def _generate_charstrings (font ):
325
326
"""
326
327
Transform font glyphs into CharStrings
327
328
@@ -345,7 +346,7 @@ def _charstrings(font):
345
346
return s
346
347
347
348
348
- def _sfnts (fontdata , font , breakpoints ):
349
+ def _generate_sfnts (fontdata , font , breakpoints ):
349
350
"""
350
351
Transform font data into PostScript sfnts format.
351
352
0 commit comments