From 86d4c53d79801b1e8ebf5d5dd7fdc0d8d348c01c Mon Sep 17 00:00:00 2001 From: nulano Date: Tue, 2 Jul 2019 08:52:15 +0200 Subject: [PATCH 1/2] revert #3780 for PyPy as it hasn't been updated --- Tests/test_imagefont.py | 6 ++++-- src/_imagingft.c | 13 ++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index 34ddbd53b..ae9bbd52b 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -465,8 +465,10 @@ class TestImageFont(PillowTestCase): font.getsize(u"’") @unittest.skipIf( - sys.platform.startswith("win32") and sys.version.startswith("2"), - "requires Python 3.x on Windows", + sys.platform.startswith("win32") and ( + sys.version.startswith("2") or hasattr(sys, "pypy_translation_info") + ), + "requires CPython 3.x on Windows", ) def test_unicode_extended(self): # issue #3777 diff --git a/src/_imagingft.c b/src/_imagingft.c index 4a3b3ccff..87376383e 100644 --- a/src/_imagingft.c +++ b/src/_imagingft.c @@ -327,7 +327,7 @@ getfont(PyObject* self_, PyObject* args, PyObject* kw) static int font_getchar(PyObject* string, int index, FT_ULong* char_out) { -#if PY_VERSION_HEX < 0x03000000 +#if (PY_VERSION_HEX < 0x03030000) || (defined(PYPY_VERSION_NUM)) if (PyUnicode_Check(string)) { Py_UNICODE* p = PyUnicode_AS_UNICODE(string); int size = PyUnicode_GET_SIZE(string); @@ -336,7 +336,7 @@ font_getchar(PyObject* string, int index, FT_ULong* char_out) *char_out = p[index]; return 1; } - +#if PY_VERSION_HEX < 0x03000000 if (PyString_Check(string)) { unsigned char* p = (unsigned char*) PyString_AS_STRING(string); int size = PyString_GET_SIZE(string); @@ -345,6 +345,7 @@ font_getchar(PyObject* string, int index, FT_ULong* char_out) *char_out = (unsigned char) p[index]; return 1; } +#endif #else if (PyUnicode_Check(string)) { if (index >= PyUnicode_GET_LENGTH(string)) @@ -373,7 +374,7 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, PyObject * goto failed; } -#if PY_VERSION_HEX < 0x03000000 +#if (PY_VERSION_HEX < 0x03030000) || (defined(PYPY_VERSION_NUM)) if (PyUnicode_Check(string)) { Py_UNICODE *text = PyUnicode_AS_UNICODE(string); Py_ssize_t size = PyUnicode_GET_SIZE(string); @@ -392,8 +393,9 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, PyObject * goto failed; } } - - } else if (PyString_Check(string)) { + } +#if PY_VERSION_HEX < 0x03000000 + else if (PyString_Check(string)) { char *text = PyString_AS_STRING(string); int size = PyString_GET_SIZE(string); if (! size) { @@ -410,6 +412,7 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, PyObject * } } } +#endif #else if (PyUnicode_Check(string)) { Py_UCS4 *text = PyUnicode_AsUCS4Copy(string); From 14ddfd30b2afc346038ded3bd6d782753e0e55ef Mon Sep 17 00:00:00 2001 From: nulano Date: Tue, 2 Jul 2019 09:31:05 +0200 Subject: [PATCH 2/2] fix lint --- Tests/test_imagefont.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index ae9bbd52b..ace3b7d33 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -465,9 +465,8 @@ class TestImageFont(PillowTestCase): font.getsize(u"’") @unittest.skipIf( - sys.platform.startswith("win32") and ( - sys.version.startswith("2") or hasattr(sys, "pypy_translation_info") - ), + sys.platform.startswith("win32") + and (sys.version.startswith("2") or hasattr(sys, "pypy_translation_info")), "requires CPython 3.x on Windows", ) def test_unicode_extended(self):