Merge remote-tracking branch 'origin/master' into colrv1-latest
This commit is contained in:
commit
09fa418eb0
@ -30,6 +30,7 @@ from fontTools.otlLib.error import OpenTypeLibError
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -707,9 +708,13 @@ class Builder(object):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
for ix in lookup_indices:
|
for ix in lookup_indices:
|
||||||
self.lookup_locations[tag][str(ix)] = self.lookup_locations[tag][
|
try:
|
||||||
str(ix)
|
self.lookup_locations[tag][str(ix)] = self.lookup_locations[tag][
|
||||||
]._replace(feature=key)
|
str(ix)
|
||||||
|
]._replace(feature=key)
|
||||||
|
except KeyError:
|
||||||
|
warnings.warn("feaLib.Builder subclass needs upgrading to "
|
||||||
|
"stash debug information. See fonttools#2065.")
|
||||||
|
|
||||||
feature_key = (feature_tag, lookup_indices)
|
feature_key = (feature_tag, lookup_indices)
|
||||||
feature_index = feature_indices.get(feature_key)
|
feature_index = feature_indices.get(feature_key)
|
||||||
|
@ -43,6 +43,10 @@ from .errors import VarLibError, VarLibValidationError
|
|||||||
|
|
||||||
log = logging.getLogger("fontTools.varLib")
|
log = logging.getLogger("fontTools.varLib")
|
||||||
|
|
||||||
|
# This is a lib key for the designspace document. The value should be
|
||||||
|
# an OpenType feature tag, to be used as the FeatureVariations feature.
|
||||||
|
# If present, the DesignSpace <rules processing="..."> flag is ignored.
|
||||||
|
FEAVAR_FEATURETAG_LIB_KEY = "com.github.fonttools.varLib.featureVarsFeatureTag"
|
||||||
|
|
||||||
#
|
#
|
||||||
# Creation routines
|
# Creation routines
|
||||||
@ -629,7 +633,7 @@ def _merge_OTL(font, model, master_fonts, axisTags):
|
|||||||
font['GPOS'].table.remap_device_varidxes(varidx_map)
|
font['GPOS'].table.remap_device_varidxes(varidx_map)
|
||||||
|
|
||||||
|
|
||||||
def _add_GSUB_feature_variations(font, axes, internal_axis_supports, rules, rulesProcessingLast):
|
def _add_GSUB_feature_variations(font, axes, internal_axis_supports, rules, featureTag):
|
||||||
|
|
||||||
def normalize(name, value):
|
def normalize(name, value):
|
||||||
return models.normalizeLocation(
|
return models.normalizeLocation(
|
||||||
@ -664,10 +668,6 @@ def _add_GSUB_feature_variations(font, axes, internal_axis_supports, rules, rule
|
|||||||
|
|
||||||
conditional_subs.append((region, subs))
|
conditional_subs.append((region, subs))
|
||||||
|
|
||||||
if rulesProcessingLast:
|
|
||||||
featureTag = 'rclt'
|
|
||||||
else:
|
|
||||||
featureTag = 'rvrn'
|
|
||||||
addFeatureVariations(font, conditional_subs, featureTag)
|
addFeatureVariations(font, conditional_subs, featureTag)
|
||||||
|
|
||||||
|
|
||||||
@ -682,6 +682,7 @@ _DesignSpaceData = namedtuple(
|
|||||||
"instances",
|
"instances",
|
||||||
"rules",
|
"rules",
|
||||||
"rulesProcessingLast",
|
"rulesProcessingLast",
|
||||||
|
"lib",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -811,6 +812,7 @@ def load_designspace(designspace):
|
|||||||
instances,
|
instances,
|
||||||
ds.rules,
|
ds.rules,
|
||||||
ds.rulesProcessingLast,
|
ds.rulesProcessingLast,
|
||||||
|
ds.lib,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -917,7 +919,11 @@ def build(designspace, master_finder=lambda s:s, exclude=[], optimize=True):
|
|||||||
if 'cvar' not in exclude and 'glyf' in vf:
|
if 'cvar' not in exclude and 'glyf' in vf:
|
||||||
_merge_TTHinting(vf, model, master_fonts)
|
_merge_TTHinting(vf, model, master_fonts)
|
||||||
if 'GSUB' not in exclude and ds.rules:
|
if 'GSUB' not in exclude and ds.rules:
|
||||||
_add_GSUB_feature_variations(vf, ds.axes, ds.internal_axis_supports, ds.rules, ds.rulesProcessingLast)
|
featureTag = ds.lib.get(
|
||||||
|
FEAVAR_FEATURETAG_LIB_KEY,
|
||||||
|
"rclt" if ds.rulesProcessingLast else "rvrn"
|
||||||
|
)
|
||||||
|
_add_GSUB_feature_variations(vf, ds.axes, ds.internal_axis_supports, ds.rules, featureTag)
|
||||||
if 'CFF2' not in exclude and ('CFF ' in vf or 'CFF2' in vf):
|
if 'CFF2' not in exclude and ('CFF ' in vf or 'CFF2' in vf):
|
||||||
_add_CFF2(vf, model, master_fonts)
|
_add_CFF2(vf, model, master_fonts)
|
||||||
if "post" in vf:
|
if "post" in vf:
|
||||||
|
@ -68,7 +68,7 @@ class OnlineVarStoreBuilder(object):
|
|||||||
self._outer = varDataIdx
|
self._outer = varDataIdx
|
||||||
self._data = self._store.VarData[varDataIdx]
|
self._data = self._store.VarData[varDataIdx]
|
||||||
self._cache = self._varDataCaches[key]
|
self._cache = self._varDataCaches[key]
|
||||||
if len(self._data.Item) == 0xFFF:
|
if len(self._data.Item) == 0xFFFF:
|
||||||
# This is full. Need new one.
|
# This is full. Need new one.
|
||||||
varDataIdx = None
|
varDataIdx = None
|
||||||
|
|
||||||
|
77
Tests/varLib/data/FeatureVarsCustomTag.designspace
Normal file
77
Tests/varLib/data/FeatureVarsCustomTag.designspace
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?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 processing="last">
|
||||||
|
<rule name="dollar-stroke">
|
||||||
|
<conditionset>
|
||||||
|
<condition name="weight" minimum="500" /> <!-- intentionally omitted maximum -->
|
||||||
|
</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>
|
||||||
|
<lib>
|
||||||
|
<dict>
|
||||||
|
<key>com.github.fonttools.varLib.featureVarsFeatureTag</key>
|
||||||
|
<string>calt</string>
|
||||||
|
</dict>
|
||||||
|
</lib>
|
||||||
|
</designspace>
|
180
Tests/varLib/data/test_results/FeatureVarsCustomTag.ttx
Normal file
180
Tests/varLib/data/test_results/FeatureVarsCustomTag.ttx
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
<?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=1 -->
|
||||||
|
<FeatureIndex index="0" value="0"/>
|
||||||
|
</DefaultLangSys>
|
||||||
|
<!-- LangSysCount=0 -->
|
||||||
|
</Script>
|
||||||
|
</ScriptRecord>
|
||||||
|
</ScriptList>
|
||||||
|
<FeatureList>
|
||||||
|
<!-- FeatureCount=1 -->
|
||||||
|
<FeatureRecord index="0">
|
||||||
|
<FeatureTag value="calt"/>
|
||||||
|
<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="0x00010000"/>
|
||||||
|
<!-- 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=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="0x00010000"/>
|
||||||
|
<!-- SubstitutionCount=1 -->
|
||||||
|
<SubstitutionRecord index="0">
|
||||||
|
<FeatureIndex value="0"/>
|
||||||
|
<Feature>
|
||||||
|
<!-- LookupCount=1 -->
|
||||||
|
<LookupListIndex index="0" value="2"/>
|
||||||
|
</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="0x00010000"/>
|
||||||
|
<!-- 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=1 -->
|
||||||
|
<ConditionTable index="0" Format="1">
|
||||||
|
<AxisIndex value="0"/>
|
||||||
|
<FilterRangeMinValue value="0.20886"/>
|
||||||
|
<FilterRangeMaxValue value="1.0"/>
|
||||||
|
</ConditionTable>
|
||||||
|
</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>
|
@ -221,6 +221,18 @@ class BuildTest(unittest.TestCase):
|
|||||||
save_before_dump=True,
|
save_before_dump=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_varlib_build_feature_variations_custom_tag(self):
|
||||||
|
"""Designspace file contains <rules> element, used to build
|
||||||
|
GSUB FeatureVariations table.
|
||||||
|
"""
|
||||||
|
self._run_varlib_build_test(
|
||||||
|
designspace_name="FeatureVarsCustomTag",
|
||||||
|
font_name="TestFamily",
|
||||||
|
tables=["fvar", "GSUB"],
|
||||||
|
expected_ttx_name="FeatureVarsCustomTag",
|
||||||
|
save_before_dump=True,
|
||||||
|
)
|
||||||
|
|
||||||
def test_varlib_build_feature_variations_whole_range(self):
|
def test_varlib_build_feature_variations_whole_range(self):
|
||||||
"""Designspace file contains <rules> element specifying the entire design
|
"""Designspace file contains <rules> element specifying the entire design
|
||||||
space, used to build GSUB FeatureVariations table.
|
space, used to build GSUB FeatureVariations table.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user