@@ -222,30 +222,36 @@ def _font_to_ps_type42(font_path, chars, fh):
222
222
subset_str = '' .join (chr (c ) for c in chars )
223
223
_log .debug ("SUBSET %s characters: %s" , font_path , subset_str )
224
224
try :
225
- with _backend_pdf_ps .get_glyphs_subset (
226
- font_path , subset_str
227
- ) as subset :
225
+ kw = {}
226
+ if font_path .endswith ('.ttc' ):
227
+ # fix this once we support loading more fonts from a collection
228
+ # https://github.com/matplotlib/matplotlib/issues/3135#issuecomment-571085541
229
+ kw ['fontNumber' ] = 0
230
+ with fontTools .ttLib .TTFont (font_path , ** kw ) as font , \
231
+ _backend_pdf_ps .get_glyphs_subset (font_path , subset_str ) as subset :
228
232
fontdata = _backend_pdf_ps .font_as_file (subset ).getvalue ()
229
233
_log .debug (
230
234
"SUBSET %s %d -> %d" , font_path , os .stat (font_path ).st_size ,
231
235
len (fontdata )
232
236
)
233
- fh .write (_serialize_type42 (subset , fontdata ))
237
+ fh .write (_serialize_type42 (font , subset , fontdata ))
234
238
except RuntimeError :
235
239
_log .warning (
236
240
"The PostScript backend does not currently "
237
241
"support the selected font (%s)." , font_path )
238
242
raise
239
243
240
244
241
- def _serialize_type42 (font , fontdata ):
245
+ def _serialize_type42 (font , subset , fontdata ):
242
246
"""
243
247
Output a PostScript Type-42 format representation of font
244
248
245
249
Parameters
246
250
----------
247
251
font : fontTools.ttLib.ttFont.TTFont
248
- The font object
252
+ The original font object
253
+ subset : fontTools.ttLib.ttFont.TTFont
254
+ The subset font object
249
255
fontdata : bytes
250
256
The raw font data in TTF format
251
257
@@ -280,7 +286,7 @@ def _serialize_type42(font, fontdata):
280
286
FontName currentdict end definefont pop
281
287
""" )
282
288
283
- return fmt % (_charstrings (font ), _sfnts (fontdata , font , breakpoints ))
289
+ return fmt % (_charstrings (subset ), _sfnts (fontdata , subset , breakpoints ))
284
290
285
291
286
292
def _version_and_breakpoints (loca , fontdata ):
0 commit comments