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

Function test_glyphs_subset

lib/matplotlib/tests/test_backend_pdf.py:357–380  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

355
356
357def test_glyphs_subset():
358 fpath = str(_get_data_path("fonts/ttf/DejaVuSerif.ttf"))
359 chars = "these should be subsetted! 1234567890"
360
361 # non-subsetted FT2Font
362 nosubfont = FT2Font(fpath)
363 nosubfont.set_text(chars)
364 nosubcmap = nosubfont.get_charmap()
365
366 # subsetted FT2Font
367 glyph_indices = {nosubcmap[ord(c)] for c in chars}
368 with get_glyphs_subset(fm.FontPath(fpath, 0), glyph_indices) as subset:
369 subfont = FT2Font(font_as_file(subset))
370 subfont.set_text(chars)
371 subcmap = subfont.get_charmap()
372
373 # all unique chars must be available in subsetted font
374 assert {*chars} == {chr(key) for key in subcmap}
375
376 # subsetted font's charmap should have less entries
377 assert len(subcmap) < len(nosubcmap)
378
379 # since both objects are assigned same characters
380 assert subfont.get_num_glyphs() == nosubfont.get_num_glyphs()
381
382
383@image_comparison(["multi_font_type3.pdf"], style='mpl20')

Callers

nothing calls this directly

Calls 4

_get_data_pathFunction · 0.90
get_glyphs_subsetFunction · 0.90
font_as_fileFunction · 0.90
set_textMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…