[_v_h_e_a_test] Add tests for recalc()

This commit is contained in:
Masaya Nakamura 2017-05-22 14:53:47 +09:00
parent a4fda12810
commit 423e829b73
4 changed files with 235 additions and 0 deletions

View File

@ -5,8 +5,13 @@ from fontTools.misc.testTools import parseXML, getXML
from fontTools.misc.textTools import deHexStr
from fontTools.ttLib import TTFont, newTable
from fontTools.misc.fixedTools import log
import os
import unittest
CURR_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
DATA_DIR = os.path.join(CURR_DIR, 'data')
VHEA_DATA_VERSION_11 = deHexStr(
'0001 1000 ' # 1.1 version
'01F4 ' # 500 ascent
@ -232,6 +237,39 @@ class VheaDecompileOrFromXMLTest(unittest.TestCase):
self.assertEqual(getattr(vhea, key), VHEA_VERSION_11_AS_DICT[key])
class VheaRecalcTest(unittest.TestCase):
def test_recalc_TTF(self):
font = TTFont()
font.importXML(os.path.join(DATA_DIR, '_v_h_e_a_recalc_TTF.ttx'))
vhea = font['vhea']
vhea.recalc(font)
self.assertEqual(vhea.advanceHeightMax, 900)
self.assertEqual(vhea.minTopSideBearing, 200)
self.assertEqual(vhea.minBottomSideBearing, 377)
self.assertEqual(vhea.yMaxExtent, 312)
def test_recalc_OTF(self):
font = TTFont()
font.importXML(os.path.join(DATA_DIR, '_v_h_e_a_recalc_OTF.ttx'))
vhea = font['vhea']
vhea.recalc(font)
self.assertEqual(vhea.advanceHeightMax, 900)
self.assertEqual(vhea.minTopSideBearing, 200)
self.assertEqual(vhea.minBottomSideBearing, 377)
self.assertEqual(vhea.yMaxExtent, 312)
def test_recalc_empty(self):
font = TTFont()
font.importXML(os.path.join(DATA_DIR, '_v_h_e_a_recalc_empty.ttx'))
vhea = font['vhea']
vhea.recalc(font)
self.assertEqual(vhea.advanceHeightMax, 900)
self.assertEqual(vhea.minTopSideBearing, 0)
self.assertEqual(vhea.minBottomSideBearing, 0)
self.assertEqual(vhea.yMaxExtent, 0)
if __name__ == "__main__":
import sys
sys.exit(unittest.main())

View File

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont sfntVersion="OTTO" ttLibVersion="3.12">
<GlyphOrder>
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
<GlyphID id="0" name=".notdef"/>
<GlyphID id="1" name="A"/>
<GlyphID id="2" name="B"/>
<GlyphID id="3" name="C"/>
</GlyphOrder>
<vhea>
<tableVersion value="0x00011000"/>
<ascent value="500"/>
<descent value="-500"/>
<lineGap value="0"/>
<advanceHeightMax value="999"/>
<minTopSideBearing value="99"/>
<minBottomSideBearing value="99"/>
<yMaxExtent value="99"/>
<caretSlopeRise value="0"/>
<caretSlopeRun value="1"/>
<caretOffset value="0"/>
<reserved1 value="0"/>
<reserved2 value="0"/>
<reserved3 value="0"/>
<reserved4 value="0"/>
<metricDataFormat value="0"/>
<numberOfVMetrics value="4"/>
</vhea>
<CFF>
<major value="1"/>
<minor value="0"/>
<CFFFont name="Test">
<Private>
</Private>
<CharStrings>
<CharString name=".notdef">
300
0 0 rmoveto
1 1 rlineto
endchar
</CharString>
<CharString name="A">
400
-55.2 -55.2 rmoveto
110.4 110.4 rlineto
endchar
</CharString>
<CharString name="B">
500
100 0 rmoveto
300 0 rlineto
endchar
</CharString>
<CharString name="C">
600
endchar
</CharString>
</CharStrings>
</CFFFont>
</CFF>
<vmtx>
<mtx name=".notdef" height="600" tsb="222"/>
<mtx name="A" height="700" tsb="200"/>
<mtx name="B" height="800" tsb="300"/>
<mtx name="C" height="900" tsb="0"/>
</vmtx>
</ttFont>

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="3.12">
<GlyphOrder>
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
<GlyphID id="0" name=".notdef"/>
<GlyphID id="1" name="A"/>
<GlyphID id="2" name="B"/>
<GlyphID id="3" name="C"/>
</GlyphOrder>
<vhea>
<tableVersion value="0x00011000"/>
<ascent value="500"/>
<descent value="-500"/>
<lineGap value="0"/>
<advanceHeightMax value="999"/>
<minTopSideBearing value="99"/>
<minBottomSideBearing value="99"/>
<yMaxExtent value="99"/>
<caretSlopeRise value="0"/>
<caretSlopeRun value="1"/>
<caretOffset value="0"/>
<reserved1 value="0"/>
<reserved2 value="0"/>
<reserved3 value="0"/>
<reserved4 value="0"/>
<metricDataFormat value="0"/>
<numberOfVMetrics value="4"/>
</vhea>
<glyf>
<!-- The xMin, yMin, xMax and yMax values
will be recalculated by the compiler. -->
<TTGlyph name=".notdef" xMin="0" yMin="0" xMax="1" yMax="1">
<contour>
<pt x="0" y="0" on="1"/>
<pt x="1" y="1" on="1"/>
</contour>
</TTGlyph>
<TTGlyph name="A" xMin="-56" yMin="-56" xMax="56" yMax="56">
<contour>
<pt x="-56" y="-56" on="1"/>
<pt x="56" y="56" on="1"/>
</contour>
</TTGlyph>
<TTGlyph name="B" xMin="100" yMin="0" xMax="400" yMax="0">
<contour>
<pt x="100" y="0" on="1"/>
<pt x="400" y="0" on="1"/>
</contour>
</TTGlyph>
<TTGlyph name="C"/><!-- contains no outline data -->
</glyf>
<vmtx>
<mtx name=".notdef" height="600" tsb="222"/>
<mtx name="A" height="700" tsb="200"/>
<mtx name="B" height="800" tsb="300"/>
<mtx name="C" height="900" tsb="0"/>
</vmtx>
</ttFont>

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont sfntVersion="OTTO" ttLibVersion="3.12">
<GlyphOrder>
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
<GlyphID id="0" name=".notdef"/>
<GlyphID id="1" name="A"/>
<GlyphID id="2" name="B"/>
<GlyphID id="3" name="C"/>
</GlyphOrder>
<vhea>
<tableVersion value="0x00011000"/>
<ascent value="500"/>
<descent value="-500"/>
<lineGap value="0"/>
<advanceHeightMax value="999"/>
<minTopSideBearing value="99"/>
<minBottomSideBearing value="99"/>
<yMaxExtent value="99"/>
<caretSlopeRise value="0"/>
<caretSlopeRun value="1"/>
<caretOffset value="0"/>
<reserved1 value="0"/>
<reserved2 value="0"/>
<reserved3 value="0"/>
<reserved4 value="0"/>
<metricDataFormat value="0"/>
<numberOfVMetrics value="4"/>
</vhea>
<CFF>
<major value="1"/>
<minor value="0"/>
<CFFFont name="Test">
<Private>
</Private>
<CharStrings>
<CharString name=".notdef">
300 endchar
</CharString>
<CharString name="A">
400 endchar
</CharString>
<CharString name="B">
500 endchar
</CharString>
<CharString name="C">
600 endchar
</CharString>
</CharStrings>
</CFFFont>
</CFF>
<vmtx>
<mtx name=".notdef" height="600" tsb="0"/>
<mtx name="A" height="700" tsb="0"/>
<mtx name="B" height="800" tsb="0"/>
<mtx name="C" height="900" tsb="0"/>
</vmtx>
</ttFont>