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

Appearance settings

Commit 6a685d2

Browse filesBrowse files
committed
Add tests that hinting_factor works.
1 parent cd37119 commit 6a685d2
Copy full SHA for 6a685d2

File tree

Expand file treeCollapse file tree

2 files changed

+36
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+36
-0
lines changed

‎lib/matplotlib/tests/test_font_manager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_font_manager.py
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import tempfile
88
import warnings
99

10+
import numpy as np
1011
import pytest
1112

1213
from matplotlib.font_manager import (
@@ -86,3 +87,22 @@ def test_otf():
8687
@pytest.mark.skipif(not has_fclist, reason='no fontconfig installed')
8788
def test_get_fontconfig_fonts():
8889
assert len(get_fontconfig_fonts()) > 1
90+
91+
92+
@pytest.mark.parametrize('factor', [2, 4, 6, 8])
93+
def test_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 (10%) amount.
107+
np.testing.assert_allclose(hinted_font.get_width_height(), expected,
108+
rtol=0.1)

‎lib/matplotlib/tests/test_text.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_text.py
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
unicode_literals)
33

44
import six
5+
6+
import io
57
import warnings
68

79
import numpy as np
@@ -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+
def test_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=0.1)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.