mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Merge pull request #1072 from wiredfool/pr960
Fix for corrupted bitmaps embedded in truetype fonts.
This commit is contained in:
commit
efeca060a3
BIN
Tests/fonts/DejaVuSans-bitmap.ttf
Normal file
BIN
Tests/fonts/DejaVuSans-bitmap.ttf
Normal file
Binary file not shown.
BIN
Tests/fonts/DejaVuSans.ttf
Normal file
BIN
Tests/fonts/DejaVuSans.ttf
Normal file
Binary file not shown.
24
Tests/test_imagefont_bitmap.py
Normal file
24
Tests/test_imagefont_bitmap.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
from PIL import Image, ImageFont, ImageDraw
|
||||
|
||||
class TestImageFontBitmap(PillowTestCase):
|
||||
def test_similar(self):
|
||||
text = 'EmbeddedBitmap'
|
||||
font_outline = ImageFont.truetype(font='Tests/fonts/DejaVuSans.ttf', size=24)
|
||||
font_bitmap = ImageFont.truetype(font='Tests/fonts/DejaVuSans-bitmap.ttf', size=24)
|
||||
size_outline, size_bitmap = font_outline.getsize(text), font_bitmap.getsize(text)
|
||||
size_final = max(size_outline[0], size_bitmap[0]), max(size_outline[1], size_bitmap[1])
|
||||
im_bitmap = Image.new('RGB', size_final, (255, 255, 255))
|
||||
im_outline = im_bitmap.copy()
|
||||
draw_bitmap, draw_outline = ImageDraw.Draw(im_bitmap), ImageDraw.Draw(im_outline)
|
||||
|
||||
# Metrics are different on the bitmap and ttf fonts, more so on some platforms
|
||||
# and versions of freetype than others. Mac has a 1px difference, linux doesn't.
|
||||
draw_bitmap.text((0, size_final[1] - size_bitmap[1]),
|
||||
text, fill=(0, 0, 0), font=font_bitmap)
|
||||
draw_outline.text((0, size_final[1] - size_outline[1]),
|
||||
text, fill=(0, 0, 0), font=font_outline)
|
||||
self.assert_image_similar(im_bitmap, im_outline, 20)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
13
_imagingft.c
13
_imagingft.c
|
@ -243,7 +243,11 @@ font_getsize(FontObject* self, PyObject* args)
|
|||
&delta);
|
||||
x += delta.x;
|
||||
}
|
||||
error = FT_Load_Glyph(face, index, FT_LOAD_DEFAULT);
|
||||
|
||||
/* Note: bitmap fonts within ttf fonts do not work, see #891/pr#960
|
||||
* Yifu Yu<root@jackyyf.com>, 2014-10-15
|
||||
*/
|
||||
error = FT_Load_Glyph(face, index, FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP);
|
||||
if (error)
|
||||
return geterror(error);
|
||||
if (i == 0)
|
||||
|
@ -316,7 +320,8 @@ font_getabc(FontObject* self, PyObject* args)
|
|||
int index, error;
|
||||
face = self->face;
|
||||
index = FT_Get_Char_Index(face, ch);
|
||||
error = FT_Load_Glyph(face, index, FT_LOAD_DEFAULT);
|
||||
/* Note: bitmap fonts within ttf fonts do not work, see #891/pr#960 */
|
||||
error = FT_Load_Glyph(face, index, FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP);
|
||||
if (error)
|
||||
return geterror(error);
|
||||
a = face->glyph->metrics.horiBearingX / 64.0;
|
||||
|
@ -363,8 +368,8 @@ font_render(FontObject* self, PyObject* args)
|
|||
}
|
||||
|
||||
im = (Imaging) id;
|
||||
|
||||
load_flags = FT_LOAD_RENDER;
|
||||
/* Note: bitmap fonts within ttf fonts do not work, see #891/pr#960 */
|
||||
load_flags = FT_LOAD_RENDER|FT_LOAD_NO_BITMAP;
|
||||
if (mask)
|
||||
load_flags |= FT_LOAD_TARGET_MONO;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user