Skip to content

Commit

Permalink
[varLib] Allow feature variations to be active across the entire space (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
madig committed May 15, 2020
1 parent ecc764e commit 45a8fce
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Lib/fontTools/varLib/featureVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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:
Expand Down
34 changes: 34 additions & 0 deletions Tests/varLib/data/FeatureVarsWholeRange.designspace
Original file line number Diff line number Diff line change
@@ -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>
33 changes: 33 additions & 0 deletions Tests/varLib/data/FeatureVarsWholeRangeEmpty.designspace
Original file line number Diff line number Diff line change
@@ -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>
75 changes: 75 additions & 0 deletions Tests/varLib/data/test_results/FeatureVarsWholeRange.ttx
Original file line number Diff line number Diff line change
@@ -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>
24 changes: 24 additions & 0 deletions Tests/varLib/varLib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,30 @@ def test_varlib_build_feature_variations(self):
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
Expand Down

0 comments on commit 45a8fce

Please sign in to comment.