Skip to content

Commit 606b5ae

Browse files
committed
Remove support for FreeType 2.7 and older
1 parent 20cf82b commit 606b5ae

File tree

7 files changed

+42
-81
lines changed

7 files changed

+42
-81
lines changed

Tests/test_imagefont.py

+1-22
Original file line numberDiff line numberDiff line change
@@ -757,11 +757,7 @@ def test_anchor(self, anchor, left, left_old, top):
757757
name, text = "quick", "Quick"
758758
path = f"Tests/images/test_anchor_{name}_{anchor}.png"
759759

760-
freetype = parse_version(features.version_module("freetype2"))
761-
if freetype < parse_version("2.4"):
762-
width, height = (129, 44)
763-
left = left_old
764-
elif self.LAYOUT_ENGINE == ImageFont.LAYOUT_RAQM:
760+
if self.LAYOUT_ENGINE == ImageFont.LAYOUT_RAQM:
765761
width, height = (129, 44)
766762
else:
767763
width, height = (128, 44)
@@ -894,7 +890,6 @@ def test_standard_embedded_color(self):
894890

895891
assert_image_similar_tofile(im, "Tests/images/standard_embedded.png", 6.2)
896892

897-
@skip_unless_feature_version("freetype2", "2.5.0")
898893
def test_cbdt(self):
899894
try:
900895
font = ImageFont.truetype(
@@ -913,7 +908,6 @@ def test_cbdt(self):
913908
assert str(e) in ("unimplemented feature", "unknown file format")
914909
pytest.skip("freetype compiled without libpng or CBDT support")
915910

916-
@skip_unless_feature_version("freetype2", "2.5.0")
917911
def test_cbdt_mask(self):
918912
try:
919913
font = ImageFont.truetype(
@@ -934,7 +928,6 @@ def test_cbdt_mask(self):
934928
assert str(e) in ("unimplemented feature", "unknown file format")
935929
pytest.skip("freetype compiled without libpng or CBDT support")
936930

937-
@skip_unless_feature_version("freetype2", "2.5.1")
938931
def test_sbix(self):
939932
try:
940933
font = ImageFont.truetype(
@@ -953,7 +946,6 @@ def test_sbix(self):
953946
assert str(e) in ("unimplemented feature", "unknown file format")
954947
pytest.skip("freetype compiled without libpng or SBIX support")
955948

956-
@skip_unless_feature_version("freetype2", "2.5.1")
957949
def test_sbix_mask(self):
958950
try:
959951
font = ImageFont.truetype(
@@ -1008,7 +1000,6 @@ class TestImageFont_RaqmLayout(TestImageFont):
10081000
LAYOUT_ENGINE = ImageFont.LAYOUT_RAQM
10091001

10101002

1011-
@skip_unless_feature_version("freetype2", "2.4", "Different metrics")
10121003
def test_render_mono_size():
10131004
# issue 4177
10141005

@@ -1024,18 +1015,6 @@ def test_render_mono_size():
10241015
assert_image_equal_tofile(im, "Tests/images/text_mono.gif")
10251016

10261017

1027-
def test_freetype_deprecation(monkeypatch):
1028-
# Arrange: mock features.version_module to return fake FreeType version
1029-
def fake_version_module(module):
1030-
return "2.7"
1031-
1032-
monkeypatch.setattr(features, "version_module", fake_version_module)
1033-
1034-
# Act / Assert
1035-
with pytest.warns(DeprecationWarning):
1036-
ImageFont.truetype(FONT_PATH, FONT_SIZE)
1037-
1038-
10391018
@pytest.mark.parametrize(
10401019
"test_file",
10411020
[

Tests/test_imagefontctl.py

+2-20
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import pytest
2-
from packaging.version import parse as parse_version
32

4-
from PIL import Image, ImageDraw, ImageFont, features
3+
from PIL import Image, ImageDraw, ImageFont
54

6-
from .helper import (
7-
assert_image_similar_tofile,
8-
skip_unless_feature,
9-
skip_unless_feature_version,
10-
)
5+
from .helper import assert_image_similar_tofile, skip_unless_feature
116

127
FONT_SIZE = 20
138
FONT_PATH = "Tests/fonts/DejaVuSans/DejaVuSans.ttf"
@@ -252,11 +247,6 @@ def test_getlength_combine(mode, direction, text):
252247
pytest.skip("libraqm 0.7 or greater not available")
253248

254249

255-
# FreeType 2.5.1 README: Miscellaneous Changes:
256-
# Improved computation of emulated vertical metrics for TrueType fonts.
257-
@skip_unless_feature_version(
258-
"freetype2", "2.5.1", "FreeType <2.5.1 has incompatible ttb metrics"
259-
)
260250
@pytest.mark.parametrize("anchor", ("lt", "mm", "rb", "sm"))
261251
def test_anchor_ttb(anchor):
262252
text = "f"
@@ -315,14 +305,6 @@ def test_anchor_ttb(anchor):
315305
"name, text, anchor, dir, epsilon", combine_tests, ids=[r[0] for r in combine_tests]
316306
)
317307
def test_combine(name, text, dir, anchor, epsilon):
318-
if (
319-
parse_version(features.version_module("freetype2")) < parse_version("2.5.1")
320-
and dir == "ttb"
321-
):
322-
# FreeType 2.5.1 README: Miscellaneous Changes:
323-
# Improved computation of emulated vertical metrics for TrueType fonts.
324-
pytest.skip("FreeType <2.5.1 has incompatible ttb metrics")
325-
326308
path = f"Tests/images/test_combine_{name}.png"
327309
f = ImageFont.truetype("Tests/fonts/NotoSans-Regular.ttf", 48)
328310

docs/deprecations.rst

+13-13
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,6 @@ Deprecated features
1212
Below are features which are considered deprecated. Where appropriate,
1313
a ``DeprecationWarning`` is issued.
1414

15-
FreeType 2.7
16-
~~~~~~~~~~~~
17-
18-
.. deprecated:: 8.1.0
19-
20-
Support for FreeType 2.7 is deprecated and will be removed in Pillow 9.0.0 (2022-01-02),
21-
when FreeType 2.8 will be the minimum supported.
22-
23-
We recommend upgrading to at least FreeType `2.10.4`_, which fixed a severe
24-
vulnerability introduced in FreeType 2.6 (:cve:`CVE-2020-15999`).
25-
26-
.. _2.10.4: https://sourceforge.net/projects/freetype/files/freetype2/2.10.4/
27-
2815
Tk/Tcl 8.4
2916
~~~~~~~~~~
3017

@@ -111,6 +98,19 @@ ImageFile.raise_ioerror
11198
So, ``ImageFile.raise_ioerror`` has been removed.
11299
Use ``ImageFile.raise_oserror`` instead.
113100

101+
FreeType 2.7
102+
~~~~~~~~~~~~
103+
104+
.. deprecated:: 8.1.0
105+
.. versionremoved:: 9.0.0
106+
107+
Support for FreeType 2.7 has been removed.
108+
109+
We recommend upgrading to at least `FreeType`_ 2.10.4, which fixed a severe
110+
vulnerability introduced in FreeType 2.6 (:cve:`CVE-2020-15999`).
111+
112+
.. _FreeType: https://www.freetype.org
113+
114114
im.offset
115115
~~~~~~~~~
116116

docs/releasenotes/9.0.0.rst

+22-3
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,44 @@ PILLOW_VERSION constant
99

1010
``PILLOW_VERSION`` has been removed. Use ``__version__`` instead.
1111

12+
FreeType 2.7
13+
^^^^^^^^^^^^
14+
15+
Support for FreeType 2.7 has been removed; FreeType 2.8 is the minimum supported.
16+
17+
We recommend upgrading to at least `FreeType`_ 2.10.4, which fixed a severe
18+
vulnerability introduced in FreeType 2.6 (:cve:`CVE-2020-15999`).
19+
20+
.. _FreeType: https://www.freetype.org
21+
1222
Image.show command parameter
13-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1424

1525
The ``command`` parameter has been removed. Use a subclass of
1626
:py:class:`PIL.ImageShow.Viewer` instead.
1727

1828
Image._showxv
19-
~~~~~~~~~~~~~
29+
^^^^^^^^^^^^^
2030

2131
``Image._showxv`` has been removed. Use :py:meth:`~PIL.Image.Image.show`
2232
instead. If custom behaviour is required, use :py:meth:`~PIL.ImageShow.register` to add
2333
a custom :py:class:`~PIL.ImageShow.Viewer` class.
2434

2535
ImageFile.raise_ioerror
26-
~~~~~~~~~~~~~~~~~~~~~~~
36+
^^^^^^^^^^^^^^^^^^^^^^^
2737

2838
``IOError`` was merged into ``OSError`` in Python 3.3. So, ``ImageFile.raise_ioerror``
2939
has been removed. Use ``ImageFile.raise_oserror`` instead.
3040

41+
42+
Deprecations
43+
============
44+
45+
TODO
46+
^^^^
47+
48+
TODO
49+
3150
API Changes
3251
===========
3352

docs/releasenotes/template.rst

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ TODO
3434
Security
3535
========
3636

37+
TODO
38+
^^^^
39+
3740
TODO
3841

3942
Other Changes

src/PIL/ImageFont.py

+1-19
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@
2828
import base64
2929
import os
3030
import sys
31-
import warnings
3231
from io import BytesIO
3332

34-
from . import Image, features
33+
from . import Image
3534
from ._util import isDirectory, isPath
3635

3736
LAYOUT_BASIC = 0
@@ -165,23 +164,6 @@ def __init__(self, font=None, size=10, index=0, encoding="", layout_engine=None)
165164
self.index = index
166165
self.encoding = encoding
167166

168-
try:
169-
from packaging.version import parse as parse_version
170-
except ImportError:
171-
pass
172-
else:
173-
freetype_version = features.version_module("freetype2")
174-
if freetype_version is not None and parse_version(
175-
freetype_version
176-
) < parse_version("2.8"):
177-
warnings.warn(
178-
"Support for FreeType 2.7 is deprecated and will be removed"
179-
" in Pillow 9 (2022-01-02). Please upgrade to FreeType 2.8 "
180-
"or newer, preferably FreeType 2.10.4 which fixes "
181-
"CVE-2020-15999.",
182-
DeprecationWarning,
183-
)
184-
185167
if layout_engine not in (LAYOUT_BASIC, LAYOUT_RAQM):
186168
layout_engine = LAYOUT_BASIC
187169
if core.HAVE_RAQM:

src/_imagingft.c

-4
Original file line numberDiff line numberDiff line change
@@ -933,11 +933,7 @@ font_render(FontObject *self, PyObject *args) {
933933
case FT_PIXEL_MODE_GRAY2:
934934
case FT_PIXEL_MODE_GRAY4:
935935
if (!bitmap_converted_ready) {
936-
#if FREETYPE_MAJOR > 2 || (FREETYPE_MAJOR == 2 && FREETYPE_MINOR > 6)
937936
FT_Bitmap_Init(&bitmap_converted);
938-
#else
939-
FT_Bitmap_New(&bitmap_converted);
940-
#endif
941937
bitmap_converted_ready = 1;
942938
}
943939
error = FT_Bitmap_Convert(library, &bitmap, &bitmap_converted, 1);

0 commit comments

Comments
 (0)