fixed tests, and memory leak

This commit is contained in:
Micah Chambers 2016-05-20 06:19:00 +00:00
parent 652bf225aa
commit 93b4321665
3 changed files with 15 additions and 11 deletions

View File

@ -180,7 +180,8 @@ class FreeTypeFont(object):
Return a string containing all the characters with matching glyphs in
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

View File

@ -52,9 +52,10 @@ try:
ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE)
self.assertEqual(ttf.path, FONT_PATH)
self.assertEqual(ttf.size, FONT_SIZE)
self.assertTrue(ttf.hasglyph('a'))
self.assertFalse(ttf.hasglyph('\ueeee'))
self.assertEqual(ttf.getglyphs(), '....')
self.assertTrue(ttf.hasglyphs('a'))
self.assertFalse(ttf.hasglyphs(u'a\ueeee'))
self.assertEqual(len(ttf.getglyphs()), 4160)
self.assertIn('a', ttf.getglyphs())
ttf_copy = ttf.font_variant()
self.assertEqual(ttf_copy.path, FONT_PATH)
@ -66,9 +67,10 @@ try:
second_font_path = "Tests/fonts/DejaVuSans.ttf"
ttf_copy = ttf.font_variant(font=second_font_path)
self.assertEqual(ttf_copy.path, second_font_path)
self.assertTrue(ttf_copy.hasglyph('a'))
self.assertFalse(ttf_copy.hasglyph('\ueeee'))
self.assertEqual(ttf_copy.getglyphs(), '....')
self.assertTrue(ttf_copy.hasglyphs('ae'))
self.assertFalse(ttf_copy.hasglyphs(u'a\ueeee'))
self.assertEqual(len(ttf.getglyphs()), 4160)
self.assertIn('a', ttf.getglyphs())
def test_font_with_name(self):
ImageFont.truetype(FONT_PATH, FONT_SIZE)

View File

@ -352,14 +352,15 @@ font_hasglyphs(FontObject* self, PyObject* args)
static PyObject*
font_getglyphs(FontObject* self)
{
int ii = 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;
charcode = FT_Get_First_Char(self->face, &gindex);
for(ii = 0; gindex != 0 && ii < self->face->num_glyphs; ii++) {
PyList_SetItem(characters, ii, PyLong_FromUnsignedLong(charcode));
while( gindex != 0 ) {
PyList_Append(characters, PyLong_FromUnsignedLong(charcode));
charcode = FT_Get_Next_Char(self->face, charcode, &gindex);
}