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

Method embedTTFType3

lib/matplotlib/backends/backend_pdf.py:1166–1235  ·  view source on GitHub ↗

The Type 3-specific part of embedding a Truetype font

(font, subset_index, charmap, descriptor)

Source from the content-addressed store, hash-verified

1164 return unicode_cmap
1165
1166 def embedTTFType3(font, subset_index, charmap, descriptor):
1167 """The Type 3-specific part of embedding a Truetype font"""
1168 widthsObject = self.reserveObject('font widths')
1169 fontdescObject = self.reserveObject('font descriptor')
1170 fontdictObject = self.reserveObject('font dictionary')
1171 charprocsObject = self.reserveObject('character procs')
1172 toUnicodeMapObject = self.reserveObject('ToUnicode map')
1173 differencesArray = []
1174 firstchar, lastchar = min(charmap), max(charmap)
1175 bbox = [cvt(x, nearest=False) for x in font.bbox]
1176
1177 fontdict = {
1178 'Type': Name('Font'),
1179 'BaseFont': ps_name,
1180 'FirstChar': firstchar,
1181 'LastChar': lastchar,
1182 'FontDescriptor': fontdescObject,
1183 'Subtype': Name('Type3'),
1184 'Name': descriptor['FontName'],
1185 'FontBBox': bbox,
1186 'FontMatrix': [.001, 0, 0, .001, 0, 0],
1187 'CharProcs': charprocsObject,
1188 'Encoding': {
1189 'Type': Name('Encoding'),
1190 'Differences': differencesArray},
1191 'Widths': widthsObject,
1192 'ToUnicode': toUnicodeMapObject,
1193 }
1194
1195 # Make the "Widths" array
1196 def get_char_width(charcode):
1197 width = font.load_glyph(
1198 charmap.get(charcode, 0),
1199 flags=LoadFlags.NO_SCALE | LoadFlags.NO_HINTING).horiAdvance
1200 return cvt(width)
1201 widths = [get_char_width(charcode)
1202 for charcode in range(firstchar, lastchar+1)]
1203 descriptor['MaxWidth'] = max(widths)
1204
1205 # Make the "Differences" array with the whole set of character codes that we
1206 # need from this font.
1207 differences = sorted([
1208 (ccode, font.get_glyph_name(gind)) for ccode, gind in charmap.items()
1209 ])
1210 last_c = -2
1211 for c, name in differences:
1212 if c != last_c + 1:
1213 differencesArray.append(c)
1214 differencesArray.append(Name(name))
1215 last_c = c
1216
1217 # Make the charprocs array.
1218 rawcharprocs = _get_pdf_charprocs(filename, charmap.values())
1219 charprocs = {}
1220 for charname in sorted(rawcharprocs):
1221 stream = rawcharprocs[charname]
1222 charprocObject = self.reserveObject('charProc')
1223 self.outputStream(charprocObject, stream)

Callers

nothing calls this directly

Calls 7

reserveObjectMethod · 0.95
outputStreamMethod · 0.95
writeObjectMethod · 0.95
NameClass · 0.85
_get_pdf_charprocsFunction · 0.85
get_glyph_nameMethod · 0.80
valuesMethod · 0.80

Tested by

no test coverage detected