[TTGlyphPen] Add a new e2e test
This commit is contained in:
parent
b511b2b0d8
commit
f5b9ec0186
@ -9,30 +9,37 @@ from fontTools.pens.ttGlyphPen import TTGlyphPen
|
|||||||
|
|
||||||
|
|
||||||
class TTGlyphPenTest(unittest.TestCase):
|
class TTGlyphPenTest(unittest.TestCase):
|
||||||
def setUp(self):
|
|
||||||
#self.font = ttLib.TTFont(recalcBBoxes=False, recalcTimestamp=False)
|
def runEndToEnd(self, filename):
|
||||||
self.font = ttLib.TTFont()
|
font = ttLib.TTFont()
|
||||||
ttx_path = os.path.join(
|
ttx_path = os.path.join(
|
||||||
os.path.abspath(os.path.dirname(os.path.realpath(__file__))),
|
os.path.abspath(os.path.dirname(os.path.realpath(__file__))),
|
||||||
'..', 'ttLib', 'testdata', 'TestTTF-Regular.ttx')
|
'..', 'ttLib', 'testdata', filename)
|
||||||
self.font.importXML(ttx_path, quiet=True)
|
font.importXML(ttx_path, quiet=True)
|
||||||
self.pen = TTGlyphPen(self.font.getGlyphSet())
|
|
||||||
|
|
||||||
def test_drawGlyphsUnchanged(self):
|
glyphSet = font.getGlyphSet()
|
||||||
glyphSet = self.font.getGlyphSet()
|
glyfTable = font['glyf']
|
||||||
glyfTable = self.font['glyf']
|
pen = TTGlyphPen(font.getGlyphSet())
|
||||||
|
|
||||||
for name in self.font.getGlyphOrder():
|
for name in font.getGlyphOrder():
|
||||||
oldGlyph = glyphSet[name]
|
oldGlyph = glyphSet[name]
|
||||||
oldGlyph.draw(self.pen)
|
oldGlyph.draw(pen)
|
||||||
oldGlyph = oldGlyph._glyph
|
oldGlyph = oldGlyph._glyph
|
||||||
newGlyph = self.pen.glyph()
|
newGlyph = pen.glyph()
|
||||||
|
|
||||||
newGlyph.recalcBounds(glyfTable)
|
newGlyph.recalcBounds(glyfTable)
|
||||||
if hasattr(oldGlyph, 'program'):
|
if hasattr(oldGlyph, 'program'):
|
||||||
newGlyph.program = oldGlyph.program
|
newGlyph.program = oldGlyph.program
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
oldGlyph.compile(glyfTable), newGlyph.compile(glyfTable))
|
oldGlyph.compile(glyfTable), newGlyph.compile(glyfTable))
|
||||||
|
|
||||||
|
def test_e2e_linesAndSimpleComponents(self):
|
||||||
|
self.runEndToEnd('TestTTF-Regular.ttx')
|
||||||
|
|
||||||
|
def test_e2e_curvesAndComponentTransforms(self):
|
||||||
|
self.runEndToEnd('TestTTFComplex-Regular.ttx')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
114
Lib/fontTools/ttLib/testdata/TestTTFComplex-Regular.ttx
vendored
Normal file
114
Lib/fontTools/ttLib/testdata/TestTTFComplex-Regular.ttx
vendored
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="2.5">
|
||||||
|
|
||||||
|
<GlyphOrder>
|
||||||
|
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
|
||||||
|
<GlyphID id="0" name=".notdef"/>
|
||||||
|
<GlyphID id="1" name=".null"/>
|
||||||
|
<GlyphID id="2" name="CR"/>
|
||||||
|
<GlyphID id="3" name="space"/>
|
||||||
|
<GlyphID id="4" name="period"/>
|
||||||
|
<GlyphID id="5" name="ellipsis"/>
|
||||||
|
</GlyphOrder>
|
||||||
|
|
||||||
|
<maxp>
|
||||||
|
<!-- Most of this table will be recalculated by the compiler -->
|
||||||
|
<tableVersion value="0x10000"/>
|
||||||
|
<numGlyphs value="6"/>
|
||||||
|
<maxPoints value="8"/>
|
||||||
|
<maxContours value="2"/>
|
||||||
|
<maxCompositePoints value="12"/>
|
||||||
|
<maxCompositeContours value="3"/>
|
||||||
|
<maxZones value="1"/>
|
||||||
|
<maxTwilightPoints value="0"/>
|
||||||
|
<maxStorage value="0"/>
|
||||||
|
<maxFunctionDefs value="0"/>
|
||||||
|
<maxInstructionDefs value="0"/>
|
||||||
|
<maxStackElements value="0"/>
|
||||||
|
<maxSizeOfInstructions value="0"/>
|
||||||
|
<maxComponentElements value="3"/>
|
||||||
|
<maxComponentDepth value="1"/>
|
||||||
|
</maxp>
|
||||||
|
|
||||||
|
<hmtx>
|
||||||
|
<mtx name=".notdef" width="500" lsb="50"/>
|
||||||
|
<mtx name=".null" width="0" lsb="0"/>
|
||||||
|
<mtx name="CR" width="250" lsb="0"/>
|
||||||
|
<mtx name="ellipsis" width="723" lsb="55"/>
|
||||||
|
<mtx name="period" width="241" lsb="55"/>
|
||||||
|
<mtx name="space" width="250" lsb="0"/>
|
||||||
|
</hmtx>
|
||||||
|
|
||||||
|
<cmap>
|
||||||
|
<tableVersion version="0"/>
|
||||||
|
<cmap_format_4 platformID="3" platEncID="1" language="0">
|
||||||
|
<map code="0x0" name=".null"/><!-- ???? -->
|
||||||
|
<map code="0xd" name="CR"/><!-- ???? -->
|
||||||
|
<map code="0x20" name="space"/><!-- SPACE -->
|
||||||
|
<map code="0x2e" name="period"/><!-- FULL STOP -->
|
||||||
|
<map code="0x2026" name="ellipsis"/><!-- HORIZONTAL ELLIPSIS -->
|
||||||
|
</cmap_format_4>
|
||||||
|
</cmap>
|
||||||
|
|
||||||
|
<glyf>
|
||||||
|
|
||||||
|
<!-- The xMin, yMin, xMax and yMax values
|
||||||
|
will be recalculated by the compiler. -->
|
||||||
|
|
||||||
|
<TTGlyph name=".notdef" xMin="50" yMin="0" xMax="450" yMax="750">
|
||||||
|
<contour>
|
||||||
|
<pt x="250" y="0" on="1"/>
|
||||||
|
<pt x="50" y="0" on="0"/>
|
||||||
|
<pt x="50" y="375" on="1"/>
|
||||||
|
<pt x="50" y="750" on="0"/>
|
||||||
|
<pt x="250" y="750" on="1"/>
|
||||||
|
<pt x="450" y="750" on="0"/>
|
||||||
|
<pt x="450" y="375" on="1"/>
|
||||||
|
<pt x="450" y="0" on="0"/>
|
||||||
|
</contour>
|
||||||
|
<contour>
|
||||||
|
<pt x="250" y="50" on="1"/>
|
||||||
|
<pt x="300" y="50" on="0"/>
|
||||||
|
<pt x="400" y="325" on="0"/>
|
||||||
|
<pt x="400" y="375" on="1"/>
|
||||||
|
<pt x="400" y="425" on="0"/>
|
||||||
|
<pt x="300" y="700" on="0"/>
|
||||||
|
<pt x="250" y="700" on="1"/>
|
||||||
|
<pt x="200" y="700" on="0"/>
|
||||||
|
<pt x="100" y="425" on="0"/>
|
||||||
|
<pt x="100" y="375" on="1"/>
|
||||||
|
<pt x="100" y="325" on="0"/>
|
||||||
|
<pt x="200" y="50" on="0"/>
|
||||||
|
</contour>
|
||||||
|
<instructions><assembly>
|
||||||
|
</assembly></instructions>
|
||||||
|
</TTGlyph>
|
||||||
|
|
||||||
|
<TTGlyph name=".null"/><!-- contains no outline data -->
|
||||||
|
|
||||||
|
<TTGlyph name="CR"/><!-- contains no outline data -->
|
||||||
|
|
||||||
|
<TTGlyph name="ellipsis" xMin="55" yMin="0" xMax="668" yMax="122">
|
||||||
|
<component glyphName="period" x="0" y="0" scale="1.5" flags="0x4"/>
|
||||||
|
<component glyphName="period" x="241" y="0" scale="1.5" flags="0x4"/>
|
||||||
|
<component glyphName="period" x="482" y="0" scale="1.5" flags="0x4"/>
|
||||||
|
<instructions><assembly>
|
||||||
|
</assembly></instructions>
|
||||||
|
</TTGlyph>
|
||||||
|
|
||||||
|
<TTGlyph name="period" xMin="55" yMin="0" xMax="186" yMax="122">
|
||||||
|
<contour>
|
||||||
|
<pt x="55" y="122" on="0"/>
|
||||||
|
<pt x="186" y="122" on="0"/>
|
||||||
|
<pt x="186" y="0" on="0"/>
|
||||||
|
<pt x="55" y="0" on="0"/>
|
||||||
|
</contour>
|
||||||
|
<instructions><assembly>
|
||||||
|
</assembly></instructions>
|
||||||
|
</TTGlyph>
|
||||||
|
|
||||||
|
<TTGlyph name="space"/><!-- contains no outline data -->
|
||||||
|
|
||||||
|
</glyf>
|
||||||
|
|
||||||
|
</ttFont>
|
Loading…
x
Reference in New Issue
Block a user