@@ -960,9 +960,9 @@ def writeFonts(self):
960
960
else :
961
961
# a normal TrueType font
962
962
_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 )
966
966
self .writeObject (self .fontObject , fonts )
967
967
968
968
def _write_afm_font (self , filename ):
@@ -1004,8 +1004,8 @@ def _embedTeXFont(self, dvifont):
1004
1004
1005
1005
# Reduce the font to only the glyphs used in the document, get the encoding
1006
1006
# 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 ))
1009
1009
fontdict ['BaseFont' ] = Name (t1font .prop ['FontName' ])
1010
1010
# createType1Descriptor writes the font data as a side effect
1011
1011
fontdict ['FontDescriptor' ] = self .createType1Descriptor (t1font )
@@ -1136,7 +1136,7 @@ def _get_xobject_glyph_name(self, filename, glyph_name):
1136
1136
end
1137
1137
end"""
1138
1138
1139
- def embedTTF (self , filename , glyphs ):
1139
+ def embedTTF (self , filename , charmap ):
1140
1140
"""Embed the TTF font from the named file into the document."""
1141
1141
font = get_font (filename )
1142
1142
fonttype = mpl .rcParams ['pdf.fonttype' ]
@@ -1152,7 +1152,7 @@ def cvt(length, upe=font.units_per_EM, nearest=True):
1152
1152
else :
1153
1153
return math .ceil (value )
1154
1154
1155
- def embedTTFType3 (font , glyphs , descriptor ):
1155
+ def embedTTFType3 (font , charmap , descriptor ):
1156
1156
"""The Type 3-specific part of embedding a Truetype font"""
1157
1157
widthsObject = self .reserveObject ('font widths' )
1158
1158
fontdescObject = self .reserveObject ('font descriptor' )
@@ -1199,10 +1199,8 @@ def get_char_width(charcode):
1199
1199
# that we need from this font.
1200
1200
differences = []
1201
1201
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 ():
1204
1203
glyph_name = font .get_glyph_name (gind )
1205
- ccode = charmap .get (gind )
1206
1204
if ccode is not None and ccode <= 255 :
1207
1205
differences .append ((ccode , glyph_name ))
1208
1206
else :
@@ -1217,7 +1215,7 @@ def get_char_width(charcode):
1217
1215
last_c = c
1218
1216
1219
1217
# Make the charprocs array.
1220
- rawcharprocs = _get_pdf_charprocs (filename , glyphs )
1218
+ rawcharprocs = _get_pdf_charprocs (filename , charmap . values () )
1221
1219
charprocs = {}
1222
1220
for charname in sorted (rawcharprocs ):
1223
1221
stream = rawcharprocs [charname ]
@@ -1254,7 +1252,7 @@ def get_char_width(charcode):
1254
1252
1255
1253
return fontdictObject
1256
1254
1257
- def embedTTFType42 (font , glyphs , descriptor ):
1255
+ def embedTTFType42 (font , charmap , descriptor ):
1258
1256
"""The Type 42-specific part of embedding a Truetype font"""
1259
1257
fontdescObject = self .reserveObject ('font descriptor' )
1260
1258
cidFontDictObject = self .reserveObject ('CID font dictionary' )
@@ -1264,8 +1262,9 @@ def embedTTFType42(font, glyphs, descriptor):
1264
1262
wObject = self .reserveObject ('Type 0 widths' )
1265
1263
toUnicodeMapObject = self .reserveObject ('ToUnicode map' )
1266
1264
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 :
1269
1268
fontdata = _backend_pdf_ps .font_as_file (subset )
1270
1269
_log .debug (
1271
1270
"SUBSET %s %d -> %d" , filename ,
@@ -1313,11 +1312,9 @@ def embedTTFType42(font, glyphs, descriptor):
1313
1312
cid_to_gid_map = ['\0 ' ] * 65536
1314
1313
widths = []
1315
1314
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 ():
1318
1316
glyph = font .load_glyph (gind ,
1319
1317
flags = LoadFlags .NO_SCALE | LoadFlags .NO_HINTING )
1320
- ccode = charmap [gind ]
1321
1318
widths .append ((ccode , cvt (glyph .horiAdvance )))
1322
1319
if ccode < 65536 :
1323
1320
cid_to_gid_map [ccode ] = chr (gind )
@@ -1356,8 +1353,8 @@ def embedTTFType42(font, glyphs, descriptor):
1356
1353
1357
1354
# Add XObjects for unsupported chars
1358
1355
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 )
1361
1358
]
1362
1359
1363
1360
bbox = [cvt (x , nearest = False ) for x in full_font .bbox ]
@@ -1443,9 +1440,9 @@ def embedTTFType42(font, glyphs, descriptor):
1443
1440
}
1444
1441
1445
1442
if fonttype == 3 :
1446
- return embedTTFType3 (font , glyphs , descriptor )
1443
+ return embedTTFType3 (font , charmap , descriptor )
1447
1444
elif fonttype == 42 :
1448
- return embedTTFType42 (font , glyphs , descriptor )
1445
+ return embedTTFType42 (font , charmap , descriptor )
1449
1446
1450
1447
def alphaState (self , alpha ):
1451
1448
"""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):
2210
2207
2211
2208
self .file .output (Op .begin_text )
2212
2209
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 )
2214
2211
fontname = font .fname
2215
2212
if not _font_supports_glyph (fonttype , ccode ):
2216
2213
# Unsupported chars (i.e. multibyte in Type 3 or beyond BMP in
0 commit comments