Merge pull request #2624 from radarhere/getsize_emptystring

Added fix for font getsize on empty string
This commit is contained in:
wiredfool 2017-07-16 16:30:15 +01:00 committed by GitHub
commit c58dd9bcb3
2 changed files with 6 additions and 3 deletions

View File

@ -393,6 +393,11 @@ class TestImageFont(PillowTestCase):
# Assert
self.assert_image_equal(im, target_img)
def test_getsize_empty(self):
font = self.get_font()
# should not crash.
self.assertEqual((0, 0), font.getsize(''))
def _test_fake_loading_font(self, path_to_fake, fontname):
# Make a copy of FreeTypeFont so we can patch the original
free_type_font = copy.deepcopy(ImageFont.FreeTypeFont)

View File

@ -109,7 +109,7 @@ getfont(PyObject* self_, PyObject* args, PyObject* kw)
unsigned char* font_bytes;
int font_bytes_size = 0;
static char* kwlist[] = {
"filename", "size", "index", "encoding", "font_bytes",
"filename", "size", "index", "encoding", "font_bytes",
"layout_engine", NULL
};
@ -449,8 +449,6 @@ font_getsize(FontObject* self, PyObject* args)
y_max = y_min = 0;
count = text_layout(string, self, dir, features, &glyph_info, 0);
if (count == 0)
return NULL;
for (x = i = 0; i < count; i++) {
int index, error;