2015-11-04 18:01:34 -08:00
|
|
|
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()
|
2015-11-04 18:01:34 -08:00
|
|
|
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-04 18:01:34 -08:00
|
|
|
|
2015-11-05 14:01:52 -08:00
|
|
|
glyphSet = font.getGlyphSet()
|
|
|
|
glyfTable = font['glyf']
|
|
|
|
pen = TTGlyphPen(font.getGlyphSet())
|
2015-11-04 18:01:34 -08:00
|
|
|
|
2015-11-05 14:01:52 -08:00
|
|
|
for name in font.getGlyphOrder():
|
2015-11-04 18:01:34 -08:00
|
|
|
oldGlyph = glyphSet[name]
|
2015-11-05 14:01:52 -08:00
|
|
|
oldGlyph.draw(pen)
|
2015-11-04 18:01:34 -08:00
|
|
|
oldGlyph = oldGlyph._glyph
|
2015-11-05 14:01:52 -08:00
|
|
|
newGlyph = pen.glyph()
|
|
|
|
|
2015-11-04 18:01:34 -08:00
|
|
|
if hasattr(oldGlyph, 'program'):
|
|
|
|
newGlyph.program = oldGlyph.program
|
2015-11-05 14:01:52 -08:00
|
|
|
|
2015-11-04 18:01:34 -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')
|
|
|
|
|
2015-11-04 18:01:34 -08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|