33
33
RendererBase )
34
34
from matplotlib .backends .backend_mixed import MixedModeRenderer
35
35
from 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
37
37
from matplotlib ._afm import AFM
38
38
from matplotlib .ft2font import FT2Font , FaceFlags , LoadFlags , StyleFlags
39
39
from matplotlib .transforms import Affine2D , BboxBase
@@ -910,8 +910,10 @@ def fontName(self, fontprop):
910
910
as the filename of the font.
911
911
"""
912
912
913
- if isinstance (fontprop , str ):
913
+ if isinstance (fontprop , FontPath ):
914
914
filenames = [fontprop ]
915
+ elif isinstance (fontprop , str ):
916
+ filenames = [FontPath (fontprop , 0 )]
915
917
elif mpl .rcParams ['pdf.use14corefonts' ]:
916
918
filenames = _fontManager ._find_fonts_by_props (
917
919
fontprop , fontext = 'afm' , directory = RendererPdf ._afm_font_dir
@@ -950,9 +952,8 @@ def writeFonts(self):
950
952
for pdfname , dvifont in sorted (self ._dviFontInfo .items ()):
951
953
_log .debug ('Embedding Type-1 font %s from dvi.' , dvifont .texname )
952
954
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 )
956
957
if filename .endswith ('.afm' ):
957
958
# from pdf.use14corefonts
958
959
_log .debug ('Writing AFM font.' )
@@ -1004,7 +1005,8 @@ def _embedTeXFont(self, dvifont):
1004
1005
1005
1006
# Reduce the font to only the glyphs used in the document, get the encoding
1006
1007
# 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 ])
1008
1010
t1font = t1font .subset (chars , self ._get_subset_prefix (chars ))
1009
1011
fontdict ['BaseFont' ] = Name (t1font .prop ['FontName' ])
1010
1012
# createType1Descriptor writes the font data as a side effect
@@ -1113,6 +1115,7 @@ def _get_xobject_glyph_name(self, filename, glyph_name):
1113
1115
return "-" .join ([
1114
1116
Fx .name .decode (),
1115
1117
os .path .splitext (os .path .basename (filename ))[0 ],
1118
+ str (filename .face_index ),
1116
1119
glyph_name ])
1117
1120
1118
1121
_identityToUnicodeCMap = b"""/CIDInit /ProcSet findresource begin
@@ -1270,7 +1273,7 @@ def embedTTFType42(font, glyphs, descriptor):
1270
1273
with _backend_pdf_ps .get_glyphs_subset (filename , glyphs ) as subset :
1271
1274
fontdata = _backend_pdf_ps .font_as_file (subset )
1272
1275
_log .debug (
1273
- "SUBSET %s %d -> %d" , filename ,
1276
+ "SUBSET %r %d -> %d" , filename ,
1274
1277
os .stat (filename ).st_size , fontdata .getbuffer ().nbytes
1275
1278
)
1276
1279
@@ -2214,22 +2217,22 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
2214
2217
self .file .output (Op .begin_text )
2215
2218
for font , fontsize , glyph_index , ox , oy in glyphs :
2216
2219
self .file ._character_tracker .track_glyph (font , glyph_index )
2217
- fontname = font .fname
2218
- if font not in font_charmaps :
2219
- font_charmaps [font ] = {gind : ccode
2220
- for ccode , gind in font .get_charmap ().items ()}
2221
- ccode = font_charmaps [font ].get (glyph_index )
2220
+ font_path = FontPath ( font .fname , font . face_index )
2221
+ if font_path not in font_charmaps :
2222
+ font_charmaps [font_path ] = {
2223
+ gind : ccode for ccode , gind in font .get_charmap ().items ()}
2224
+ ccode = font_charmaps [font_path ].get (glyph_index )
2222
2225
if ccode is None or not _font_supports_glyph (fonttype , ccode ):
2223
2226
# Unsupported chars (i.e. multibyte in Type 3 or beyond BMP in
2224
2227
# Type 42) must be emitted separately (below).
2225
2228
unsupported_chars .append ((font , fontsize , ox , oy , glyph_index ))
2226
2229
else :
2227
2230
self ._setup_textpos (ox , oy , 0 , oldx , oldy )
2228
2231
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 ,
2231
2234
Op .selectfont )
2232
- prev_font = fontname , fontsize
2235
+ prev_font = font_path , fontsize
2233
2236
self .file .output (self .encode_string (chr (ccode ), fonttype ),
2234
2237
Op .show )
2235
2238
self .file .output (Op .end_text )
@@ -2419,7 +2422,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
2419
2422
self .file .output (Op .begin_text )
2420
2423
prev_start_x = 0
2421
2424
for ft_object , start_x , kerns_or_chars in singlebyte_chunks :
2422
- ft_name = self .file .fontName (ft_object .fname )
2425
+ font_path = FontPath (ft_object .fname , ft_object .face_index )
2426
+ ft_name = self .file .fontName (font_path )
2423
2427
self .file .output (ft_name , fontsize , Op .selectfont )
2424
2428
self ._setup_textpos (start_x , 0 , 0 , prev_start_x , 0 , 0 )
2425
2429
self .file .output (
@@ -2441,7 +2445,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
2441
2445
def _draw_xobject_glyph (self , font , fontsize , glyph_index , x , y ):
2442
2446
"""Draw a multibyte character from a Type 3 font as an XObject."""
2443
2447
glyph_name = font .get_glyph_name (glyph_index )
2444
- name = self .file ._get_xobject_glyph_name (font .fname , glyph_name )
2448
+ name = self .file ._get_xobject_glyph_name (FontPath (font .fname , font .face_index ),
2449
+ glyph_name )
2445
2450
self .file .output (
2446
2451
Op .gsave ,
2447
2452
0.001 * fontsize , 0 , 0 , 0.001 * fontsize , x , y , Op .concat_matrix ,
0 commit comments