Skip to content

Commit

Permalink
fix support for extended unicode characters in PyPy
Browse files Browse the repository at this point in the history
  • Loading branch information
nulano authored and O. Baranovic committed Nov 8, 2019
1 parent 24b8501 commit 5161a09
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Tests/test_imagefont.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def test_unicode_pilfont(self):
with self.assertRaises(UnicodeEncodeError):
font.getsize("’")

@unittest.skipIf(is_pypy(), "requires CPython")
@unittest.skipIf(is_pypy(), "failing on PyPy")
def test_unicode_extended(self):
# issue #3777
text = "A\u278A\U0001F12B"
Expand Down
14 changes: 1 addition & 13 deletions src/_imagingft.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,24 +326,12 @@ getfont(PyObject* self_, PyObject* args, PyObject* kw)
static int
font_getchar(PyObject* string, int index, FT_ULong* char_out)
{
#if (defined(PYPY_VERSION_NUM))
if (PyUnicode_Check(string)) {
Py_UNICODE* p = PyUnicode_AS_UNICODE(string);
int size = PyUnicode_GET_SIZE(string);
if (index >= size)
return 0;
*char_out = p[index];
return 1;
}
#else
if (PyUnicode_Check(string)) {
if (index >= PyUnicode_GET_LENGTH(string))
return 0;
*char_out = PyUnicode_READ_CHAR(string, index);
return 1;
}
#endif

return 0;
}

Expand All @@ -363,7 +351,7 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, PyObject *
goto failed;
}

#if (defined(PYPY_VERSION_NUM))
#if (defined(PYPY_VERSION_NUM) && (PYPY_VERSION_NUM < 0x07020000))
if (PyUnicode_Check(string)) {
Py_UNICODE *text = PyUnicode_AS_UNICODE(string);
Py_ssize_t size = PyUnicode_GET_SIZE(string);
Expand Down

0 comments on commit 5161a09

Please sign in to comment.