mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 17:54:32 +03:00
Added ability to render a bytes object using an old style bitmap font to make it easier to use in Py3k
This commit is contained in:
parent
cacd638187
commit
540e1e2c68
|
@ -30,14 +30,20 @@ def xtest_draw():
|
||||||
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():
|
def _test_high_characters(message):
|
||||||
|
|
||||||
message = "".join([chr(i+1) for i in range(140,232)])
|
|
||||||
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)
|
||||||
|
|
||||||
compare = Image.open('Tests/images/high_ascii_chars.png')
|
compare = Image.open('Tests/images/high_ascii_chars.png')
|
||||||
|
|
||||||
assert_image_equal(image, compare)
|
assert_image_equal(image, compare)
|
||||||
|
|
||||||
|
def test_high_characters():
|
||||||
|
message = "".join([chr(i+1) for i in range(140,232)])
|
||||||
|
_test_high_characters(message)
|
||||||
|
# accept bytes instances in Py3.
|
||||||
|
if bytes is not str:
|
||||||
|
_test_high_characters(message.encode('latin1'))
|
||||||
|
|
||||||
|
|
36
_imaging.c
36
_imaging.c
|
@ -2240,29 +2240,27 @@ textwidth(ImagingFontObject* self, const unsigned char* text)
|
||||||
}
|
}
|
||||||
|
|
||||||
void _font_text_asBytes(PyObject* encoded_string, unsigned char** text){
|
void _font_text_asBytes(PyObject* encoded_string, unsigned char** text){
|
||||||
PyObject* bytes;
|
PyObject* bytes = NULL;
|
||||||
|
|
||||||
|
*text = NULL;
|
||||||
|
|
||||||
if (PyUnicode_CheckExact(encoded_string)){
|
if (PyUnicode_CheckExact(encoded_string)){
|
||||||
bytes = PyUnicode_AsLatin1String(encoded_string);
|
bytes = PyUnicode_AsLatin1String(encoded_string);
|
||||||
if (bytes) {
|
} else if (PyBytes_Check(encoded_string)) {
|
||||||
*text = (unsigned char*)PyBytes_AsString(bytes);
|
bytes = encoded_string;
|
||||||
} else {
|
|
||||||
*text = NULL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
/* this should always be a unicode if we're in Py3.x */
|
|
||||||
*text = NULL;
|
|
||||||
#else
|
|
||||||
/* likely case here is py2.x with an ordinary string.
|
|
||||||
but this isn't defined in Py3.x */
|
|
||||||
if (PyString_Check(encoded_string)) {
|
|
||||||
*text = (unsigned char *)PyString_AsString(encoded_string);
|
|
||||||
} else {
|
|
||||||
*text = NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
if (bytes) {
|
||||||
|
*text = (unsigned char*)PyBytes_AsString(bytes);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if PY_VERSION_HEX < 0x03000000
|
||||||
|
/* likely case here is py2.x with an ordinary string.
|
||||||
|
but this isn't defined in Py3.x */
|
||||||
|
if (PyString_Check(encoded_string)) {
|
||||||
|
*text = (unsigned char *)PyString_AsString(encoded_string);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user