()
| 355 | |
| 356 | |
| 357 | def 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') |
nothing calls this directly
no test coverage detected
searching dependent graphs…