@@ -222,30 +222,36 @@ def _font_to_ps_type42(font_path, chars, fh):
222222 subset_str = '' .join (chr (c ) for c in chars )
223223 _log .debug ("SUBSET %s characters: %s" , font_path , subset_str )
224224 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 :
228232 fontdata = _backend_pdf_ps .font_as_file (subset ).getvalue ()
229233 _log .debug (
230234 "SUBSET %s %d -> %d" , font_path , os .stat (font_path ).st_size ,
231235 len (fontdata )
232236 )
233- fh .write (_serialize_type42 (subset , fontdata ))
237+ fh .write (_serialize_type42 (font , subset , fontdata ))
234238 except RuntimeError :
235239 _log .warning (
236240 "The PostScript backend does not currently "
237241 "support the selected font (%s)." , font_path )
238242 raise
239243
240244
241- def _serialize_type42 (font , fontdata ):
245+ def _serialize_type42 (font , subset , fontdata ):
242246 """
243247 Output a PostScript Type-42 format representation of font
244248
245249 Parameters
246250 ----------
247251 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
249255 fontdata : bytes
250256 The raw font data in TTF format
251257
@@ -280,7 +286,7 @@ def _serialize_type42(font, fontdata):
280286 FontName currentdict end definefont pop
281287 """ )
282288
283- return fmt % (_charstrings (font ), _sfnts (fontdata , font , breakpoints ))
289+ return fmt % (_charstrings (subset ), _sfnts (fontdata , subset , breakpoints ))
284290
285291
286292def _version_and_breakpoints (loca , fontdata ):
0 commit comments