diff --git a/Lib/fontTools/subset/__init__.py b/Lib/fontTools/subset/__init__.py index ed296ed65..c924d574b 100644 --- a/Lib/fontTools/subset/__init__.py +++ b/Lib/fontTools/subset/__init__.py @@ -2693,6 +2693,22 @@ def prune_post_subset(self, font, options): if comp.axisIndicesIndex is not None: comp.axisIndicesIndex = mapping[comp.axisIndicesIndex] + conditionSetList = table.ConditionSetList + if conditionSetList is not None: + conditionSets = conditionSetList.ConditionSet + usedIndices = set() + for glyph in table.VarCompositeGlyphs.VarCompositeGlyph: + for comp in glyph.components: + if comp.conditionSetIndex is not None: + usedIndices.add(comp.conditionSetIndex) + usedIndices = sorted(usedIndices) + conditionSetList.ConditionSet = _list_subset(conditionSets, usedIndices) + mapping = {old: new for new, old in enumerate(usedIndices)} + for glyph in table.VarCompositeGlyphs.VarCompositeGlyph: + for comp in glyph.components: + if comp.conditionSetIndex is not None: + comp.conditionSetIndex = mapping[comp.conditionSetIndex] + return True diff --git a/Lib/fontTools/ttLib/tables/otData.py b/Lib/fontTools/ttLib/tables/otData.py index cb7ad5de9..a2071b1f5 100644 --- a/Lib/fontTools/ttLib/tables/otData.py +++ b/Lib/fontTools/ttLib/tables/otData.py @@ -3168,6 +3168,25 @@ otData = [ ), ], ), + ( + "ConditionSetList", + [ + ( + "uint32", + "ConditionSetCount", + None, + None, + "Number of condition-set tables in the ConditionSet array", + ), + ( + "LOffset", + "ConditionSet", + "ConditionSetCount", + 0, + "Array of condition-set tables.", + ), + ], + ), ( "ConditionSet", [ @@ -3377,6 +3396,7 @@ otData = [ ), ("LOffset", "Coverage", None, None, ""), ("LOffset", "MultiVarStore", None, None, "(may be NULL)"), + ("LOffset", "ConditionSetList", None, None, "(may be NULL)"), ("LOffset", "AxisIndicesList", None, None, "(may be NULL)"), ("LOffset", "VarCompositeGlyphs", None, None, ""), ], diff --git a/Lib/fontTools/ttLib/tables/otTables.py b/Lib/fontTools/ttLib/tables/otTables.py index 95fa83f8a..15797fbed 100644 --- a/Lib/fontTools/ttLib/tables/otTables.py +++ b/Lib/fontTools/ttLib/tables/otTables.py @@ -60,7 +60,7 @@ class VarComponentFlags(IntFlag): HAVE_TRANSLATE_Y = 1 << 5 HAVE_ROTATION = 1 << 6 - USE_MY_METRICS = 1 << 7 + HAVE_CONDITION = 1 << 7 HAVE_SCALE_X = 1 << 8 HAVE_SCALE_Y = 1 << 9 @@ -158,6 +158,7 @@ class VarComponent: def populateDefaults(self, propagator=None): self.flags = 0 self.glyphName = None + self.conditionSetIndex = None self.axisIndicesIndex = None self.axisValues = () self.axisValuesVarIndex = NO_VARIATION_INDEX @@ -174,6 +175,9 @@ class VarComponent: i += gidSize self.glyphName = font.glyphOrder[glyphID] + if flags & VarComponentFlags.HAVE_CONDITION: + self.conditionSetIndex, i = _read_uint32var(data, i) + if flags & VarComponentFlags.HAVE_AXES: self.axisIndicesIndex, i = _read_uint32var(data, i) else: @@ -244,6 +248,10 @@ class VarComponent: flags &= ~VarComponentFlags.GID_IS_24BIT data.append(_packer[2](glyphID)) + if self.conditionSetIndex is not None: + flags |= VarComponentFlags.HAVE_CONDITION + data.append(_write_uint32var(self.conditionSetIndex)) + numAxes = len(self.axisValues) if numAxes: @@ -293,6 +301,8 @@ class VarComponent: write("glyphName", self.glyphName) + if self.conditionSetIndex is not None: + write("conditionSetIndex", self.conditionSetIndex) if self.axisIndicesIndex is not None: write("axisIndicesIndex", self.axisIndicesIndex) if ( @@ -332,6 +342,8 @@ class VarComponent: if name == "glyphName": self.glyphName = v + elif name == "conditionSetIndex": + self.conditionSetIndex = safeEval(v) elif name == "axisIndicesIndex": self.axisIndicesIndex = safeEval(v) elif name == "axisValues": diff --git a/Lib/fontTools/ttLib/ttGlyphSet.py b/Lib/fontTools/ttLib/ttGlyphSet.py index 0e1bcd6d6..9772ae813 100644 --- a/Lib/fontTools/ttLib/ttGlyphSet.py +++ b/Lib/fontTools/ttLib/ttGlyphSet.py @@ -299,6 +299,28 @@ class _TTGlyphVARC(_TTGlyph): ) for comp in glyph.components: + + if comp.flags & VarComponentFlags.HAVE_CONDITION: + conditionSet = varc.ConditionSetList.ConditionSet[ + comp.conditionSetIndex + ] + # Evaluate condition + show = True + for condition in conditionSet.ConditionTable: + if condition.Format == 1: + axisIndex = condition.AxisIndex + axisTag = fvarAxes[axisIndex].axisTag + axisValue = self.glyphSet.location[axisTag] + minValue = condition.FilterRangeMinValue + maxValue = condition.FilterRangeMaxValue + if not (minValue <= axisValue <= maxValue): + show = False + break + else: + show = False # Unkonwn condition format + if not show: + continue + location = {} if comp.axisIndicesIndex is not None: axisIndices = varc.AxisIndicesList.Item[comp.axisIndicesIndex] diff --git a/Tests/ttLib/data/varc-6868.ttf b/Tests/ttLib/data/varc-6868.ttf index bb2c518b7..6041d6cc1 100644 Binary files a/Tests/ttLib/data/varc-6868.ttf and b/Tests/ttLib/data/varc-6868.ttf differ diff --git a/Tests/ttLib/data/varc-ac00-ac01-500upem.ttx b/Tests/ttLib/data/varc-ac00-ac01-500upem.ttx index 49b1696d6..9976b5bf7 100644 --- a/Tests/ttLib/data/varc-ac00-ac01-500upem.ttx +++ b/Tests/ttLib/data/varc-ac00-ac01-500upem.ttx @@ -58,12 +58,12 @@ - + - + - - + + @@ -94,31 +94,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -140,6 +116,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -161,6 +161,36 @@ + + rcjk + + + varc + + + Weight + + + OpticalSize + + + 0000 + + + 0001 + + + 0002 + + + 0003 + + + 0004 + + + 0005 + rcjk @@ -191,30 +221,6 @@ 0005 - - 0006 - - - 0007 - - - 0008 - - - 0009 - - - 0010 - - - 0011 - - - 0012 - - - 0013 - @@ -235,10 +241,10 @@ - - + + @@ -285,88 +291,88 @@ - - - - - - - + + + + + + + - - + + - + - + - + - + - + - - - - + + + + + + + - - - - - + + + + - - + + - - + + - + - - - - - + + + - + - + - - + + @@ -453,201 +459,12 @@ 1.0 263 - - - - 0006 - 0x0 - -1.0 - 0.0 - 1.0 - 264 - - - - - 0007 - 0x0 - -1.0 - 0.0 - 1.0 - 265 - - - - - 0008 - 0x0 - -1.0 - 0.0 - 1.0 - 266 - - - - - 0009 - 0x0 - -1.0 - 0.0 - 1.0 - 267 - - - - - 0010 - 0x0 - -1.0 - 0.0 - 1.0 - 268 - - - - - 0011 - 0x0 - -1.0 - 0.0 - 1.0 - 269 - - - - - 0012 - 0x0 - -1.0 - 0.0 - 1.0 - 270 - - - - - 0013 - 0x0 - -1.0 - 0.0 - 1.0 - 271 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1080,6 +897,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/ttLib/data/varc-ac00-ac01.ttf b/Tests/ttLib/data/varc-ac00-ac01.ttf index 3134c0ad3..fb3a08780 100644 Binary files a/Tests/ttLib/data/varc-ac00-ac01.ttf and b/Tests/ttLib/data/varc-ac00-ac01.ttf differ diff --git a/Tests/ttLib/tables/V_A_R_C_test.py b/Tests/ttLib/tables/V_A_R_C_test.py index 9ddc107f1..dcd35da8e 100644 --- a/Tests/ttLib/tables/V_A_R_C_test.py +++ b/Tests/ttLib/tables/V_A_R_C_test.py @@ -9,7 +9,7 @@ DATA_DIR = os.path.join(CURR_DIR, "data") class VarCompositeTest(unittest.TestCase): - def test_trim_varComposite_glyph(self): + def test_basic(self): font_path = os.path.join(DATA_DIR, "..", "..", "data", "varc-ac00-ac01.ttf") font = TTFont(font_path) varc = font["VARC"] @@ -18,10 +18,10 @@ class VarCompositeTest(unittest.TestCase): "uniAC00", "uniAC01", "glyph00003", - "glyph00004", "glyph00005", - "glyph00006", "glyph00007", + "glyph00008", + "glyph00009", ] font_path = os.path.join(DATA_DIR, "..", "..", "data", "varc-6868.ttf") @@ -31,11 +31,11 @@ class VarCompositeTest(unittest.TestCase): assert varc.table.Coverage.glyphs == [ "uni6868", "glyph00002", - "glyph00003", - "glyph00004", + "glyph00005", + "glyph00007", ] - def test_varComposite_basic(self): + def test_roundtrip(self): font_path = os.path.join(DATA_DIR, "..", "..", "data", "varc-ac00-ac01.ttf") font = TTFont(font_path) tables = [ diff --git a/Tests/ttLib/ttGlyphSet_test.py b/Tests/ttLib/ttGlyphSet_test.py index c9c5150d2..d4bc5ad85 100644 --- a/Tests/ttLib/ttGlyphSet_test.py +++ b/Tests/ttLib/ttGlyphSet_test.py @@ -226,7 +226,7 @@ class TTGlyphSetTest(object): ( "addVarComponent", ( - "glyph00007", + "glyph00003", DecomposedTransform( translateX=0, translateY=0, @@ -244,7 +244,7 @@ class TTGlyphSetTest(object): ( "addVarComponent", ( - "glyph00003", + "glyph00005", DecomposedTransform( translateX=0, translateY=0,