MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / embedTTFType42

Method embedTTFType42

lib/matplotlib/backends/backend_pdf.py:1237–1330  ·  view source on GitHub ↗

The Type 42-specific part of embedding a Truetype font

(font, subset_index, charmap, descriptor)

Source from the content-addressed store, hash-verified

1235 return fontdictObject
1236
1237 def embedTTFType42(font, subset_index, charmap, descriptor):
1238 """The Type 42-specific part of embedding a Truetype font"""
1239 fontdescObject = self.reserveObject('font descriptor')
1240 cidFontDictObject = self.reserveObject('CID font dictionary')
1241 type0FontDictObject = self.reserveObject('Type 0 font dictionary')
1242 cidToGidMapObject = self.reserveObject('CIDToGIDMap stream')
1243 fontfileObject = self.reserveObject('font file stream')
1244 wObject = self.reserveObject('Type 0 widths')
1245 toUnicodeMapObject = self.reserveObject('ToUnicode map')
1246
1247 _log.debug("SUBSET %r:%d characters: %s", filename, subset_index, charmap)
1248 with _backend_pdf_ps.get_glyphs_subset(filename,
1249 charmap.values()) as subset:
1250 fontdata = _backend_pdf_ps.font_as_file(subset)
1251 _log.debug(
1252 "SUBSET %r:%d %d -> %d", filename, subset_index,
1253 os.stat(filename).st_size, fontdata.getbuffer().nbytes
1254 )
1255
1256 # reload the font object from the subset
1257 # (all the necessary data could probably be obtained directly
1258 # using fontLib.ttLib)
1259 font = FT2Font(fontdata)
1260
1261 cidFontDict = {
1262 'Type': Name('Font'),
1263 'Subtype': Name('CIDFontType2'),
1264 'BaseFont': ps_name,
1265 'CIDSystemInfo': {
1266 'Registry': 'Adobe',
1267 'Ordering': 'Identity',
1268 'Supplement': 0},
1269 'FontDescriptor': fontdescObject,
1270 'W': wObject,
1271 'CIDToGIDMap': cidToGidMapObject
1272 }
1273
1274 type0FontDict = {
1275 'Type': Name('Font'),
1276 'Subtype': Name('Type0'),
1277 'BaseFont': ps_name,
1278 'Encoding': Name('Identity-H'),
1279 'DescendantFonts': [cidFontDictObject],
1280 'ToUnicode': toUnicodeMapObject
1281 }
1282
1283 # Make fontfile stream
1284 descriptor['FontFile2'] = fontfileObject
1285 self.outputStream(
1286 fontfileObject, fontdata.getvalue(),
1287 extra={'Length1': fontdata.getbuffer().nbytes})
1288
1289 # Make the 'W' (Widths) array and CidToGidMap at the same time.
1290 cid_to_gid_map = ['\0'] * 65536
1291 widths = []
1292 max_ccode = 0
1293 for ccode, gind in charmap.items():
1294 glyph = font.load_glyph(gind,

Callers

nothing calls this directly

Calls 6

reserveObjectMethod · 0.95
outputStreamMethod · 0.95
writeObjectMethod · 0.95
NameClass · 0.85
valuesMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected