(fallback, fontlist)
| 449 | [("cm", ['DejaVu Sans', 'mpltest', 'STIXGeneral', 'cmr10', 'STIXGeneral']), |
| 450 | ("stix", ['DejaVu Sans', 'mpltest', 'STIXGeneral', 'STIXGeneral', 'STIXGeneral'])]) |
| 451 | def test_mathtext_fallback(fallback, fontlist): |
| 452 | mpl.font_manager.fontManager.addfont( |
| 453 | (Path(__file__).resolve().parent / 'data/mpltest.ttf')) |
| 454 | mpl.rcParams["svg.fonttype"] = 'none' |
| 455 | mpl.rcParams['mathtext.fontset'] = 'custom' |
| 456 | mpl.rcParams['mathtext.rm'] = 'mpltest' |
| 457 | mpl.rcParams['mathtext.it'] = 'mpltest:italic' |
| 458 | mpl.rcParams['mathtext.bf'] = 'mpltest:bold' |
| 459 | mpl.rcParams['mathtext.bfit'] = 'mpltest:italic:bold' |
| 460 | mpl.rcParams['mathtext.fallback'] = fallback |
| 461 | |
| 462 | test_str = r'a$A\AA\breve\gimel$' |
| 463 | |
| 464 | buff = io.BytesIO() |
| 465 | fig, ax = plt.subplots() |
| 466 | fig.text(.5, .5, test_str, fontsize=40, ha='center') |
| 467 | fig.savefig(buff, format="svg") |
| 468 | tspans = (ET.fromstring(buff.getvalue()) |
| 469 | .findall(".//{http://www.w3.org/2000/svg}tspan[@style]")) |
| 470 | char_fonts = [ |
| 471 | re.search(r"font-family: '([\w ]+)'", tspan.attrib["style"]).group(1) |
| 472 | for tspan in tspans] |
| 473 | assert char_fonts == fontlist, f'Expected {fontlist}, got {char_fonts}' |
| 474 | mpl.font_manager.fontManager.ttflist.pop() |
| 475 | |
| 476 | |
| 477 | def test_math_to_image(tmp_path): |
nothing calls this directly
no test coverage detected
searching dependent graphs…