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 , Kerning , 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,11 +1273,11 @@ def embedTTFType42(font, characters, descriptor):
1270
1273
toUnicodeMapObject = self .reserveObject ('ToUnicode map' )
1271
1274
1272
1275
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 )
1274
1277
with _backend_pdf_ps .get_glyphs_subset (filename , subset_str ) as subset :
1275
1278
fontdata = _backend_pdf_ps .font_as_file (subset )
1276
1279
_log .debug (
1277
- "SUBSET %s %d -> %d" , filename ,
1280
+ "SUBSET %r %d -> %d" , filename ,
1278
1281
os .stat (filename ).st_size , fontdata .getbuffer ().nbytes
1279
1282
)
1280
1283
@@ -2218,18 +2221,18 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
2218
2221
self .file .output (Op .begin_text )
2219
2222
for font , fontsize , num , ox , oy in glyphs :
2220
2223
self .file ._character_tracker .track_glyph (font , num )
2221
- fontname = font .fname
2224
+ font_path = FontPath ( font .fname , font . face_index )
2222
2225
if not _font_supports_glyph (fonttype , num ):
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 , num ))
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 (num ), fonttype ),
2234
2237
Op .show )
2235
2238
self .file .output (Op .end_text )
@@ -2413,7 +2416,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
2413
2416
self .file .output (Op .begin_text )
2414
2417
prev_start_x = 0
2415
2418
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 )
2417
2421
self .file .output (ft_name , fontsize , Op .selectfont )
2418
2422
self ._setup_textpos (start_x , 0 , 0 , prev_start_x , 0 , 0 )
2419
2423
self .file .output (
@@ -2435,7 +2439,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
2435
2439
def _draw_xobject_glyph (self , font , fontsize , glyph_idx , x , y ):
2436
2440
"""Draw a multibyte character from a Type 3 font as an XObject."""
2437
2441
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 )
2439
2444
self .file .output (
2440
2445
Op .gsave ,
2441
2446
0.001 * fontsize , 0 , 0 , 0.001 * fontsize , x , y , Op .concat_matrix ,
0 commit comments