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

Skip to content

Commit a7cfac8

Browse files
committed
Drop support for font hinting factor
In #9681 we decided that the hinting factor is not needed with modern font rendering engines, but we only set our defaults to 1. The classic style remained as 8, but our internal testing framework then reset that to 1 as well. Unfortunately, with the new pipeline, anything other than 1 is broken (cf. SciTools/cartopy#2666), and we were just not seeing it because of the testing override. As we expect downstreams to have to update results for all the rest of the font changes, there's not much need to preserve this functionality. So like the kerning factor, deprecate the hinting factor setting/parameters, and drop all related code.
1 parent 389efd5 commit a7cfac8

21 files changed

Lines changed: 57 additions & 114 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Font hinting factor is deprecated
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Due to internal changes to support complex text rendering, the hinting factor on fonts is
5+
no longer used. Setting the ``text.hinting_factor`` rcParam to any value other than None
6+
is deprecated, and the rcParam will be removed in the future. Likewise, passing the
7+
``hinting_factor`` argument to the `.FT2Font` constructor is deprecated.

lib/matplotlib/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,8 @@ def __setitem__(self, key, val):
779779
cval = valid_key(val)
780780
except ValueError as ve:
781781
raise ValueError(f"Key {key}: {ve}") from None
782-
if key == "text.kerning_factor" and cval is not None:
783-
_api.warn_deprecated("3.11", name="text.kerning_factor", obj_type="rcParam")
782+
if key in {"text.hinting_factor", "text.kerning_factor"} and cval is not None:
783+
_api.warn_deprecated("3.11", name=key, obj_type="rcParam")
784784
self._set(key, cval)
785785

786786
def __getitem__(self, key):

lib/matplotlib/backends/backend_agg.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,9 @@ def _draw_text_glyphs_and_boxes(self, gc, x, y, angle, glyphs, boxes):
179179
load_flags = get_hinting_flag()
180180
for font, size, glyph_index, slant, extend, dx, dy in glyphs: # dy is upwards.
181181
font.set_size(size, self.dpi)
182-
hf = font._hinting_factor
183182
font._set_transform(
184183
(0x10000 * np.array([[cos, -sin], [sin, cos]])
185-
@ [[extend, extend * slant], [0, 1]]
186-
@ [[1 / hf, 0], [0, 1]]).round().astype(int),
184+
@ [[extend, extend * slant], [0, 1]]).round().astype(int),
187185
[round(0x40 * (x + dx * cos - dy * sin)),
188186
# FreeType's y is upwards.
189187
round(0x40 * (self.height - y + dx * sin + dy * cos))]

lib/matplotlib/backends/backend_pdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ def _flush(self):
597597

598598

599599
def _get_pdf_charprocs(font_path, glyph_indices):
600-
font = get_font(font_path, hinting_factor=1)
600+
font = get_font(font_path)
601601
conv = 1000 / font.units_per_EM # Conversion to PS units (1/1000's).
602602
procs = {}
603603
for glyph_index in glyph_indices:

lib/matplotlib/backends/backend_ps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def _font_to_ps_type3(font_path, subset_index, glyph_indices):
107107
The string representation of a Type 3 font, which can be included
108108
verbatim into a PostScript file.
109109
"""
110-
font = get_font(font_path, hinting_factor=1)
110+
font = get_font(font_path)
111111

112112
preamble = """\
113113
%!PS-Adobe-3.0 Resource-Font

lib/matplotlib/dviread.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ def get_metrics(self, idx):
10261026

10271027
class TtfMetrics:
10281028
def __init__(self, filename):
1029-
self._face = font_manager.get_font(filename, hinting_factor=1)
1029+
self._face = font_manager.get_font(filename)
10301030

10311031
def get_metrics(self, idx):
10321032
# _mul1220 uses a truncating bitshift for compatibility with dvitype.

lib/matplotlib/font_manager.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,11 +1731,11 @@ def is_opentype_cff_font(filename):
17311731

17321732

17331733
@lru_cache(64)
1734-
def _get_font(font_filepaths, hinting_factor, *, _kerning_factor, thread_id,
1734+
def _get_font(font_filepaths, *, _kerning_factor, thread_id,
17351735
enable_last_resort):
17361736
(first_fontpath, first_fontindex), *rest = font_filepaths
17371737
fallback_list = [
1738-
ft2font.FT2Font(fpath, hinting_factor, face_index=index,
1738+
ft2font.FT2Font(fpath, face_index=index,
17391739
_kerning_factor=_kerning_factor)
17401740
for fpath, index in rest
17411741
]
@@ -1749,12 +1749,12 @@ def _get_font(font_filepaths, hinting_factor, *, _kerning_factor, thread_id,
17491749
# already in the list.
17501750
if enable_last_resort:
17511751
fallback_list.append(
1752-
ft2font.FT2Font(last_resort_path, hinting_factor,
1752+
ft2font.FT2Font(last_resort_path,
17531753
_kerning_factor=_kerning_factor,
17541754
_warn_if_used=True))
17551755
last_resort_index = len(fallback_list)
17561756
font = ft2font.FT2Font(
1757-
first_fontpath, hinting_factor, face_index=first_fontindex,
1757+
first_fontpath, face_index=first_fontindex,
17581758
_fallback_list=fallback_list,
17591759
_kerning_factor=_kerning_factor
17601760
)
@@ -1783,6 +1783,7 @@ def _cached_realpath(path):
17831783
return os.path.realpath(path)
17841784

17851785

1786+
@_api.delete_parameter('3.11', 'hinting_factor')
17861787
def get_font(font_filepaths, hinting_factor=None):
17871788
"""
17881789
Get an `.ft2font.FT2Font` object given a list of file paths.
@@ -1816,20 +1817,16 @@ def get_font(font_filepaths, hinting_factor=None):
18161817
if isinstance(fname, FontPath) else (_cached_realpath(fname), 0)
18171818
for fname in font_filepaths)
18181819

1819-
hinting_factor = mpl._val_or_rc(hinting_factor, 'text.hinting_factor')
1820-
18211820
font = _get_font(
18221821
# must be a tuple to be cached
18231822
paths,
1824-
hinting_factor,
18251823
_kerning_factor=mpl.rcParams['text.kerning_factor'],
18261824
# also key on the thread ID to prevent segfaults with multi-threading
18271825
thread_id=threading.get_ident(),
18281826
enable_last_resort=mpl.rcParams['font.enable_last_resort'],
18291827
)
18301828
# Ensure the transform is always consistent.
1831-
font._set_transform([[round(0x10000 / font._hinting_factor), 0], [0, 0x10000]],
1832-
[0, 0])
1829+
font._set_transform([[0x10000, 0], [0, 0x10000]], [0, 0])
18331830
return font
18341831

18351832

lib/matplotlib/font_manager.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ class FontManager:
142142
def is_opentype_cff_font(filename: str) -> bool: ...
143143
def get_font(
144144
font_filepaths: Iterable[str | bytes | os.PathLike | FontPath] | str | bytes | os.PathLike | FontPath,
145-
hinting_factor: int | None = ...,
146145
) -> ft2font.FT2Font: ...
147146

148147
fontManager: FontManager

lib/matplotlib/ft2font.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ class FT2Font(Buffer):
236236
def __init__(
237237
self,
238238
filename: str | bytes | PathLike | BinaryIO,
239-
hinting_factor: int = ...,
240239
*,
241240
face_index: int = ...,
242241
_fallback_list: list[FT2Font] | None = ...,

lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,7 @@
308308
## - no_hinting: Disable hinting. ("none" is a synonym.)
309309
#text.hinting: default
310310

311-
#text.hinting_factor: 1 # Specifies the amount of softness for hinting in the
312-
# horizontal direction. A value of 1 will hint to full
313-
# pixels. A value of 2 will hint to half pixels etc.
311+
#text.hinting_factor: None # This setting does nothing and is deprecated.
314312
#text.kerning_factor: None # Specifies the scaling factor for kerning values. Values
315313
# other than 0, 6, or None have no defined meaning.
316314
# This setting is deprecated.

0 commit comments

Comments
 (0)