@@ -960,9 +960,9 @@ def writeFonts(self):
960960 else :
961961 # a normal TrueType font
962962 _log .debug ('Writing TrueType font.' )
963- glyphs = self ._character_tracker .used .get (filename )
964- if glyphs :
965- fonts [Fx ] = self .embedTTF (filename , glyphs )
963+ charmap = self ._character_tracker .used .get (( filename , 0 ) )
964+ if charmap :
965+ fonts [Fx ] = self .embedTTF (filename , charmap )
966966 self .writeObject (self .fontObject , fonts )
967967
968968 def _write_afm_font (self , filename ):
@@ -1004,8 +1004,8 @@ def _embedTeXFont(self, dvifont):
10041004
10051005 # Reduce the font to only the glyphs used in the document, get the encoding
10061006 # for that subset, and compute various properties based on the encoding.
1007- chars = frozenset (self ._character_tracker .used [dvifont .fname ] )
1008- t1font = t1font .subset (chars , self ._get_subset_prefix (chars ))
1007+ glyphs = frozenset (self ._character_tracker .used [( dvifont .fname , 0 )]. values () )
1008+ t1font = t1font .subset (glyphs , self ._get_subset_prefix (glyphs ))
10091009 fontdict ['BaseFont' ] = Name (t1font .prop ['FontName' ])
10101010 # createType1Descriptor writes the font data as a side effect
10111011 fontdict ['FontDescriptor' ] = self .createType1Descriptor (t1font )
@@ -1136,7 +1136,7 @@ def _get_xobject_glyph_name(self, filename, glyph_name):
11361136end
11371137end"""
11381138
1139- def embedTTF (self , filename , glyphs ):
1139+ def embedTTF (self , filename , charmap ):
11401140 """Embed the TTF font from the named file into the document."""
11411141 font = get_font (filename )
11421142 fonttype = mpl .rcParams ['pdf.fonttype' ]
@@ -1152,7 +1152,7 @@ def cvt(length, upe=font.units_per_EM, nearest=True):
11521152 else :
11531153 return math .ceil (value )
11541154
1155- def embedTTFType3 (font , glyphs , descriptor ):
1155+ def embedTTFType3 (font , charmap , descriptor ):
11561156 """The Type 3-specific part of embedding a Truetype font"""
11571157 widthsObject = self .reserveObject ('font widths' )
11581158 fontdescObject = self .reserveObject ('font descriptor' )
@@ -1199,10 +1199,8 @@ def get_char_width(charcode):
11991199 # that we need from this font.
12001200 differences = []
12011201 multi_byte_chars = set ()
1202- charmap = {gind : ccode for ccode , gind in font .get_charmap ().items ()}
1203- for gind in glyphs :
1202+ for ccode , gind in charmap .items ():
12041203 glyph_name = font .get_glyph_name (gind )
1205- ccode = charmap .get (gind )
12061204 if ccode is not None and ccode <= 255 :
12071205 differences .append ((ccode , glyph_name ))
12081206 else :
@@ -1217,7 +1215,7 @@ def get_char_width(charcode):
12171215 last_c = c
12181216
12191217 # Make the charprocs array.
1220- rawcharprocs = _get_pdf_charprocs (filename , glyphs )
1218+ rawcharprocs = _get_pdf_charprocs (filename , charmap . values () )
12211219 charprocs = {}
12221220 for charname in sorted (rawcharprocs ):
12231221 stream = rawcharprocs [charname ]
@@ -1254,7 +1252,7 @@ def get_char_width(charcode):
12541252
12551253 return fontdictObject
12561254
1257- def embedTTFType42 (font , glyphs , descriptor ):
1255+ def embedTTFType42 (font , charmap , descriptor ):
12581256 """The Type 42-specific part of embedding a Truetype font"""
12591257 fontdescObject = self .reserveObject ('font descriptor' )
12601258 cidFontDictObject = self .reserveObject ('CID font dictionary' )
@@ -1264,8 +1262,9 @@ def embedTTFType42(font, glyphs, descriptor):
12641262 wObject = self .reserveObject ('Type 0 widths' )
12651263 toUnicodeMapObject = self .reserveObject ('ToUnicode map' )
12661264
1267- _log .debug ("SUBSET %s characters: %s" , filename , glyphs )
1268- with _backend_pdf_ps .get_glyphs_subset (filename , glyphs ) as subset :
1265+ _log .debug ("SUBSET %s characters: %s" , filename , charmap )
1266+ with _backend_pdf_ps .get_glyphs_subset (filename ,
1267+ charmap .values ()) as subset :
12691268 fontdata = _backend_pdf_ps .font_as_file (subset )
12701269 _log .debug (
12711270 "SUBSET %s %d -> %d" , filename ,
@@ -1313,11 +1312,9 @@ def embedTTFType42(font, glyphs, descriptor):
13131312 cid_to_gid_map = ['\0 ' ] * 65536
13141313 widths = []
13151314 max_ccode = 0
1316- charmap = {gind : ccode for ccode , gind in font .get_charmap ().items ()}
1317- for gind in glyphs :
1315+ for ccode , gind in charmap .items ():
13181316 glyph = font .load_glyph (gind ,
13191317 flags = LoadFlags .NO_SCALE | LoadFlags .NO_HINTING )
1320- ccode = charmap [gind ]
13211318 widths .append ((ccode , cvt (glyph .horiAdvance )))
13221319 if ccode < 65536 :
13231320 cid_to_gid_map [ccode ] = chr (gind )
@@ -1356,8 +1353,8 @@ def embedTTFType42(font, glyphs, descriptor):
13561353
13571354 # Add XObjects for unsupported chars
13581355 glyph_indices = [
1359- glyph_index for glyph_index in glyphs
1360- if not _font_supports_glyph (fonttype , charmap [ glyph_index ] )
1356+ glyph_index for ccode , glyph_index in charmap . items ()
1357+ if not _font_supports_glyph (fonttype , ccode )
13611358 ]
13621359
13631360 bbox = [cvt (x , nearest = False ) for x in full_font .bbox ]
@@ -1443,9 +1440,9 @@ def embedTTFType42(font, glyphs, descriptor):
14431440 }
14441441
14451442 if fonttype == 3 :
1446- return embedTTFType3 (font , glyphs , descriptor )
1443+ return embedTTFType3 (font , charmap , descriptor )
14471444 elif fonttype == 42 :
1448- return embedTTFType42 (font , glyphs , descriptor )
1445+ return embedTTFType42 (font , charmap , descriptor )
14491446
14501447 def alphaState (self , alpha ):
14511448 """Return name of an ExtGState that sets alpha to the given value."""
@@ -2210,7 +2207,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
22102207
22112208 self .file .output (Op .begin_text )
22122209 for font , fontsize , ccode , glyph_index , ox , oy in glyphs :
2213- self .file ._character_tracker .track_glyph (font , glyph_index )
2210+ self .file ._character_tracker .track_glyph (font , glyph_index , ccode )
22142211 fontname = font .fname
22152212 if not _font_supports_glyph (fonttype , ccode ):
22162213 # Unsupported chars (i.e. multibyte in Type 3 or beyond BMP in
0 commit comments