From a766b5b0d5ab541dd93876f124da2b080fa79ff0 Mon Sep 17 00:00:00 2001 From: nulano Date: Sat, 16 Apr 2022 17:07:32 +0200 Subject: [PATCH 1/8] deprecate fill in imageFont --- Tests/test_imagefont.py | 5 +++++ src/PIL/ImageFont.py | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index f9d0a4c4f..a8fdddc24 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -977,6 +977,11 @@ class TestImageFont: assert_image_similar_tofile(im, "Tests/images/colr_bungee_mask.png", 22) + def test_fill_deprecation(self): + font = self.get_font() + with pytest.warns(DeprecationWarning): + font.getmask2("Hello world", fill=Image.core.fill) + @skip_unless_feature("raqm") class TestImageFont_RaqmLayout(TestImageFont): diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index f420e197e..77dce3bc6 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -602,7 +602,7 @@ class FreeTypeFont: self, text, mode="", - fill=Image.core.fill, + fill=None, direction=None, features=None, language=None, @@ -627,6 +627,8 @@ class FreeTypeFont: .. versionadded:: 1.1.5 + :param fill: Fill function. Deprecated. + :param direction: Direction of the text. It can be 'rtl' (right to left), 'ltr' (left to right) or 'ttb' (top to bottom). Requires libraqm. @@ -674,6 +676,10 @@ class FreeTypeFont: :py:mod:`PIL.Image.core` interface module, and the text offset, the gap between the starting coordinate and the first marking """ + if fill is not None: + deprecate("fill", 10) + else: + fill = Image.core.fill size, offset = self.font.getsize( text, mode, direction, features, language, anchor ) From d088c804d0df4f790209dddf2d4b83e2be75561b Mon Sep 17 00:00:00 2001 From: nulano Date: Sat, 16 Apr 2022 17:36:21 +0200 Subject: [PATCH 2/8] release notes --- docs/releasenotes/9.2.0.rst | 49 +++++++++++++++++++++++++++++++++++++ docs/releasenotes/index.rst | 1 + 2 files changed, 50 insertions(+) create mode 100644 docs/releasenotes/9.2.0.rst diff --git a/docs/releasenotes/9.2.0.rst b/docs/releasenotes/9.2.0.rst new file mode 100644 index 000000000..35e8ca2d5 --- /dev/null +++ b/docs/releasenotes/9.2.0.rst @@ -0,0 +1,49 @@ +9.2.0 +----- + +Backwards Incompatible Changes +============================== + +TODO +^^^^ + +Deprecations +============ + +FreeTypeFont.getmask2 fill parameter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The undocumented ``fill`` parameter of :py:meth:`.FreeTypeFont.getmask2` +has been deprecated and will be removed in Pillow 10 (2023-07-01). + +API Changes +=========== + +TODO +^^^^ + +TODO + +API Additions +============= + +TODO +^^^^ + +TODO + +Security +======== + +TODO +^^^^ + +TODO + +Other Changes +============= + +TODO +^^^^ + +TODO diff --git a/docs/releasenotes/index.rst b/docs/releasenotes/index.rst index 656acef95..db578bdb7 100644 --- a/docs/releasenotes/index.rst +++ b/docs/releasenotes/index.rst @@ -14,6 +14,7 @@ expected to be backported to earlier versions. .. toctree:: :maxdepth: 2 + 9.2.0 9.1.0 9.0.1 9.0.0 From b4b8249c9d7678dc8c08efa4c32a2b4b17a26b54 Mon Sep 17 00:00:00 2001 From: nulano Date: Sat, 16 Apr 2022 17:46:43 +0200 Subject: [PATCH 3/8] None is also not a valid value --- Tests/test_imagefont.py | 3 +++ src/PIL/ImageFont.py | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index a8fdddc24..c074c5205 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -981,6 +981,9 @@ class TestImageFont: font = self.get_font() with pytest.warns(DeprecationWarning): font.getmask2("Hello world", fill=Image.core.fill) + with pytest.raises(TypeError): + with pytest.warns(DeprecationWarning): + font.getmask2("Hello world", fill=None) @skip_unless_feature("raqm") diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index 77dce3bc6..7a34160f9 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -64,6 +64,9 @@ except ImportError: core = _imagingft_not_installed() +_UNSPECIFIED = object() + + # FIXME: add support for pilfont2 format (see FontFile.py) # -------------------------------------------------------------------- @@ -602,7 +605,7 @@ class FreeTypeFont: self, text, mode="", - fill=None, + fill=_UNSPECIFIED, direction=None, features=None, language=None, @@ -676,7 +679,7 @@ class FreeTypeFont: :py:mod:`PIL.Image.core` interface module, and the text offset, the gap between the starting coordinate and the first marking """ - if fill is not None: + if fill is not _UNSPECIFIED: deprecate("fill", 10) else: fill = Image.core.fill From 98e995f6c79378ab831a5863563784c22ecde07b Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 17 Apr 2022 14:23:46 +1000 Subject: [PATCH 4/8] FreeTypeFont.getmask2 fill parameter has been deprecated --- docs/deprecations.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/deprecations.rst b/docs/deprecations.rst index d4d5907ea..496a4df95 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -149,6 +149,14 @@ PhotoImage.paste box parameter The ``box`` parameter is unused. It will be removed in Pillow 10.0.0 (2023-07-01). +FreeTypeFont.getmask2 fill parameter +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. deprecated:: 9.2.0 + +The undocumented ``fill`` parameter of :py:meth:`.FreeTypeFont.getmask2` has been +deprecated and will be removed in Pillow 10 (2023-07-01). + Removed features ---------------- From 2a29b2dba1d075784e53c81dafb9626f83c63e2d Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 17 Apr 2022 14:33:16 +1000 Subject: [PATCH 5/8] Document that fill parameter is optional --- src/PIL/ImageFont.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index 7a34160f9..95059d5b2 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -630,7 +630,10 @@ class FreeTypeFont: .. versionadded:: 1.1.5 - :param fill: Fill function. Deprecated. + :param fill: Optional fill function. By default, an internal Pillow function + will be used. + + Deprecated. :param direction: Direction of the text. It can be 'rtl' (right to left), 'ltr' (left to right) or 'ttb' (top to bottom). From c87c2cf5b3d836ff53577aa292c581eea6c5f62f Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 17 Apr 2022 14:33:27 +1000 Subject: [PATCH 6/8] Added removal date for fill parameter --- src/PIL/ImageFont.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index 95059d5b2..ef6a8d4c7 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -633,7 +633,8 @@ class FreeTypeFont: :param fill: Optional fill function. By default, an internal Pillow function will be used. - Deprecated. + Deprecated. This parameter will be removed in Pillow 10 + (2023-07-01). :param direction: Direction of the text. It can be 'rtl' (right to left), 'ltr' (left to right) or 'ttb' (top to bottom). From ab86bdda0a751c7e9357b3396288d6d96628ed15 Mon Sep 17 00:00:00 2001 From: nulano Date: Sun, 17 Apr 2022 16:02:51 +0200 Subject: [PATCH 7/8] fix deprecation test --- Tests/test_imagefont.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index c074c5205..0e1d1e637 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -981,8 +981,8 @@ class TestImageFont: font = self.get_font() with pytest.warns(DeprecationWarning): font.getmask2("Hello world", fill=Image.core.fill) - with pytest.raises(TypeError): - with pytest.warns(DeprecationWarning): + with pytest.warns(DeprecationWarning): + with pytest.raises(TypeError): font.getmask2("Hello world", fill=None) From 995be34ddb80de3fe1b806deff81d80144353601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ondrej=20Baranovi=C4=8D?= Date: Sun, 17 Apr 2022 19:27:14 +0200 Subject: [PATCH 8/8] flip so the conditional is positive Co-authored-by: Hugo van Kemenade --- src/PIL/ImageFont.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index ef6a8d4c7..7a53de53c 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -683,10 +683,10 @@ class FreeTypeFont: :py:mod:`PIL.Image.core` interface module, and the text offset, the gap between the starting coordinate and the first marking """ - if fill is not _UNSPECIFIED: - deprecate("fill", 10) - else: + if fill is _UNSPECIFIED: fill = Image.core.fill + else: + deprecate("fill", 10) size, offset = self.font.getsize( text, mode, direction, features, language, anchor )