|
| 1 | +from io import BytesIO |
1 | 2 | import os |
2 | 3 | import shutil |
3 | 4 | import tempfile |
|
9 | 10 | from matplotlib.font_manager import ( |
10 | 11 | findfont, FontProperties, fontManager, json_dump, json_load, get_font, |
11 | 12 | get_fontconfig_fonts, is_opentype_cff_font) |
12 | | -from matplotlib import rc_context |
| 13 | +from matplotlib import pyplot as plt, rc_context |
13 | 14 |
|
14 | 15 | has_fclist = shutil.which('fc-list') is not None |
15 | 16 |
|
@@ -96,3 +97,19 @@ def test_hinting_factor(factor): |
96 | 97 | # Check that hinting only changes text layout by a small (10%) amount. |
97 | 98 | np.testing.assert_allclose(hinted_font.get_width_height(), expected, |
98 | 99 | rtol=0.1) |
| 100 | + |
| 101 | + |
| 102 | +@pytest.mark.xfail(not os.environ.get("TRAVIS"), reason="Font may be missing.") |
| 103 | +def test_find_ttc(): |
| 104 | + fp = FontProperties(family=["WenQuanYi Zen Hei"]) |
| 105 | + font = findfont(fp) |
| 106 | + assert os.path.basename(font) == "wqy-zenhei.ttc" |
| 107 | + |
| 108 | + fig, ax = plt.subplots() |
| 109 | + ax.text(.5, .5, "\N{KANGXI RADICAL DRAGON}", fontproperties=fp) |
| 110 | + fig.savefig(BytesIO(), format="raw") |
| 111 | + fig.savefig(BytesIO(), format="svg") |
| 112 | + with pytest.raises(RuntimeError): |
| 113 | + fig.savefig(BytesIO(), format="pdf") |
| 114 | + with pytest.raises(RuntimeError): |
| 115 | + fig.savefig(BytesIO(), format="ps") |
0 commit comments