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

Function test_ft2font_charmaps

lib/matplotlib/tests/test_ft2font.py:268–355  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

266
267
268def test_ft2font_charmaps():
269 def enc(name):
270 # We don't expose the encoding enum from FreeType, but can generate it here.
271 # For DejaVu, there are 5 charmaps, but only 2 have enum entries in FreeType.
272 e = 0
273 for x in name:
274 e <<= 8
275 e += ord(x)
276 return e
277
278 file = fm.findfont('DejaVu Sans')
279 font = ft2font.FT2Font(file)
280 assert font.num_charmaps == 5
281
282 # Unicode.
283 font.select_charmap(enc('unic'))
284 unic = font.get_charmap()
285 font.set_charmap(0) # Unicode platform, Unicode BMP only.
286 after = font.get_charmap()
287 assert len(after) <= len(unic)
288 for chr, glyph in after.items():
289 assert unic[chr] == glyph == font.get_char_index(chr)
290 font.set_charmap(1) # Unicode platform, modern subtable.
291 after = font.get_charmap()
292 assert unic == after
293 font.set_charmap(3) # Windows platform, Unicode BMP only.
294 after = font.get_charmap()
295 assert len(after) <= len(unic)
296 for chr, glyph in after.items():
297 assert unic[chr] == glyph == font.get_char_index(chr)
298 font.set_charmap(4) # Windows platform, Unicode full repertoire, modern subtable.
299 after = font.get_charmap()
300 assert unic == after
301
302 # This is just a random sample from FontForge.
303 glyph_names = cast(dict[str, ft2font.GlyphIndexType], {
304 'non-existent-glyph-name': 0,
305 'plusminus': 115,
306 'Racute': 278,
307 'perthousand': 2834,
308 'seveneighths': 3057,
309 'triagup': 3721,
310 'uni01D3': 405,
311 'uni0417': 939,
312 'uni2A02': 4464,
313 'u1D305': 5410,
314 'u1F0A1': 5784,
315 })
316 for name, index in glyph_names.items():
317 assert font.get_name_index(name) == index
318 if name == 'non-existent-glyph-name':
319 name = '.notdef'
320 # This doesn't always apply, but it does for DejaVu Sans.
321 assert font.get_glyph_name(index) == name
322
323 # Apple Roman.
324 font.select_charmap(enc('armn'))
325 armn = font.get_charmap()

Callers

nothing calls this directly

Calls 4

encFunction · 0.85
findfontMethod · 0.80
get_char_indexMethod · 0.80
get_glyph_nameMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…