3333 RendererBase )
3434from matplotlib .backends .backend_mixed import MixedModeRenderer
3535from matplotlib .figure import Figure
36- from matplotlib .font_manager import get_font , fontManager as _fontManager
36+ from matplotlib .font_manager import FontPath , get_font , fontManager as _fontManager
3737from matplotlib ._afm import AFM
3838from matplotlib .ft2font import FT2Font , FaceFlags , Kerning , LoadFlags , StyleFlags
3939from matplotlib .transforms import Affine2D , BboxBase
@@ -910,8 +910,10 @@ def fontName(self, fontprop):
910910 as the filename of the font.
911911 """
912912
913- if isinstance (fontprop , str ):
913+ if isinstance (fontprop , FontPath ):
914914 filenames = [fontprop ]
915+ elif isinstance (fontprop , str ):
916+ filenames = [FontPath (fontprop , 0 )]
915917 elif mpl .rcParams ['pdf.use14corefonts' ]:
916918 filenames = _fontManager ._find_fonts_by_props (
917919 fontprop , fontext = 'afm' , directory = RendererPdf ._afm_font_dir
@@ -950,9 +952,8 @@ def writeFonts(self):
950952 for pdfname , dvifont in sorted (self ._dviFontInfo .items ()):
951953 _log .debug ('Embedding Type-1 font %s from dvi.' , dvifont .texname )
952954 fonts [pdfname ] = self ._embedTeXFont (dvifont )
953- for filename in sorted (self ._fontNames ):
954- Fx = self ._fontNames [filename ]
955- _log .debug ('Embedding font %s.' , filename )
955+ for filename , Fx in sorted (self ._fontNames .items ()):
956+ _log .debug ('Embedding font %r.' , filename )
956957 if filename .endswith ('.afm' ):
957958 # from pdf.use14corefonts
958959 _log .debug ('Writing AFM font.' )
@@ -1004,7 +1005,8 @@ def _embedTeXFont(self, dvifont):
10041005
10051006 # Reduce the font to only the glyphs used in the document, get the encoding
10061007 # for that subset, and compute various properties based on the encoding.
1007- chars = frozenset (self ._character_tracker .used [dvifont .fname ])
1008+ font_path = FontPath (dvifont .fname , dvifont .face_index )
1009+ chars = frozenset (self ._character_tracker .used [font_path ])
10081010 t1font = t1font .subset (chars , self ._get_subset_prefix (chars ))
10091011 fontdict ['BaseFont' ] = Name (t1font .prop ['FontName' ])
10101012 # createType1Descriptor writes the font data as a side effect
@@ -1113,6 +1115,7 @@ def _get_xobject_glyph_name(self, filename, glyph_name):
11131115 return "-" .join ([
11141116 Fx .name .decode (),
11151117 os .path .splitext (os .path .basename (filename ))[0 ],
1118+ str (filename .face_index ),
11161119 glyph_name ])
11171120
11181121 _identityToUnicodeCMap = b"""/CIDInit /ProcSet findresource begin
@@ -1270,11 +1273,11 @@ def embedTTFType42(font, characters, descriptor):
12701273 toUnicodeMapObject = self .reserveObject ('ToUnicode map' )
12711274
12721275 subset_str = "" .join (chr (c ) for c in characters )
1273- _log .debug ("SUBSET %s characters: %s" , filename , subset_str )
1276+ _log .debug ("SUBSET %r characters: %s" , filename , subset_str )
12741277 with _backend_pdf_ps .get_glyphs_subset (filename , subset_str ) as subset :
12751278 fontdata = _backend_pdf_ps .font_as_file (subset )
12761279 _log .debug (
1277- "SUBSET %s %d -> %d" , filename ,
1280+ "SUBSET %r %d -> %d" , filename ,
12781281 os .stat (filename ).st_size , fontdata .getbuffer ().nbytes
12791282 )
12801283
@@ -2218,18 +2221,18 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
22182221 self .file .output (Op .begin_text )
22192222 for font , fontsize , num , ox , oy in glyphs :
22202223 self .file ._character_tracker .track_glyph (font , num )
2221- fontname = font .fname
2224+ font_path = FontPath ( font .fname , font . face_index )
22222225 if not _font_supports_glyph (fonttype , num ):
22232226 # Unsupported chars (i.e. multibyte in Type 3 or beyond BMP in
22242227 # Type 42) must be emitted separately (below).
22252228 unsupported_chars .append ((font , fontsize , ox , oy , num ))
22262229 else :
22272230 self ._setup_textpos (ox , oy , 0 , oldx , oldy )
22282231 oldx , oldy = ox , oy
2229- if (fontname , fontsize ) != prev_font :
2230- self .file .output (self .file .fontName (fontname ), fontsize ,
2232+ if (font_path , fontsize ) != prev_font :
2233+ self .file .output (self .file .fontName (font_path ), fontsize ,
22312234 Op .selectfont )
2232- prev_font = fontname , fontsize
2235+ prev_font = font_path , fontsize
22332236 self .file .output (self .encode_string (chr (num ), fonttype ),
22342237 Op .show )
22352238 self .file .output (Op .end_text )
@@ -2413,7 +2416,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
24132416 self .file .output (Op .begin_text )
24142417 prev_start_x = 0
24152418 for ft_object , start_x , kerns_or_chars in singlebyte_chunks :
2416- ft_name = self .file .fontName (ft_object .fname )
2419+ font_path = FontPath (ft_object .fname , ft_object .face_index )
2420+ ft_name = self .file .fontName (font_path )
24172421 self .file .output (ft_name , fontsize , Op .selectfont )
24182422 self ._setup_textpos (start_x , 0 , 0 , prev_start_x , 0 , 0 )
24192423 self .file .output (
@@ -2435,7 +2439,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
24352439 def _draw_xobject_glyph (self , font , fontsize , glyph_idx , x , y ):
24362440 """Draw a multibyte character from a Type 3 font as an XObject."""
24372441 glyph_name = font .get_glyph_name (glyph_idx )
2438- name = self .file ._get_xobject_glyph_name (font .fname , glyph_name )
2442+ name = self .file ._get_xobject_glyph_name (FontPath (font .fname , font .face_index ),
2443+ glyph_name )
24392444 self .file .output (
24402445 Op .gsave ,
24412446 0.001 * fontsize , 0 , 0 , 0.001 * fontsize , x , y , Op .concat_matrix ,
0 commit comments