[_h_h_e_a_test] Add tests for recalc()
This commit is contained in:
parent
1b773c17d7
commit
a4fda12810
@ -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')
|
||||
|
||||
HHEA_DATA = deHexStr(
|
||||
'0001 0000 ' # 1.0 version
|
||||
'02EE ' # 750 ascent
|
||||
@ -155,6 +160,39 @@ class HheaDecompileOrFromXMLTest(unittest.TestCase):
|
||||
self.assertEqual(getattr(hhea, key), HHEA_AS_DICT[key])
|
||||
|
||||
|
||||
class HheaRecalcTest(unittest.TestCase):
|
||||
|
||||
def test_recalc_TTF(self):
|
||||
font = TTFont()
|
||||
font.importXML(os.path.join(DATA_DIR, '_h_h_e_a_recalc_TTF.ttx'))
|
||||
hhea = font['hhea']
|
||||
hhea.recalc(font)
|
||||
self.assertEqual(hhea.advanceWidthMax, 600)
|
||||
self.assertEqual(hhea.minLeftSideBearing, -56)
|
||||
self.assertEqual(hhea.minRightSideBearing, 100)
|
||||
self.assertEqual(hhea.xMaxExtent, 400)
|
||||
|
||||
def test_recalc_OTF(self):
|
||||
font = TTFont()
|
||||
font.importXML(os.path.join(DATA_DIR, '_h_h_e_a_recalc_OTF.ttx'))
|
||||
hhea = font['hhea']
|
||||
hhea.recalc(font)
|
||||
self.assertEqual(hhea.advanceWidthMax, 600)
|
||||
self.assertEqual(hhea.minLeftSideBearing, -56)
|
||||
self.assertEqual(hhea.minRightSideBearing, 100)
|
||||
self.assertEqual(hhea.xMaxExtent, 400)
|
||||
|
||||
def test_recalc_empty(self):
|
||||
font = TTFont()
|
||||
font.importXML(os.path.join(DATA_DIR, '_h_h_e_a_recalc_empty.ttx'))
|
||||
hhea = font['hhea']
|
||||
hhea.recalc(font)
|
||||
self.assertEqual(hhea.advanceWidthMax, 600)
|
||||
self.assertEqual(hhea.minLeftSideBearing, 0)
|
||||
self.assertEqual(hhea.minRightSideBearing, 0)
|
||||
self.assertEqual(hhea.xMaxExtent, 0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
sys.exit(unittest.main())
|
||||
|
72
Tests/ttLib/tables/data/_h_h_e_a_recalc_OTF.ttx
Normal file
72
Tests/ttLib/tables/data/_h_h_e_a_recalc_OTF.ttx
Normal 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>
|
||||
|
||||
<hhea>
|
||||
<tableVersion value="0x00010000"/>
|
||||
<ascent value="800"/>
|
||||
<descent value="-200"/>
|
||||
<lineGap value="0"/>
|
||||
<advanceWidthMax value="999"/>
|
||||
<minLeftSideBearing value="99"/>
|
||||
<minRightSideBearing value="99"/>
|
||||
<xMaxExtent value="99"/>
|
||||
<caretSlopeRise value="1"/>
|
||||
<caretSlopeRun value="0"/>
|
||||
<caretOffset value="0"/>
|
||||
<reserved0 value="0"/>
|
||||
<reserved1 value="0"/>
|
||||
<reserved2 value="0"/>
|
||||
<reserved3 value="0"/>
|
||||
<metricDataFormat value="0"/>
|
||||
<numberOfHMetrics value="4"/>
|
||||
</hhea>
|
||||
|
||||
<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>
|
||||
|
||||
<hmtx>
|
||||
<mtx name=".notdef" width="300" lsb="0"/>
|
||||
<mtx name="A" width="400" lsb="-56"/>
|
||||
<mtx name="B" width="500" lsb="100"/>
|
||||
<mtx name="C" width="600" lsb="0"/>
|
||||
</hmtx>
|
||||
|
||||
</ttFont>
|
63
Tests/ttLib/tables/data/_h_h_e_a_recalc_TTF.ttx
Normal file
63
Tests/ttLib/tables/data/_h_h_e_a_recalc_TTF.ttx
Normal 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>
|
||||
|
||||
<hhea>
|
||||
<tableVersion value="0x00010000"/>
|
||||
<ascent value="800"/>
|
||||
<descent value="-200"/>
|
||||
<lineGap value="0"/>
|
||||
<advanceWidthMax value="999"/>
|
||||
<minLeftSideBearing value="99"/>
|
||||
<minRightSideBearing value="99"/>
|
||||
<xMaxExtent value="99"/>
|
||||
<caretSlopeRise value="1"/>
|
||||
<caretSlopeRun value="0"/>
|
||||
<caretOffset value="0"/>
|
||||
<reserved0 value="0"/>
|
||||
<reserved1 value="0"/>
|
||||
<reserved2 value="0"/>
|
||||
<reserved3 value="0"/>
|
||||
<metricDataFormat value="0"/>
|
||||
<numberOfHMetrics value="4"/>
|
||||
</hhea>
|
||||
|
||||
<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>
|
||||
|
||||
<hmtx>
|
||||
<mtx name=".notdef" width="300" lsb="0"/>
|
||||
<mtx name="A" width="400" lsb="-56"/>
|
||||
<mtx name="B" width="500" lsb="100"/>
|
||||
<mtx name="C" width="600" lsb="0"/>
|
||||
</hmtx>
|
||||
|
||||
</ttFont>
|
62
Tests/ttLib/tables/data/_h_h_e_a_recalc_empty.ttx
Normal file
62
Tests/ttLib/tables/data/_h_h_e_a_recalc_empty.ttx
Normal 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>
|
||||
|
||||
<hhea>
|
||||
<tableVersion value="0x00010000"/>
|
||||
<ascent value="800"/>
|
||||
<descent value="-200"/>
|
||||
<lineGap value="0"/>
|
||||
<advanceWidthMax value="999"/>
|
||||
<minLeftSideBearing value="99"/>
|
||||
<minRightSideBearing value="99"/>
|
||||
<xMaxExtent value="99"/>
|
||||
<caretSlopeRise value="1"/>
|
||||
<caretSlopeRun value="0"/>
|
||||
<caretOffset value="0"/>
|
||||
<reserved0 value="0"/>
|
||||
<reserved1 value="0"/>
|
||||
<reserved2 value="0"/>
|
||||
<reserved3 value="0"/>
|
||||
<metricDataFormat value="0"/>
|
||||
<numberOfHMetrics value="4"/>
|
||||
</hhea>
|
||||
|
||||
<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>
|
||||
|
||||
<hmtx>
|
||||
<mtx name=".notdef" width="300" lsb="0"/>
|
||||
<mtx name="A" width="400" lsb="0"/>
|
||||
<mtx name="B" width="500" lsb="0"/>
|
||||
<mtx name="C" width="600" lsb="0"/>
|
||||
</hmtx>
|
||||
|
||||
</ttFont>
|
Loading…
x
Reference in New Issue
Block a user