mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 10:46:16 +03:00
Working in py3k, not in 2.x
This commit is contained in:
parent
cb309c9f59
commit
4d32136365
BIN
Tests/images/high_ascii_chars.png
Normal file
BIN
Tests/images/high_ascii_chars.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
|
@ -22,10 +22,22 @@ def test_sanity():
|
||||||
|
|
||||||
font.save(tempname)
|
font.save(tempname)
|
||||||
|
|
||||||
def test_draw():
|
def xtest_draw():
|
||||||
|
|
||||||
font = ImageFont.load(tempname)
|
font = ImageFont.load(tempname)
|
||||||
image = Image.new("L", font.getsize(message), "white")
|
image = Image.new("L", font.getsize(message), "white")
|
||||||
draw = ImageDraw.Draw(image)
|
draw = ImageDraw.Draw(image)
|
||||||
draw.text((0, 0), message, font=font)
|
draw.text((0, 0), message, font=font)
|
||||||
# assert_signature(image, "7216c60f988dea43a46bb68321e3c1b03ec62aee")
|
# 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)
|
||||||
|
|
23
_imaging.c
23
_imaging.c
|
@ -2245,24 +2245,28 @@ _font_getmask(ImagingFontObject* self, PyObject* args)
|
||||||
Imaging im;
|
Imaging im;
|
||||||
Imaging bitmap;
|
Imaging bitmap;
|
||||||
int x, b;
|
int x, b;
|
||||||
|
int i=0;
|
||||||
int status;
|
int status;
|
||||||
Glyph* glyph;
|
Glyph* glyph;
|
||||||
|
|
||||||
unsigned char* text;
|
unsigned char* text;
|
||||||
char* mode = "";
|
char* mode = "";
|
||||||
if (!PyArg_ParseTuple(args, "s|s:getmask", &text, &mode))
|
if (!PyArg_ParseTuple(args, "es|s:getmask", "latin1", &text, &mode)){
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
im = ImagingNew(self->bitmap->mode, textwidth(self, text), self->ysize);
|
im = ImagingNew(self->bitmap->mode, textwidth(self, text), self->ysize);
|
||||||
if (!im)
|
if (!im) {
|
||||||
|
PyMem_Free(text);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
b = 0;
|
b = 0;
|
||||||
(void) ImagingFill(im, &b);
|
(void) ImagingFill(im, &b);
|
||||||
|
|
||||||
b = self->baseline;
|
b = self->baseline;
|
||||||
for (x = 0; *text; text++) {
|
for (x = 0; text[i]; i++) {
|
||||||
glyph = &self->glyphs[*text];
|
glyph = &self->glyphs[text[i]];
|
||||||
bitmap = ImagingCrop(
|
bitmap = ImagingCrop(
|
||||||
self->bitmap,
|
self->bitmap,
|
||||||
glyph->sx0, glyph->sy0, glyph->sx1, glyph->sy1
|
glyph->sx0, glyph->sy0, glyph->sx1, glyph->sy1
|
||||||
|
@ -2279,10 +2283,11 @@ _font_getmask(ImagingFontObject* self, PyObject* args)
|
||||||
x = x + glyph->dx;
|
x = x + glyph->dx;
|
||||||
b = b + glyph->dy;
|
b = b + glyph->dy;
|
||||||
}
|
}
|
||||||
|
PyMem_Free(text);
|
||||||
return PyImagingNew(im);
|
return PyImagingNew(im);
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
|
PyMem_Free(text);
|
||||||
ImagingDelete(im);
|
ImagingDelete(im);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2291,10 +2296,14 @@ static PyObject*
|
||||||
_font_getsize(ImagingFontObject* self, PyObject* args)
|
_font_getsize(ImagingFontObject* self, PyObject* args)
|
||||||
{
|
{
|
||||||
unsigned char* text;
|
unsigned char* text;
|
||||||
if (!PyArg_ParseTuple(args, "s:getsize", &text))
|
PyObject* retval;
|
||||||
|
if (!PyArg_ParseTuple(args, "es:getsize", "latin-1", &text))
|
||||||
return NULL;
|
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[] = {
|
static struct PyMethodDef _font_methods[] = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user