varLib_test: add test case for GSUB FeatureVariations
This commit is contained in:
parent
9f18570aac
commit
af8c461c92
71
Tests/varLib/data/FeatureVars.designspace
Normal file
71
Tests/varLib/data/FeatureVars.designspace
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<designspace format="3">
|
||||||
|
<axes>
|
||||||
|
<axis default="368.0" maximum="1000.0" minimum="0.0" name="weight" tag="wght" />
|
||||||
|
<axis default="0.0" maximum="100.0" minimum="0.0" name="contrast" tag="cntr">
|
||||||
|
<labelname xml:lang="en">Contrast</labelname>
|
||||||
|
</axis>
|
||||||
|
</axes>
|
||||||
|
<rules>
|
||||||
|
<rule name="dollar-stroke">
|
||||||
|
<conditionset>
|
||||||
|
<condition name="weight" minimum="500" maximum="1000" />
|
||||||
|
</conditionset>
|
||||||
|
<sub name="uni0024" with="uni0024.nostroke" />
|
||||||
|
</rule>
|
||||||
|
<rule name="to-lowercase">
|
||||||
|
<conditionset>
|
||||||
|
<condition name="contrast" minimum="75" maximum="100" />
|
||||||
|
</conditionset>
|
||||||
|
<sub name="uni0041" with="uni0061" />
|
||||||
|
</rule>
|
||||||
|
<rule name="to-uppercase">
|
||||||
|
<conditionset>
|
||||||
|
<condition name="weight" minimum="0" maximum="200" />
|
||||||
|
<condition name="contrast" minimum="0" maximum="25" />
|
||||||
|
</conditionset>
|
||||||
|
<sub name="uni0061" with="uni0041" />
|
||||||
|
</rule>
|
||||||
|
</rules>
|
||||||
|
<sources>
|
||||||
|
<source familyname="Test Family" filename="master_ufo/TestFamily-Master0.ufo" name="master_0" stylename="Master0">
|
||||||
|
<location>
|
||||||
|
<dimension name="weight" xvalue="0" />
|
||||||
|
<dimension name="contrast" xvalue="0" />
|
||||||
|
</location>
|
||||||
|
</source>
|
||||||
|
<source familyname="Test Family" filename="master_ufo/TestFamily-Master1.ufo" name="master_1" stylename="Master1">
|
||||||
|
<lib copy="1" />
|
||||||
|
<groups copy="1" />
|
||||||
|
<info copy="1" />
|
||||||
|
<location>
|
||||||
|
<dimension name="weight" xvalue="368" />
|
||||||
|
<dimension name="contrast" xvalue="0" />
|
||||||
|
</location>
|
||||||
|
</source>
|
||||||
|
<source familyname="Test Family" filename="master_ufo/TestFamily-Master2.ufo" name="master_2" stylename="Master2">
|
||||||
|
<location>
|
||||||
|
<dimension name="weight" xvalue="1000" />
|
||||||
|
<dimension name="contrast" xvalue="0" />
|
||||||
|
</location>
|
||||||
|
</source>
|
||||||
|
<source familyname="Test Family" filename="master_ufo/TestFamily-Master3.ufo" name="master_3" stylename="Master3">
|
||||||
|
<location>
|
||||||
|
<dimension name="weight" xvalue="1000" />
|
||||||
|
<dimension name="contrast" xvalue="100" />
|
||||||
|
</location>
|
||||||
|
</source>
|
||||||
|
<source familyname="Test Family" filename="master_ufo/TestFamily-Master0.ufo" name="master_0" stylename="Master0">
|
||||||
|
<location>
|
||||||
|
<dimension name="weight" xvalue="0" />
|
||||||
|
<dimension name="contrast" xvalue="100" />
|
||||||
|
</location>
|
||||||
|
</source>
|
||||||
|
<source familyname="Test Family" filename="master_ufo/TestFamily-Master4.ufo" name="master_4" stylename="Master4">
|
||||||
|
<location>
|
||||||
|
<dimension name="weight" xvalue="368" />
|
||||||
|
<dimension name="contrast" xvalue="100" />
|
||||||
|
</location>
|
||||||
|
</source>
|
||||||
|
</sources>
|
||||||
|
</designspace>
|
181
Tests/varLib/data/test_results/FeatureVars.ttx
Normal file
181
Tests/varLib/data/test_results/FeatureVars.ttx
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="3.29">
|
||||||
|
|
||||||
|
<fvar>
|
||||||
|
|
||||||
|
<!-- Weight -->
|
||||||
|
<Axis>
|
||||||
|
<AxisTag>wght</AxisTag>
|
||||||
|
<Flags>0x0</Flags>
|
||||||
|
<MinValue>0.0</MinValue>
|
||||||
|
<DefaultValue>368.0</DefaultValue>
|
||||||
|
<MaxValue>1000.0</MaxValue>
|
||||||
|
<AxisNameID>256</AxisNameID>
|
||||||
|
</Axis>
|
||||||
|
|
||||||
|
<!-- Contrast -->
|
||||||
|
<Axis>
|
||||||
|
<AxisTag>cntr</AxisTag>
|
||||||
|
<Flags>0x0</Flags>
|
||||||
|
<MinValue>0.0</MinValue>
|
||||||
|
<DefaultValue>0.0</DefaultValue>
|
||||||
|
<MaxValue>100.0</MaxValue>
|
||||||
|
<AxisNameID>257</AxisNameID>
|
||||||
|
</Axis>
|
||||||
|
</fvar>
|
||||||
|
|
||||||
|
<GSUB>
|
||||||
|
<Version value="0x00010001"/>
|
||||||
|
<ScriptList>
|
||||||
|
<!-- ScriptCount=1 -->
|
||||||
|
<ScriptRecord index="0">
|
||||||
|
<ScriptTag value="DFLT"/>
|
||||||
|
<Script>
|
||||||
|
<DefaultLangSys>
|
||||||
|
<ReqFeatureIndex value="65535"/>
|
||||||
|
<!-- FeatureCount=2 -->
|
||||||
|
<FeatureIndex index="0" value="0"/>
|
||||||
|
<FeatureIndex index="1" value="0"/>
|
||||||
|
</DefaultLangSys>
|
||||||
|
<!-- LangSysCount=0 -->
|
||||||
|
</Script>
|
||||||
|
</ScriptRecord>
|
||||||
|
</ScriptList>
|
||||||
|
<FeatureList>
|
||||||
|
<!-- FeatureCount=1 -->
|
||||||
|
<FeatureRecord index="0">
|
||||||
|
<FeatureTag value="rvrn"/>
|
||||||
|
<Feature>
|
||||||
|
<!-- LookupCount=0 -->
|
||||||
|
</Feature>
|
||||||
|
</FeatureRecord>
|
||||||
|
</FeatureList>
|
||||||
|
<LookupList>
|
||||||
|
<!-- LookupCount=3 -->
|
||||||
|
<Lookup index="0">
|
||||||
|
<LookupType value="1"/>
|
||||||
|
<LookupFlag value="0"/>
|
||||||
|
<!-- SubTableCount=1 -->
|
||||||
|
<SingleSubst index="0" Format="1">
|
||||||
|
<Substitution in="uni0024" out="uni0024.nostroke"/>
|
||||||
|
</SingleSubst>
|
||||||
|
</Lookup>
|
||||||
|
<Lookup index="1">
|
||||||
|
<LookupType value="1"/>
|
||||||
|
<LookupFlag value="0"/>
|
||||||
|
<!-- SubTableCount=1 -->
|
||||||
|
<SingleSubst index="0" Format="1">
|
||||||
|
<Substitution in="uni0041" out="uni0061"/>
|
||||||
|
</SingleSubst>
|
||||||
|
</Lookup>
|
||||||
|
<Lookup index="2">
|
||||||
|
<LookupType value="1"/>
|
||||||
|
<LookupFlag value="0"/>
|
||||||
|
<!-- SubTableCount=1 -->
|
||||||
|
<SingleSubst index="0" Format="1">
|
||||||
|
<Substitution in="uni0061" out="uni0041"/>
|
||||||
|
</SingleSubst>
|
||||||
|
</Lookup>
|
||||||
|
</LookupList>
|
||||||
|
<FeatureVariations>
|
||||||
|
<Version value="0x00010000"/>
|
||||||
|
<!-- FeatureVariationCount=4 -->
|
||||||
|
<FeatureVariationRecord index="0">
|
||||||
|
<ConditionSet>
|
||||||
|
<!-- ConditionCount=2 -->
|
||||||
|
<ConditionTable index="0" Format="1">
|
||||||
|
<AxisIndex value="1"/>
|
||||||
|
<FilterRangeMinValue value="0.75"/>
|
||||||
|
<FilterRangeMaxValue value="1.0"/>
|
||||||
|
</ConditionTable>
|
||||||
|
<ConditionTable index="1" Format="1">
|
||||||
|
<AxisIndex value="0"/>
|
||||||
|
<FilterRangeMinValue value="0.20886"/>
|
||||||
|
<FilterRangeMaxValue value="1.0"/>
|
||||||
|
</ConditionTable>
|
||||||
|
</ConditionSet>
|
||||||
|
<FeatureTableSubstitution>
|
||||||
|
<Version value="0x00010001"/>
|
||||||
|
<!-- SubstitutionCount=1 -->
|
||||||
|
<SubstitutionRecord index="0">
|
||||||
|
<FeatureIndex value="0"/>
|
||||||
|
<Feature>
|
||||||
|
<!-- LookupCount=2 -->
|
||||||
|
<LookupListIndex index="0" value="0"/>
|
||||||
|
<LookupListIndex index="1" value="1"/>
|
||||||
|
</Feature>
|
||||||
|
</SubstitutionRecord>
|
||||||
|
</FeatureTableSubstitution>
|
||||||
|
</FeatureVariationRecord>
|
||||||
|
<FeatureVariationRecord index="1">
|
||||||
|
<ConditionSet>
|
||||||
|
<!-- ConditionCount=1 -->
|
||||||
|
<ConditionTable index="0" Format="1">
|
||||||
|
<AxisIndex value="0"/>
|
||||||
|
<FilterRangeMinValue value="0.20886"/>
|
||||||
|
<FilterRangeMaxValue value="1.0"/>
|
||||||
|
</ConditionTable>
|
||||||
|
</ConditionSet>
|
||||||
|
<FeatureTableSubstitution>
|
||||||
|
<Version value="0x00010001"/>
|
||||||
|
<!-- SubstitutionCount=1 -->
|
||||||
|
<SubstitutionRecord index="0">
|
||||||
|
<FeatureIndex value="0"/>
|
||||||
|
<Feature>
|
||||||
|
<!-- LookupCount=1 -->
|
||||||
|
<LookupListIndex index="0" value="0"/>
|
||||||
|
</Feature>
|
||||||
|
</SubstitutionRecord>
|
||||||
|
</FeatureTableSubstitution>
|
||||||
|
</FeatureVariationRecord>
|
||||||
|
<FeatureVariationRecord index="2">
|
||||||
|
<ConditionSet>
|
||||||
|
<!-- ConditionCount=1 -->
|
||||||
|
<ConditionTable index="0" Format="1">
|
||||||
|
<AxisIndex value="1"/>
|
||||||
|
<FilterRangeMinValue value="0.75"/>
|
||||||
|
<FilterRangeMaxValue value="1.0"/>
|
||||||
|
</ConditionTable>
|
||||||
|
</ConditionSet>
|
||||||
|
<FeatureTableSubstitution>
|
||||||
|
<Version value="0x00010001"/>
|
||||||
|
<!-- SubstitutionCount=1 -->
|
||||||
|
<SubstitutionRecord index="0">
|
||||||
|
<FeatureIndex value="0"/>
|
||||||
|
<Feature>
|
||||||
|
<!-- LookupCount=1 -->
|
||||||
|
<LookupListIndex index="0" value="1"/>
|
||||||
|
</Feature>
|
||||||
|
</SubstitutionRecord>
|
||||||
|
</FeatureTableSubstitution>
|
||||||
|
</FeatureVariationRecord>
|
||||||
|
<FeatureVariationRecord index="3">
|
||||||
|
<ConditionSet>
|
||||||
|
<!-- ConditionCount=2 -->
|
||||||
|
<ConditionTable index="0" Format="1">
|
||||||
|
<AxisIndex value="1"/>
|
||||||
|
<FilterRangeMinValue value="0.0"/>
|
||||||
|
<FilterRangeMaxValue value="0.25"/>
|
||||||
|
</ConditionTable>
|
||||||
|
<ConditionTable index="1" Format="1">
|
||||||
|
<AxisIndex value="0"/>
|
||||||
|
<FilterRangeMinValue value="-1.0"/>
|
||||||
|
<FilterRangeMaxValue value="-0.45654"/>
|
||||||
|
</ConditionTable>
|
||||||
|
</ConditionSet>
|
||||||
|
<FeatureTableSubstitution>
|
||||||
|
<Version value="0x00010001"/>
|
||||||
|
<!-- SubstitutionCount=1 -->
|
||||||
|
<SubstitutionRecord index="0">
|
||||||
|
<FeatureIndex value="0"/>
|
||||||
|
<Feature>
|
||||||
|
<!-- LookupCount=1 -->
|
||||||
|
<LookupListIndex index="0" value="2"/>
|
||||||
|
</Feature>
|
||||||
|
</SubstitutionRecord>
|
||||||
|
</FeatureTableSubstitution>
|
||||||
|
</FeatureVariationRecord>
|
||||||
|
</FeatureVariations>
|
||||||
|
</GSUB>
|
||||||
|
|
||||||
|
</ttFont>
|
@ -95,7 +95,7 @@ class BuildTest(unittest.TestCase):
|
|||||||
return font, savepath
|
return font, savepath
|
||||||
|
|
||||||
def _run_varlib_build_test(self, designspace_name, font_name, tables,
|
def _run_varlib_build_test(self, designspace_name, font_name, tables,
|
||||||
expected_ttx_name):
|
expected_ttx_name, save_before_dump=False):
|
||||||
suffix = '.ttf'
|
suffix = '.ttf'
|
||||||
ds_path = self.get_test_input(designspace_name + '.designspace')
|
ds_path = self.get_test_input(designspace_name + '.designspace')
|
||||||
ufo_dir = self.get_test_input('master_ufo')
|
ufo_dir = self.get_test_input('master_ufo')
|
||||||
@ -109,6 +109,15 @@ class BuildTest(unittest.TestCase):
|
|||||||
finder = lambda s: s.replace(ufo_dir, self.tempdir).replace('.ufo', suffix)
|
finder = lambda s: s.replace(ufo_dir, self.tempdir).replace('.ufo', suffix)
|
||||||
varfont, model, _ = build(ds_path, finder)
|
varfont, model, _ = build(ds_path, finder)
|
||||||
|
|
||||||
|
if save_before_dump:
|
||||||
|
# some data (e.g. counts printed in TTX inline comments) is only
|
||||||
|
# calculated at compile time, so before we can compare the TTX
|
||||||
|
# dumps we need to save to a temporary stream, and realod the font
|
||||||
|
buf = BytesIO()
|
||||||
|
varfont.save(buf)
|
||||||
|
buf.seek(0)
|
||||||
|
varfont = TTFont(buf)
|
||||||
|
|
||||||
expected_ttx_path = self.get_test_output(expected_ttx_name + '.ttx')
|
expected_ttx_path = self.get_test_output(expected_ttx_name + '.ttx')
|
||||||
self.expect_ttx(varfont, expected_ttx_path, tables)
|
self.expect_ttx(varfont, expected_ttx_path, tables)
|
||||||
self.check_ttx_dump(varfont, expected_ttx_path, tables, suffix)
|
self.check_ttx_dump(varfont, expected_ttx_path, tables, suffix)
|
||||||
@ -183,6 +192,18 @@ class BuildTest(unittest.TestCase):
|
|||||||
expected_ttx_name=test_name
|
expected_ttx_name=test_name
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_varlib_build_feature_variations(self):
|
||||||
|
"""Designspace file contains <rules> element, used to build
|
||||||
|
GSUB FeatureVariations table.
|
||||||
|
"""
|
||||||
|
self._run_varlib_build_test(
|
||||||
|
designspace_name="FeatureVars",
|
||||||
|
font_name="TestFamily",
|
||||||
|
tables=["fvar", "GSUB"],
|
||||||
|
expected_ttx_name="FeatureVars",
|
||||||
|
save_before_dump=True,
|
||||||
|
)
|
||||||
|
|
||||||
def test_varlib_main_ttf(self):
|
def test_varlib_main_ttf(self):
|
||||||
"""Mostly for testing varLib.main()
|
"""Mostly for testing varLib.main()
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user