Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdf5558c

Browse files
committed
Add tests that hinting_factor works.
1 parentcd37119 commitdf5558c

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

‎lib/matplotlib/tests/test_font_manager.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
importtempfile
88
importwarnings
99

10+
importnumpyasnp
1011
importpytest
1112

1213
frommatplotlib.font_managerimport (
@@ -86,3 +87,22 @@ def test_otf():
8687
@pytest.mark.skipif(nothas_fclist,reason='no fontconfig installed')
8788
deftest_get_fontconfig_fonts():
8889
assertlen(get_fontconfig_fonts())>1
90+
91+
92+
@pytest.mark.parametrize('factor', [2,4,6,8])
93+
deftest_hinting_factor(factor):
94+
font=findfont(FontProperties(family=["sans-serif"]))
95+
96+
font1=get_font(font,hinting_factor=1)
97+
font1.clear()
98+
font1.set_size(12,100)
99+
font1.set_text('abc')
100+
expected=font1.get_width_height()
101+
102+
hinted_font=get_font(font,hinting_factor=factor)
103+
hinted_font.clear()
104+
hinted_font.set_size(12,100)
105+
hinted_font.set_text('abc')
106+
# Check that hinting only changes text layout by a small (5%) amount.
107+
np.testing.assert_allclose(hinted_font.get_width_height(),expected,
108+
rtol=5e-2)

‎lib/matplotlib/tests/test_text.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
unicode_literals)
33

44
importsix
5+
6+
importio
57
importwarnings
68

79
importnumpyasnp
@@ -448,3 +450,17 @@ def test_nonfinite_pos():
448450
ax.text(0,np.nan,'nan')
449451
ax.text(np.inf,0,'inf')
450452
fig.canvas.draw()
453+
454+
455+
deftest_hinting_factor_backends():
456+
plt.rcParams['text.hinting_factor']=1
457+
fig=plt.figure()
458+
t=fig.text(0.5,0.5,'some text')
459+
460+
fig.savefig(io.BytesIO(),format='svg')
461+
expected=t.get_window_extent().intervalx
462+
463+
fig.savefig(io.BytesIO(),format='png')
464+
# Backends should apply hinting_factor consistently (within 10%).
465+
np.testing.assert_allclose(t.get_window_extent().intervalx,expected,
466+
rtol=1e-1)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp