fonttools/Lib/fontTools/pens/ttGlyphPen_test.py

45 lines
1.2 KiB
Python
Raw Normal View History

from __future__ import print_function, division, absolute_import
from fontTools.misc.py23 import *
import os
import unittest
from fontTools import ttLib
from fontTools.pens.ttGlyphPen import TTGlyphPen
class TTGlyphPenTest(unittest.TestCase):
2015-11-05 14:01:52 -08:00
def runEndToEnd(self, filename):
font = ttLib.TTFont()
ttx_path = os.path.join(
os.path.abspath(os.path.dirname(os.path.realpath(__file__))),
2015-11-05 14:01:52 -08:00
'..', 'ttLib', 'testdata', filename)
font.importXML(ttx_path, quiet=True)
2015-11-05 14:01:52 -08:00
glyphSet = font.getGlyphSet()
glyfTable = font['glyf']
pen = TTGlyphPen(font.getGlyphSet())
2015-11-05 14:01:52 -08:00
for name in font.getGlyphOrder():
oldGlyph = glyphSet[name]
2015-11-05 14:01:52 -08:00
oldGlyph.draw(pen)
oldGlyph = oldGlyph._glyph
2015-11-05 14:01:52 -08:00
newGlyph = pen.glyph()
if hasattr(oldGlyph, 'program'):
newGlyph.program = oldGlyph.program
2015-11-05 14:01:52 -08:00
self.assertEqual(
oldGlyph.compile(glyfTable), newGlyph.compile(glyfTable))
2015-11-05 14:01:52 -08:00
def test_e2e_linesAndSimpleComponents(self):
self.runEndToEnd('TestTTF-Regular.ttx')
def test_e2e_curvesAndComponentTransforms(self):
self.runEndToEnd('TestTTFComplex-Regular.ttx')
if __name__ == '__main__':
unittest.main()