[varLib] Allow feature variations to be active across the entire space (#1957)

* Allow feature variations to be active across the entire space

* Add test with empty condition set

* Skip initial box instead of removing it

* Correct comment
This commit is contained in:
Nikolaus Waxweiler 2020-05-15 17:27:15 +01:00 committed by GitHub
parent ecc764ecc0
commit 45a8fcefc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 170 additions and 1 deletions

View File

@ -82,6 +82,7 @@ def overlayFeatureVariations(conditionalSubstitutions):
... ([{"wght": (0.5, 1.0)}], {"dollar": "dollar.rvrn"}),
... ([{"wght": (0.5, 1.0)}], {"dollar": "dollar.rvrn"}),
... ([{"wdth": (0.5, 1.0)}], {"cent": "cent.rvrn"}),
... ([{"wght": (0.5, 1.0), "wdth": (-1, 1.0)}], {"dollar": "dollar.rvrn"}),
... ]
>>> from pprint import pprint
>>> pprint(overlayFeatureVariations(condSubst))
@ -136,12 +137,14 @@ def overlayFeatureVariations(conditionalSubstitutions):
remainder = hashdict(remainder)
newMap[remainder] = newMap.get(remainder, 0) | rank
boxMap = newMap
del boxMap[hashdict()]
# Generate output
items = []
for box,rank in sorted(boxMap.items(),
key=(lambda BoxAndRank: -popCount(BoxAndRank[1]))):
# Skip any box that doesn't have any substitution.
if rank == 0:
continue
substsList = []
i = 0
while rank:

View File

@ -0,0 +1,34 @@
<?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" />
</axes>
<rules processing="last">
<rule name="always">
<conditionset>
<condition name="weight" minimum="0" maximum="1000" />
</conditionset>
<sub name="uni0024" with="uni0024.nostroke" />
</rule>
</rules>
<sources>
<source familyname="Test Family" filename="master_ufo/TestFamily-Master0.ufo" name="master_0" stylename="Master0">
<location>
<dimension name="weight" 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" />
</location>
</source>
<source familyname="Test Family" filename="master_ufo/TestFamily-Master3.ufo" name="master_3" stylename="Master3">
<location>
<dimension name="weight" xvalue="1000" />
</location>
</source>
</sources>
</designspace>

View File

@ -0,0 +1,33 @@
<?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" />
</axes>
<rules processing="last">
<rule name="always">
<conditionset>
</conditionset>
<sub name="uni0024" with="uni0024.nostroke" />
</rule>
</rules>
<sources>
<source familyname="Test Family" filename="master_ufo/TestFamily-Master0.ufo" name="master_0" stylename="Master0">
<location>
<dimension name="weight" 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" />
</location>
</source>
<source familyname="Test Family" filename="master_ufo/TestFamily-Master3.ufo" name="master_3" stylename="Master3">
<location>
<dimension name="weight" xvalue="1000" />
</location>
</source>
</sources>
</designspace>

View File

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="4.9">
<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>
</fvar>
<GSUB>
<Version value="0x00010001"/>
<ScriptList>
<!-- ScriptCount=1 -->
<ScriptRecord index="0">
<ScriptTag value="DFLT"/>
<Script>
<DefaultLangSys>
<ReqFeatureIndex value="65535"/>
<!-- FeatureCount=1 -->
<FeatureIndex index="0" value="0"/>
</DefaultLangSys>
<!-- LangSysCount=0 -->
</Script>
</ScriptRecord>
</ScriptList>
<FeatureList>
<!-- FeatureCount=1 -->
<FeatureRecord index="0">
<FeatureTag value="rclt"/>
<Feature>
<!-- LookupCount=0 -->
</Feature>
</FeatureRecord>
</FeatureList>
<LookupList>
<!-- LookupCount=1 -->
<Lookup index="0">
<LookupType value="1"/>
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<SingleSubst index="0" Format="1">
<Substitution in="uni0024" out="uni0024.nostroke"/>
</SingleSubst>
</Lookup>
</LookupList>
<FeatureVariations>
<Version value="0x00010000"/>
<!-- FeatureVariationCount=1 -->
<FeatureVariationRecord index="0">
<ConditionSet>
<!-- ConditionCount=0 -->
</ConditionSet>
<FeatureTableSubstitution>
<Version value="0x00010000"/>
<!-- SubstitutionCount=1 -->
<SubstitutionRecord index="0">
<FeatureIndex value="0"/>
<Feature>
<!-- LookupCount=1 -->
<LookupListIndex index="0" value="0"/>
</Feature>
</SubstitutionRecord>
</FeatureTableSubstitution>
</FeatureVariationRecord>
</FeatureVariations>
</GSUB>
</ttFont>

View File

@ -218,6 +218,30 @@ class BuildTest(unittest.TestCase):
save_before_dump=True,
)
def test_varlib_build_feature_variations_whole_range(self):
"""Designspace file contains <rules> element specifying the entire design
space, used to build GSUB FeatureVariations table.
"""
self._run_varlib_build_test(
designspace_name="FeatureVarsWholeRange",
font_name="TestFamily",
tables=["fvar", "GSUB"],
expected_ttx_name="FeatureVarsWholeRange",
save_before_dump=True,
)
def test_varlib_build_feature_variations_whole_range_empty(self):
"""Designspace file contains <rules> element without a condition, specifying
the entire design space, used to build GSUB FeatureVariations table.
"""
self._run_varlib_build_test(
designspace_name="FeatureVarsWholeRangeEmpty",
font_name="TestFamily",
tables=["fvar", "GSUB"],
expected_ttx_name="FeatureVarsWholeRange",
save_before_dump=True,
)
def test_varlib_build_feature_variations_with_existing_rclt(self):
"""Designspace file contains <rules> element, used to build GSUB
FeatureVariations table. <rules> is specified to do its OT processing