mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-09 06:44:45 +03:00
Merge 36a8aba1d7
into 7937ac1dfb
This commit is contained in:
commit
67776d4660
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.
21
Tests/test_imagefont_bitmap.py
Normal file
21
Tests/test_imagefont_bitmap.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
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)
|
||||||
|
# Don't know why, but bitmap version is always vertical 1 pixel longer than outline one on my PC.
|
||||||
|
# Revert back to both 0, 0
|
||||||
|
draw_bitmap.text((0, 0), text, fill=(0, 0, 0), font=font_bitmap)
|
||||||
|
draw_outline.text((0, 0), text, fill=(0, 0, 0), font=font_outline)
|
||||||
|
self.assert_image_similar(im_bitmap, im_outline, 0.01)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
17
_imagingft.c
17
_imagingft.c
|
@ -18,6 +18,17 @@
|
||||||
* Copyright (c) 1998-2007 by Secret Labs AB
|
* Copyright (c) 1998-2007 by Secret Labs AB
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Notes:
|
||||||
|
* Currently, embedded bitmap fonts within truetype fonts do not work
|
||||||
|
* properly (see issue #891), truetype fonts are loaded with
|
||||||
|
* FT_LOAD_NO_BITMAP load flags, resulting in embedded bitmap fonts
|
||||||
|
* not being used.
|
||||||
|
*
|
||||||
|
* Yifu Yu<root@jackyyf.com>
|
||||||
|
* 2014-10-15
|
||||||
|
*/
|
||||||
|
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
|
@ -243,7 +254,7 @@ font_getsize(FontObject* self, PyObject* args)
|
||||||
&delta);
|
&delta);
|
||||||
x += delta.x;
|
x += delta.x;
|
||||||
}
|
}
|
||||||
error = FT_Load_Glyph(face, index, FT_LOAD_DEFAULT);
|
error = FT_Load_Glyph(face, index, FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP);
|
||||||
if (error)
|
if (error)
|
||||||
return geterror(error);
|
return geterror(error);
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
|
@ -316,7 +327,7 @@ font_getabc(FontObject* self, PyObject* args)
|
||||||
int index, error;
|
int index, error;
|
||||||
face = self->face;
|
face = self->face;
|
||||||
index = FT_Get_Char_Index(face, ch);
|
index = FT_Get_Char_Index(face, ch);
|
||||||
error = FT_Load_Glyph(face, index, FT_LOAD_DEFAULT);
|
error = FT_Load_Glyph(face, index, FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP);
|
||||||
if (error)
|
if (error)
|
||||||
return geterror(error);
|
return geterror(error);
|
||||||
a = face->glyph->metrics.horiBearingX / 64.0;
|
a = face->glyph->metrics.horiBearingX / 64.0;
|
||||||
|
@ -364,7 +375,7 @@ font_render(FontObject* self, PyObject* args)
|
||||||
|
|
||||||
im = (Imaging) id;
|
im = (Imaging) id;
|
||||||
|
|
||||||
load_flags = FT_LOAD_RENDER;
|
load_flags = FT_LOAD_RENDER|FT_LOAD_NO_BITMAP;
|
||||||
if (mask)
|
if (mask)
|
||||||
load_flags |= FT_LOAD_TARGET_MONO;
|
load_flags |= FT_LOAD_TARGET_MONO;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user