Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Deprecate hinting_factor. #14538

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions doc/api/next_api_changes/2019-06-14-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Deprecation of hinting_factor
`````````````````````````````

The ``hinting_factor`` parameter of `.ft2font.FT2Font` and `.font_manager.get_font`,
and :rc:`test.hinting_factor`, are deprecated. Their default value have been
changed to 1, which will be the only value supported in after the deprecation
period ends.
1 change: 1 addition & 0 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ def gen_candidates():
# listed in the rcParams (not included in _all_deprecated).
# Values are tuples of (version,)
_deprecated_remain_as_none = {
'text.hinting_factor': ('3.2',),
'text.latex.unicode': ('3.0',),
'savefig.frameon': ('3.1',),
'verbose.fileo': ('3.1',),
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,9 +1270,11 @@ def is_opentype_cff_font(filename):
fontManager = None


@cbook._delete_parameter("3.2", "hinting_factor")
def get_font(filename, hinting_factor=None):
if hinting_factor is None:
hinting_factor = rcParams['text.hinting_factor']
with cbook._suppress_matplotlib_deprecation_warning():
hinting_factor = rcParams['text.hinting_factor']
return _get_font(os.fspath(filename), hinting_factor)


Expand Down
3 changes: 0 additions & 3 deletions lib/matplotlib/mpl-data/stylelib/_classic_test.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ text.hinting : auto # May be one of the following:
# or the autohinter if none is available.
# For backward compatibility, this value may also be
# True === 'auto' or False === 'none'.
text.hinting_factor : 8 # Specifies the amount of softness for hinting in the
# horizontal direction. A value of 1 will hint to full
# pixels. A value of 2 will hint to half pixels etc.

text.antialiased : True # If True (default), the text will be antialiased.
# This only affects the Agg backend.
Expand Down
2 changes: 0 additions & 2 deletions lib/matplotlib/mpl-data/stylelib/bmh.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ patch.facecolor: blue
patch.edgecolor: eeeeee
patch.antialiased: True

text.hinting_factor : 8

mathtext.fontset : cm

axes.facecolor: eeeeee
Expand Down
3 changes: 0 additions & 3 deletions lib/matplotlib/mpl-data/stylelib/classic.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ text.hinting : auto # May be one of the following:
# or the autohinter if none is available.
# For backward compatibility, this value may also be
# True === 'auto' or False === 'none'.
text.hinting_factor : 8 # Specifies the amount of softness for hinting in the
# horizontal direction. A value of 1 will hint to full
# pixels. A value of 2 will hint to half pixels etc.

text.antialiased : True # If True (default), the text will be antialiased.
# This only affects the Agg backend.
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ def _validate_linestyle(ls):
'text.latex.preamble': ['', _validate_tex_preamble],
'text.latex.preview': [False, validate_bool],
'text.hinting': ['auto', validate_hinting],
'text.hinting_factor': [8, validate_int],
'text.hinting_factor': [1, validate_int],
'text.antialiased': [True, validate_bool],

'mathtext.cal': ['cursive', validate_font_properties],
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6163,8 +6163,8 @@ def test_normal_axes():

# test the axis bboxes
target = [
[123.375, 75.88888888888886, 983.25, 33.0],
[85.51388888888889, 99.99999999999997, 53.375, 993.0]
[123.5, 75.88888888888886, 983.0, 33.0],
[85.89, 100.0, 53.0, 993.0]
]
for nn, b in enumerate(bbaxis):
targetbb = mtransforms.Bbox.from_bounds(*target[nn])
Expand All @@ -6184,7 +6184,7 @@ def test_normal_axes():
targetbb = mtransforms.Bbox.from_bounds(*target)
assert_array_almost_equal(bbax.bounds, targetbb.bounds, decimal=2)

target = [85.5138, 75.88888, 1021.11, 1017.11]
target = [85.89, 75.88888, 1020.61, 1017.11]
targetbb = mtransforms.Bbox.from_bounds(*target)
assert_array_almost_equal(bbtb.bounds, targetbb.bounds, decimal=2)

Expand Down Expand Up @@ -6311,7 +6311,7 @@ def test_get_tightbbox_polar():
fig.canvas.draw()
bb = ax.get_tightbbox(fig.canvas.get_renderer())
assert_allclose(bb.extents,
[107.7778, 29.2778, 539.7847, 450.7222], rtol=1e-03)
[108.7778, 29.2778, 539.2222, 450.7222], rtol=1e-03)


@check_figures_equal(extensions=["png"])
Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,12 @@ def test_tightbbox():
ax.set_xlim(0, 1)
t = ax.text(1., 0.5, 'This dangles over end')
renderer = fig.canvas.get_renderer()
x1Nom0 = 9.035 # inches
x1Nom0 = 8.9625 # inches
assert abs(t.get_tightbbox(renderer).x1 - x1Nom0 * fig.dpi) < 2
assert abs(ax.get_tightbbox(renderer).x1 - x1Nom0 * fig.dpi) < 2
assert abs(fig.get_tightbbox(renderer).x1 - x1Nom0) < 0.05
assert abs(fig.get_tightbbox(renderer).x0 - 0.679) < 0.05
# now exclude t from the tight bbox so now the bbox is quite a bit
# smaller
# now exclude t from the tight bbox so now the bbox is quite a bit smaller
t.set_in_layout(False)
x1Nom = 7.333
assert abs(ax.get_tightbbox(renderer).x1 - x1Nom * fig.dpi) < 2
Expand Down
28 changes: 15 additions & 13 deletions lib/matplotlib/tests/test_font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,21 @@ def test_get_fontconfig_fonts():
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)
with cbook._suppress_matplotlib_deprecation_warning():

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)


@pytest.mark.skipif(sys.platform != "win32",
Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ def test_nonfinite_pos():


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

Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/tests/test_tightlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_tight_layout9():


def test_outward_ticks():
'Test automatic use of tight_layout'
"""Test automatic use of tight_layout."""
fig = plt.figure()
ax = fig.add_subplot(221)
ax.xaxis.set_tick_params(tickdir='out', length=16, width=3)
Expand All @@ -172,10 +172,10 @@ def test_outward_ticks():
plt.tight_layout()
# These values were obtained after visual checking that they correspond
# to a tight layouting that did take the ticks into account.
ans = [[[0.091, 0.607], [0.433, 0.933]],
[[0.579, 0.607], [0.922, 0.933]],
[[0.091, 0.140], [0.433, 0.466]],
[[0.579, 0.140], [0.922, 0.466]]]
ans = [[[0.088, 0.607], [0.433, 0.933]],
[[0.577, 0.607], [0.922, 0.933]],
[[0.088, 0.140], [0.433, 0.466]],
[[0.577, 0.140], [0.922, 0.466]]]
for nn, ax in enumerate(fig.axes):
assert_array_equal(np.round(ax.get_position().get_points(), 3),
ans[nn])
Expand Down
3 changes: 0 additions & 3 deletions matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,6 @@
# or the autohinter if none is available.
## For backward compatibility, this value may also be
## True === 'auto' or False === 'none'.
#text.hinting_factor : 8 ## Specifies the amount of softness for hinting in the
## horizontal direction. A value of 1 will hint to full
## pixels. A value of 2 will hint to half pixels etc.
#text.antialiased : True ## If True (default), the text will be antialiased.
## This only affects the Agg backend.

Expand Down
8 changes: 7 additions & 1 deletion src/ft2font_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,14 +515,20 @@ static int PyFT2Font_init(PyFT2Font *self, PyObject *args, PyObject *kwds)
{
PyObject *fname;
FT_Open_Args open_args;
long hinting_factor = 8;
long hinting_factor = -0xdeadbeef;
const char *names[] = { "filename", "hinting_factor", NULL };

if (!PyArg_ParseTupleAndKeywords(
args, kwds, "O|l:FT2Font", (char **)names, &fname, &hinting_factor)) {
return -1;
}

if (hinting_factor == -0xdeadbeef) {
hinting_factor = 1;
} else {
PyErr_WarnEx(PyExc_DeprecationWarning, "The 'hinting_factor' parameter is deprecated.", 1);
}

if (!convert_open_args(self, fname, &open_args)) {
return -1;
}
Expand Down