diff --git a/Tests/images/high_ascii_chars.png b/Tests/images/high_ascii_chars.png new file mode 100644 index 000000000..fc9ab8401 Binary files /dev/null and b/Tests/images/high_ascii_chars.png differ diff --git a/Tests/test_font_pcf.py b/Tests/test_font_pcf.py index 60e6e0e26..015885d01 100644 --- a/Tests/test_font_pcf.py +++ b/Tests/test_font_pcf.py @@ -22,10 +22,22 @@ def test_sanity(): font.save(tempname) -def test_draw(): +def xtest_draw(): font = ImageFont.load(tempname) image = Image.new("L", font.getsize(message), "white") draw = ImageDraw.Draw(image) draw.text((0, 0), message, font=font) # assert_signature(image, "7216c60f988dea43a46bb68321e3c1b03ec62aee") + +def test_high_characters(): + + message = "".join([chr(i+1) for i in range(140,232)]) + font = ImageFont.load(tempname) + image = Image.new("L", font.getsize(message), "white") + draw = ImageDraw.Draw(image) + draw.text((0, 0), message, font=font) + + compare = Image.open('Tests/images/high_ascii_chars.png') + + assert_image_equal(image, compare) diff --git a/_imaging.c b/_imaging.c index 078961da4..873617ea2 100644 --- a/_imaging.c +++ b/_imaging.c @@ -2245,24 +2245,28 @@ _font_getmask(ImagingFontObject* self, PyObject* args) Imaging im; Imaging bitmap; int x, b; + int i=0; int status; Glyph* glyph; unsigned char* text; char* mode = ""; - if (!PyArg_ParseTuple(args, "s|s:getmask", &text, &mode)) + if (!PyArg_ParseTuple(args, "es|s:getmask", "latin1", &text, &mode)){ return NULL; + } im = ImagingNew(self->bitmap->mode, textwidth(self, text), self->ysize); - if (!im) + if (!im) { + PyMem_Free(text); return NULL; + } b = 0; (void) ImagingFill(im, &b); b = self->baseline; - for (x = 0; *text; text++) { - glyph = &self->glyphs[*text]; + for (x = 0; text[i]; i++) { + glyph = &self->glyphs[text[i]]; bitmap = ImagingCrop( self->bitmap, glyph->sx0, glyph->sy0, glyph->sx1, glyph->sy1 @@ -2279,10 +2283,11 @@ _font_getmask(ImagingFontObject* self, PyObject* args) x = x + glyph->dx; b = b + glyph->dy; } - + PyMem_Free(text); return PyImagingNew(im); failed: + PyMem_Free(text); ImagingDelete(im); return NULL; } @@ -2291,10 +2296,14 @@ static PyObject* _font_getsize(ImagingFontObject* self, PyObject* args) { unsigned char* text; - if (!PyArg_ParseTuple(args, "s:getsize", &text)) + PyObject* retval; + if (!PyArg_ParseTuple(args, "es:getsize", "latin-1", &text)) return NULL; - return Py_BuildValue("ii", textwidth(self, text), self->ysize); + retval = Py_BuildValue("ii", textwidth(self, text), self->ysize); + PyMem_Free(text); + return retval; + } static struct PyMethodDef _font_methods[] = {