[Condition] Implement ConditionValue
Shift other Condition format numbers. Implements https://github.com/adobe-type-tools/opentype-spec-drafts/blob/main/condvalue_spec.md
This commit is contained in:
parent
77add05f7f
commit
973072b259
@ -3238,18 +3238,18 @@ otData = [
|
|||||||
[
|
[
|
||||||
("uint16", "Format", None, None, "Format, = 2"),
|
("uint16", "Format", None, None, "Format, = 2"),
|
||||||
(
|
(
|
||||||
"uint8",
|
"int16",
|
||||||
"ConditionCount",
|
"DefaultValue",
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
"Index for the variation axis within the fvar table, base 0.",
|
"Value at default instance.",
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"Offset24",
|
"uint32",
|
||||||
"ConditionTable",
|
"VarIdx",
|
||||||
"ConditionCount",
|
None,
|
||||||
0,
|
None,
|
||||||
"Array of condition tables for this conjunction (AND) expression.",
|
"Variation index to vary the value based on current designspace location.",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -3269,7 +3269,7 @@ otData = [
|
|||||||
"ConditionTable",
|
"ConditionTable",
|
||||||
"ConditionCount",
|
"ConditionCount",
|
||||||
0,
|
0,
|
||||||
"Array of condition tables for this disjunction (OR) expression.",
|
"Array of condition tables for this conjunction (AND) expression.",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -3277,6 +3277,26 @@ otData = [
|
|||||||
"ConditionTableFormat4",
|
"ConditionTableFormat4",
|
||||||
[
|
[
|
||||||
("uint16", "Format", None, None, "Format, = 4"),
|
("uint16", "Format", None, None, "Format, = 4"),
|
||||||
|
(
|
||||||
|
"uint8",
|
||||||
|
"ConditionCount",
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
"Index for the variation axis within the fvar table, base 0.",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"Offset24",
|
||||||
|
"ConditionTable",
|
||||||
|
"ConditionCount",
|
||||||
|
0,
|
||||||
|
"Array of condition tables for this disjunction (OR) expression.",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"ConditionTableFormat5",
|
||||||
|
[
|
||||||
|
("uint16", "Format", None, None, "Format, = 5"),
|
||||||
(
|
(
|
||||||
"Offset24",
|
"Offset24",
|
||||||
"ConditionTable",
|
"ConditionTable",
|
||||||
|
@ -276,8 +276,9 @@ class _TTGlyphCFF(_TTGlyph):
|
|||||||
self.glyphSet.charStrings[self.name].draw(pen, self.glyphSet.blender)
|
self.glyphSet.charStrings[self.name].draw(pen, self.glyphSet.blender)
|
||||||
|
|
||||||
|
|
||||||
def _evaluateCondition(condition, fvarAxes, location):
|
def _evaluateCondition(condition, fvarAxes, location, instancer):
|
||||||
if condition.Format == 1:
|
if condition.Format == 1:
|
||||||
|
# ConditionAxisRange
|
||||||
axisIndex = condition.AxisIndex
|
axisIndex = condition.AxisIndex
|
||||||
axisTag = fvarAxes[axisIndex].axisTag
|
axisTag = fvarAxes[axisIndex].axisTag
|
||||||
axisValue = location.get(axisTag, 0)
|
axisValue = location.get(axisTag, 0)
|
||||||
@ -285,20 +286,27 @@ def _evaluateCondition(condition, fvarAxes, location):
|
|||||||
maxValue = condition.FilterRangeMaxValue
|
maxValue = condition.FilterRangeMaxValue
|
||||||
return minValue <= axisValue <= maxValue
|
return minValue <= axisValue <= maxValue
|
||||||
elif condition.Format == 2:
|
elif condition.Format == 2:
|
||||||
|
# ConditionValue
|
||||||
|
value = condition.DefaultValue
|
||||||
|
value += instancer[condition.VarIdx]
|
||||||
|
return value > 0
|
||||||
|
elif condition.Format == 3:
|
||||||
# ConditionAnd
|
# ConditionAnd
|
||||||
for subcondition in condition.ConditionTable:
|
for subcondition in condition.ConditionTable:
|
||||||
if not _evaluateCondition(subcondition, fvarAxes, location):
|
if not _evaluateCondition(subcondition, fvarAxes, location, instancer):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
elif condition.Format == 3:
|
elif condition.Format == 4:
|
||||||
# ConditionOr
|
# ConditionOr
|
||||||
for subcondition in condition.ConditionTable:
|
for subcondition in condition.ConditionTable:
|
||||||
if _evaluateCondition(subcondition, fvarAxes, location):
|
if _evaluateCondition(subcondition, fvarAxes, location, instancer):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
elif condition.Format == 4:
|
elif condition.Format == 5:
|
||||||
# ConditionNegate
|
# ConditionNegate
|
||||||
return not _evaluateCondition(condition.conditionTable, fvarAxes, location)
|
return not _evaluateCondition(
|
||||||
|
condition.conditionTable, fvarAxes, location, instancer
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
return False # Unkonwn condition format
|
return False # Unkonwn condition format
|
||||||
|
|
||||||
@ -319,17 +327,26 @@ class _TTGlyphVARC(_TTGlyph):
|
|||||||
glyph = varc.VarCompositeGlyphs.VarCompositeGlyph[idx]
|
glyph = varc.VarCompositeGlyphs.VarCompositeGlyph[idx]
|
||||||
|
|
||||||
from fontTools.varLib.multiVarStore import MultiVarStoreInstancer
|
from fontTools.varLib.multiVarStore import MultiVarStoreInstancer
|
||||||
|
from fontTools.varLib.varStore import VarStoreInstancer
|
||||||
|
|
||||||
fvarAxes = glyphSet.font["fvar"].axes
|
fvarAxes = glyphSet.font["fvar"].axes
|
||||||
instancer = MultiVarStoreInstancer(
|
instancer = MultiVarStoreInstancer(
|
||||||
varc.MultiVarStore, fvarAxes, self.glyphSet.location
|
varc.MultiVarStore, fvarAxes, self.glyphSet.location
|
||||||
)
|
)
|
||||||
|
gdef = glyphSet.font.get("GDEF") if "GDEF" in glyphSet.font else None
|
||||||
|
gdefInstancer = VarStoreInstancer(
|
||||||
|
getattr(gdef.table, "VarStore") if gdef is not None else None,
|
||||||
|
fvarAxes,
|
||||||
|
self.glyphSet.location,
|
||||||
|
)
|
||||||
|
|
||||||
for comp in glyph.components:
|
for comp in glyph.components:
|
||||||
|
|
||||||
if comp.flags & VarComponentFlags.HAVE_CONDITION:
|
if comp.flags & VarComponentFlags.HAVE_CONDITION:
|
||||||
condition = varc.ConditionList.ConditionTable[comp.conditionIndex]
|
condition = varc.ConditionList.ConditionTable[comp.conditionIndex]
|
||||||
if not _evaluateCondition(condition, fvarAxes, self.glyphSet.location):
|
if not _evaluateCondition(
|
||||||
|
condition, fvarAxes, self.glyphSet.location, gdefInstancer
|
||||||
|
):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
location = {}
|
location = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user