|
4 | 4 | from pathlib import Path |
5 | 5 | import platform |
6 | 6 | import re |
7 | | -from xml.etree import ElementTree as ET |
| 7 | +import textwrap |
8 | 8 | from typing import Any |
| 9 | +from xml.etree import ElementTree as ET |
9 | 10 |
|
10 | 11 | import numpy as np |
11 | 12 | from packaging.version import parse as parse_version |
|
16 | 17 | import matplotlib as mpl |
17 | 18 | from matplotlib.testing.decorators import check_figures_equal, image_comparison |
18 | 19 | import matplotlib.pyplot as plt |
19 | | -from matplotlib import mathtext, _mathtext |
| 20 | +from matplotlib import font_manager as fm, mathtext, _mathtext |
| 21 | +from matplotlib.ft2font import LoadFlags |
20 | 22 |
|
21 | 23 | pyparsing_version = parse_version(pyparsing.__version__) |
22 | 24 |
|
@@ -558,3 +560,41 @@ def test_mathtext_operators(): |
558 | 560 | def test_boldsymbol(fig_test, fig_ref): |
559 | 561 | fig_test.text(0.1, 0.2, r"$\boldsymbol{\mathrm{abc0123\alpha}}$") |
560 | 562 | fig_ref.text(0.1, 0.2, r"$\mathrm{abc0123\alpha}$") |
| 563 | + |
| 564 | + |
| 565 | +def test_box_repr(): |
| 566 | + s = repr(_mathtext.Parser().parse( |
| 567 | + r"$\frac{1}{2}$", |
| 568 | + _mathtext.DejaVuSansFonts(fm.FontProperties(), LoadFlags.NO_HINTING), |
| 569 | + fontsize=12, dpi=100)) |
| 570 | + assert s == textwrap.dedent("""\ |
| 571 | + Hlist<w=9.49 h=16.08 d=6.64 s=0.00>[ |
| 572 | + Hlist<w=0.00 h=0.00 d=0.00 s=0.00>[], |
| 573 | + Hlist<w=9.49 h=16.08 d=6.64 s=0.00>[ |
| 574 | + Hlist<w=9.49 h=16.08 d=6.64 s=0.00>[ |
| 575 | + Vlist<w=7.40 h=22.72 d=0.00 s=6.64>[ |
| 576 | + HCentered<w=7.40 h=8.67 d=0.00 s=0.00>[ |
| 577 | + Glue, |
| 578 | + Hlist<w=7.40 h=8.67 d=0.00 s=0.00>[ |
| 579 | + `1`, |
| 580 | + k2.36, |
| 581 | + ], |
| 582 | + Glue, |
| 583 | + ], |
| 584 | + Vbox, |
| 585 | + Hrule, |
| 586 | + Vbox, |
| 587 | + HCentered<w=7.40 h=8.84 d=0.00 s=0.00>[ |
| 588 | + Glue, |
| 589 | + Hlist<w=7.40 h=8.84 d=0.00 s=0.00>[ |
| 590 | + `2`, |
| 591 | + k2.02, |
| 592 | + ], |
| 593 | + Glue, |
| 594 | + ], |
| 595 | + ], |
| 596 | + Hbox, |
| 597 | + ], |
| 598 | + ], |
| 599 | + Hlist<w=0.00 h=0.00 d=0.00 s=0.00>[], |
| 600 | + ]""") |
0 commit comments