mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-10 08:12:33 +03:00
fix raqm with 0 length strings
This commit is contained in:
parent
c3fbd9de01
commit
ee430550eb
15
_imagingft.c
15
_imagingft.c
|
@ -225,6 +225,11 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir,
|
||||||
if (PyUnicode_Check(string)) {
|
if (PyUnicode_Check(string)) {
|
||||||
Py_UNICODE *text = PyUnicode_AS_UNICODE(string);
|
Py_UNICODE *text = PyUnicode_AS_UNICODE(string);
|
||||||
Py_ssize_t size = PyUnicode_GET_SIZE(string);
|
Py_ssize_t size = PyUnicode_GET_SIZE(string);
|
||||||
|
if (! size) {
|
||||||
|
/* return 0 and clean up, no glyphs==no size,
|
||||||
|
and raqm fails with empty strings */
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
if (!raqm_set_text(rq, (const uint32_t *)(text), size)) {
|
if (!raqm_set_text(rq, (const uint32_t *)(text), size)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "raqm_set_text() failed");
|
PyErr_SetString(PyExc_ValueError, "raqm_set_text() failed");
|
||||||
goto failed;
|
goto failed;
|
||||||
|
@ -234,6 +239,9 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir,
|
||||||
else if (PyString_Check(string)) {
|
else if (PyString_Check(string)) {
|
||||||
char *text = PyString_AS_STRING(string);
|
char *text = PyString_AS_STRING(string);
|
||||||
int size = PyString_GET_SIZE(string);
|
int size = PyString_GET_SIZE(string);
|
||||||
|
if (! size) {
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
if (!raqm_set_text_utf8(rq, text, size)) {
|
if (!raqm_set_text_utf8(rq, text, size)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "raqm_set_text_utf8() failed");
|
PyErr_SetString(PyExc_ValueError, "raqm_set_text_utf8() failed");
|
||||||
goto failed;
|
goto failed;
|
||||||
|
@ -450,6 +458,10 @@ font_getsize(FontObject* self, PyObject* args)
|
||||||
y_max = y_min = 0;
|
y_max = y_min = 0;
|
||||||
|
|
||||||
count = text_layout(string, self, dir, features, &glyph_info, 0);
|
count = text_layout(string, self, dir, features, &glyph_info, 0);
|
||||||
|
if (PyErr_Occurred()) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
for (x = i = 0; i < count; i++) {
|
for (x = i = 0; i < count; i++) {
|
||||||
int index, error;
|
int index, error;
|
||||||
|
@ -584,6 +596,9 @@ font_render(FontObject* self, PyObject* args)
|
||||||
|
|
||||||
glyph_info = NULL;
|
glyph_info = NULL;
|
||||||
count = text_layout(string, self, dir, features, &glyph_info, mask);
|
count = text_layout(string, self, dir, features, &glyph_info, mask);
|
||||||
|
if (PyErr_Occurred()) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user