fontBuilder: add FontBuilder.addFeatureVariations method
like the existing addOpenTypeFeatures it simply forwards to featureVars.addFeatureVariations
This commit is contained in:
parent
e2c60e3dcb
commit
e821f1fb9e
@ -751,6 +751,20 @@ class FontBuilder(object):
|
||||
from .feaLib.builder import addOpenTypeFeaturesFromString
|
||||
addOpenTypeFeaturesFromString(self.font, features, filename=filename, tables=tables)
|
||||
|
||||
def addFeatureVariations(self, conditionalSubstitutions, featureTag="rvrn"):
|
||||
"""Add conditional substitutions to a Variable Font.
|
||||
|
||||
See `fontTools.varLib.featureVars.addFeatureVariations`.
|
||||
"""
|
||||
from .varLib import featureVars
|
||||
|
||||
if "fvar" not in self.font:
|
||||
raise KeyError("'fvar' table is missing; can't add FeatureVariations.")
|
||||
|
||||
featureVars.addFeatureVariations(
|
||||
self.font, conditionalSubstitutions, featureTag=featureTag
|
||||
)
|
||||
|
||||
|
||||
def buildCmapSubTable(cmapping, format, platformID, platEncID):
|
||||
subTable = cmap_classes[format](format)
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="3.32">
|
||||
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="4.2">
|
||||
|
||||
<GlyphOrder>
|
||||
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
|
||||
@ -19,7 +19,7 @@
|
||||
<unitsPerEm value="1024"/>
|
||||
<created value="Thu Nov 1 20:29:01 2018"/>
|
||||
<modified value="Thu Nov 1 20:29:01 2018"/>
|
||||
<xMin value="100"/>
|
||||
<xMin value="50"/>
|
||||
<yMin value="0"/>
|
||||
<xMax value="500"/>
|
||||
<yMax value="400"/>
|
||||
@ -36,7 +36,7 @@
|
||||
<descent value="200"/>
|
||||
<lineGap value="0"/>
|
||||
<advanceWidthMax value="600"/>
|
||||
<minLeftSideBearing value="100"/>
|
||||
<minLeftSideBearing value="50"/>
|
||||
<minRightSideBearing value="100"/>
|
||||
<xMaxExtent value="500"/>
|
||||
<caretSlopeRise value="1"/>
|
||||
@ -126,7 +126,7 @@
|
||||
<mtx name=".notdef" width="600" lsb="0"/>
|
||||
<mtx name=".null" width="600" lsb="0"/>
|
||||
<mtx name="A" width="600" lsb="100"/>
|
||||
<mtx name="a" width="600" lsb="100"/>
|
||||
<mtx name="a" width="600" lsb="50"/>
|
||||
</hmtx>
|
||||
|
||||
<cmap>
|
||||
@ -164,12 +164,12 @@
|
||||
<instructions/>
|
||||
</TTGlyph>
|
||||
|
||||
<TTGlyph name="a" xMin="100" yMin="0" xMax="500" yMax="400">
|
||||
<TTGlyph name="a" xMin="50" yMin="0" xMax="250" yMax="200">
|
||||
<contour>
|
||||
<pt x="100" y="0" on="1"/>
|
||||
<pt x="100" y="400" on="1"/>
|
||||
<pt x="500" y="400" on="1"/>
|
||||
<pt x="500" y="0" on="1"/>
|
||||
<pt x="50" y="0" on="1"/>
|
||||
<pt x="50" y="200" on="1"/>
|
||||
<pt x="250" y="200" on="1"/>
|
||||
<pt x="250" y="0" on="1"/>
|
||||
</contour>
|
||||
<instructions/>
|
||||
</TTGlyph>
|
||||
@ -269,6 +269,100 @@
|
||||
</extraNames>
|
||||
</post>
|
||||
|
||||
<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="A" out="a"/>
|
||||
</SingleSubst>
|
||||
</Lookup>
|
||||
</LookupList>
|
||||
<FeatureVariations>
|
||||
<Version value="0x00010000"/>
|
||||
<!-- FeatureVariationCount=2 -->
|
||||
<FeatureVariationRecord index="0">
|
||||
<ConditionSet>
|
||||
<!-- ConditionCount=2 -->
|
||||
<ConditionTable index="0" Format="1">
|
||||
<AxisIndex value="3"/>
|
||||
<FilterRangeMinValue value="0.8"/>
|
||||
<FilterRangeMaxValue value="1.0"/>
|
||||
</ConditionTable>
|
||||
<ConditionTable index="1" Format="1">
|
||||
<AxisIndex value="0"/>
|
||||
<FilterRangeMinValue value="0.8"/>
|
||||
<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>
|
||||
<FeatureVariationRecord index="1">
|
||||
<ConditionSet>
|
||||
<!-- ConditionCount=2 -->
|
||||
<ConditionTable index="0" Format="1">
|
||||
<AxisIndex value="1"/>
|
||||
<FilterRangeMinValue value="0.8"/>
|
||||
<FilterRangeMaxValue value="1.0"/>
|
||||
</ConditionTable>
|
||||
<ConditionTable index="1" Format="1">
|
||||
<AxisIndex value="2"/>
|
||||
<FilterRangeMinValue value="0.8"/>
|
||||
<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>
|
||||
|
||||
<fvar>
|
||||
|
||||
<!-- Left -->
|
||||
|
@ -164,13 +164,20 @@ def test_build_var(tmpdir):
|
||||
pen.lineTo((500, 400))
|
||||
pen.lineTo((500, 000))
|
||||
pen.closePath()
|
||||
glyph1 = pen.glyph()
|
||||
|
||||
glyph = pen.glyph()
|
||||
pen = TTGlyphPen(None)
|
||||
pen.moveTo((50, 0))
|
||||
pen.lineTo((50, 200))
|
||||
pen.lineTo((250, 200))
|
||||
pen.lineTo((250, 0))
|
||||
pen.closePath()
|
||||
glyph2 = pen.glyph()
|
||||
|
||||
pen = TTGlyphPen(None)
|
||||
emptyGlyph = pen.glyph()
|
||||
|
||||
glyphs = {".notdef": emptyGlyph, "A": glyph, "a": glyph, ".null": emptyGlyph}
|
||||
glyphs = {".notdef": emptyGlyph, "A": glyph1, "a": glyph2, ".null": emptyGlyph}
|
||||
fb.setupGlyf(glyphs)
|
||||
metrics = {}
|
||||
glyphTable = fb.font["glyf"]
|
||||
@ -206,6 +213,19 @@ def test_build_var(tmpdir):
|
||||
]
|
||||
fb.setupGvar(variations)
|
||||
|
||||
fb.addFeatureVariations(
|
||||
[
|
||||
(
|
||||
[
|
||||
{"LEFT": (0.8, 1), "DOWN": (0.8, 1)},
|
||||
{"RGHT": (0.8, 1), "UPPP": (0.8, 1)},
|
||||
],
|
||||
{"A": "a"}
|
||||
)
|
||||
],
|
||||
featureTag="rclt",
|
||||
)
|
||||
|
||||
fb.setupOS2()
|
||||
fb.setupPost()
|
||||
fb.setupDummyDSIG()
|
||||
|
Loading…
x
Reference in New Issue
Block a user