mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-16 02:04:45 +03:00
fixed tests, and memory leak
This commit is contained in:
parent
652bf225aa
commit
93b4321665
|
@ -180,7 +180,8 @@ class FreeTypeFont(object):
|
||||||
Return a string containing all the characters with matching glyphs in
|
Return a string containing all the characters with matching glyphs in
|
||||||
the font
|
the font
|
||||||
"""
|
"""
|
||||||
return ''.join(unichr(code) for code in self.font.getglyphs())
|
codes = self.font.getglyphs()
|
||||||
|
return ''.join(unichr(code) for code in codes)
|
||||||
|
|
||||||
##
|
##
|
||||||
# Wrapper that creates a transposed font from any existing font
|
# Wrapper that creates a transposed font from any existing font
|
||||||
|
|
|
@ -52,9 +52,10 @@ try:
|
||||||
ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
||||||
self.assertEqual(ttf.path, FONT_PATH)
|
self.assertEqual(ttf.path, FONT_PATH)
|
||||||
self.assertEqual(ttf.size, FONT_SIZE)
|
self.assertEqual(ttf.size, FONT_SIZE)
|
||||||
self.assertTrue(ttf.hasglyph('a'))
|
self.assertTrue(ttf.hasglyphs('a'))
|
||||||
self.assertFalse(ttf.hasglyph('\ueeee'))
|
self.assertFalse(ttf.hasglyphs(u'a\ueeee'))
|
||||||
self.assertEqual(ttf.getglyphs(), '....')
|
self.assertEqual(len(ttf.getglyphs()), 4160)
|
||||||
|
self.assertIn('a', ttf.getglyphs())
|
||||||
|
|
||||||
ttf_copy = ttf.font_variant()
|
ttf_copy = ttf.font_variant()
|
||||||
self.assertEqual(ttf_copy.path, FONT_PATH)
|
self.assertEqual(ttf_copy.path, FONT_PATH)
|
||||||
|
@ -66,9 +67,10 @@ try:
|
||||||
second_font_path = "Tests/fonts/DejaVuSans.ttf"
|
second_font_path = "Tests/fonts/DejaVuSans.ttf"
|
||||||
ttf_copy = ttf.font_variant(font=second_font_path)
|
ttf_copy = ttf.font_variant(font=second_font_path)
|
||||||
self.assertEqual(ttf_copy.path, second_font_path)
|
self.assertEqual(ttf_copy.path, second_font_path)
|
||||||
self.assertTrue(ttf_copy.hasglyph('a'))
|
self.assertTrue(ttf_copy.hasglyphs('ae'))
|
||||||
self.assertFalse(ttf_copy.hasglyph('\ueeee'))
|
self.assertFalse(ttf_copy.hasglyphs(u'a\ueeee'))
|
||||||
self.assertEqual(ttf_copy.getglyphs(), '....')
|
self.assertEqual(len(ttf.getglyphs()), 4160)
|
||||||
|
self.assertIn('a', ttf.getglyphs())
|
||||||
|
|
||||||
def test_font_with_name(self):
|
def test_font_with_name(self):
|
||||||
ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
||||||
|
|
|
@ -352,14 +352,15 @@ font_hasglyphs(FontObject* self, PyObject* args)
|
||||||
static PyObject*
|
static PyObject*
|
||||||
font_getglyphs(FontObject* self)
|
font_getglyphs(FontObject* self)
|
||||||
{
|
{
|
||||||
int ii = 0;
|
|
||||||
FT_UInt gindex = 0;
|
FT_UInt gindex = 0;
|
||||||
PyObject* characters = PyList_New(self->face->num_glyphs);
|
PyObject* characters = PyList_New(0);
|
||||||
|
if(!characters)
|
||||||
|
return PyErr_NoMemory();
|
||||||
FT_ULong charcode = 0;
|
FT_ULong charcode = 0;
|
||||||
|
|
||||||
charcode = FT_Get_First_Char(self->face, &gindex);
|
charcode = FT_Get_First_Char(self->face, &gindex);
|
||||||
for(ii = 0; gindex != 0 && ii < self->face->num_glyphs; ii++) {
|
while( gindex != 0 ) {
|
||||||
PyList_SetItem(characters, ii, PyLong_FromUnsignedLong(charcode));
|
PyList_Append(characters, PyLong_FromUnsignedLong(charcode));
|
||||||
charcode = FT_Get_Next_Char(self->face, charcode, &gindex);
|
charcode = FT_Get_Next_Char(self->face, charcode, &gindex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user