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

Apply hinting factor rcParam in all cases. #9481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 4, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add tests that hinting_factor works.
  • Loading branch information
QuLogic committed Oct 21, 2017
commit 6a685d2d3e6be4271db55c56eceb90c2a973c511
20 changes: 20 additions & 0 deletions 20 lib/matplotlib/tests/test_font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tempfile
import warnings

import numpy as np
import pytest

from matplotlib.font_manager import (
Expand Down Expand Up @@ -86,3 +87,22 @@ def test_otf():
@pytest.mark.skipif(not has_fclist, reason='no fontconfig installed')
def test_get_fontconfig_fonts():
assert len(get_fontconfig_fonts()) > 1


@pytest.mark.parametrize('factor', [2, 4, 6, 8])
def test_hinting_factor(factor):
font = findfont(FontProperties(family=["sans-serif"]))

font1 = get_font(font, hinting_factor=1)
font1.clear()
font1.set_size(12, 100)
font1.set_text('abc')
expected = font1.get_width_height()

hinted_font = get_font(font, hinting_factor=factor)
hinted_font.clear()
hinted_font.set_size(12, 100)
hinted_font.set_text('abc')
# Check that hinting only changes text layout by a small (10%) amount.
np.testing.assert_allclose(hinted_font.get_width_height(), expected,
rtol=0.1)
16 changes: 16 additions & 0 deletions 16 lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
unicode_literals)

import six

import io
import warnings

import numpy as np
Expand Down Expand Up @@ -448,3 +450,17 @@ def test_nonfinite_pos():
ax.text(0, np.nan, 'nan')
ax.text(np.inf, 0, 'inf')
fig.canvas.draw()


def test_hinting_factor_backends():
plt.rcParams['text.hinting_factor'] = 1
fig = plt.figure()
t = fig.text(0.5, 0.5, 'some text')

fig.savefig(io.BytesIO(), format='svg')
expected = t.get_window_extent().intervalx

fig.savefig(io.BytesIO(), format='png')
# Backends should apply hinting_factor consistently (within 10%).
np.testing.assert_allclose(t.get_window_extent().intervalx, expected,
rtol=0.1)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.