From 902b2a194e76b5c681a046f5f5766d37015c757e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 20 Dec 2023 12:35:31 -0700 Subject: [PATCH] [VARC] Fix scaleUpem Instancing left. --- Lib/fontTools/ttLib/scaleUpem.py | 12 +- Lib/fontTools/varLib/instancer/__init__.py | 30 ++++- Tests/ttLib/data/varc-ac00-ac01-500upem.ttx | 124 +++++++------------- 3 files changed, 72 insertions(+), 94 deletions(-) diff --git a/Lib/fontTools/ttLib/scaleUpem.py b/Lib/fontTools/ttLib/scaleUpem.py index a3754d8e8..68709825b 100644 --- a/Lib/fontTools/ttLib/scaleUpem.py +++ b/Lib/fontTools/ttLib/scaleUpem.py @@ -155,7 +155,7 @@ def visit(visitor, obj, attr, varc): store = varc.MultiVarStore storeBuilder = OnlineMultiVarStoreBuilder(fvarAxes) - for g in varc.VarCompositeGlyphs.glyphs: + for g in varc.VarCompositeGlyphs.VarCompositeGlyph: for component in g.components: t = component.transform t.translateX = visitor.scale(t.translateX) @@ -163,8 +163,8 @@ def visit(visitor, obj, attr, varc): t.tCenterX = visitor.scale(t.tCenterX) t.tCenterY = visitor.scale(t.tCenterY) - if component.flags & otTables.VarComponentFlags.AXIS_VALUES_HAVE_VARIATION: - varIdx = component.locationVarIndex + if component.axisValuesVarIndex != otTables.NO_VARIATION_INDEX: + varIdx = component.axisValuesVarIndex # TODO Move this code duplicated below to MultiVarStore.__getitem__, # or a getDeltasAndSupports(). if varIdx != otTables.NO_VARIATION_INDEX: @@ -177,11 +177,11 @@ def visit(visitor, obj, attr, varc): m = len(vec) // varData.VarRegionCount vec = list(batched(vec, m)) vec = [Vector(v) for v in vec] - component.locationVarIndex = storeBuilder.storeDeltas(vec) + component.axisValuesVarIndex = storeBuilder.storeDeltas(vec) else: - component.transformVarIndex = otTables.NO_VARIATION_INDEX + component.axisValuesVarIndex = otTables.NO_VARIATION_INDEX - if component.flags & otTables.VarComponentFlags.TRANSFORM_HAS_VARIATION: + if component.transformVarIndex != otTables.NO_VARIATION_INDEX: varIdx = component.transformVarIndex if varIdx != otTables.NO_VARIATION_INDEX: major = varIdx >> 16 diff --git a/Lib/fontTools/varLib/instancer/__init__.py b/Lib/fontTools/varLib/instancer/__init__.py index b3e27bd2c..c692433ed 100644 --- a/Lib/fontTools/varLib/instancer/__init__.py +++ b/Lib/fontTools/varLib/instancer/__init__.py @@ -474,15 +474,32 @@ def instantiateVARC(varfont, axisLimits): # I don't think it currently works. varc = varfont["VARC"].table - if varc.VarCompositeGlyphs: - for glyph in varc.VarCompositeGlyphs.glyphs: - for component in glyph.components: + fvarAxes = varfont["fvar"].axes if "fvar" in varfont else [] + if varc.VarCompositeGlyphs is not None: + for glyph in varc.VarCompositeGlyphs.VarCompositeGlyph: + for comp in glyph.components: + if comp.axisIndicesIndex is None: + continue + + axisIndices = varc.AxisIndicesList.Item[comp.axisIndicesIndex] + axisValues = comp.axisValues + + comp.axisValues = [] + for axisIndex, axisValue in zip(axisIndices, axisValues): + tag = fvarAxes[axisIndex].axisTag + if tag in axisLimits: + axisValue = axisLimits[tag].renormalizeValue( + axisValue, extrapolate=False + ) + comp.axisValues.append(axisValue) + + """ newLocation = {} for tag, loc in component.location.items(): if tag not in axisLimits: newLocation[tag] = loc continue - if component.flags & VarComponentFlags.AXIS_VALUES_HAVE_VARIATION: + if comp.flags & VarComponentFlags.AXIS_VALUES_HAVE_VARIATION: raise NotImplementedError( "Instancing accross VarComponent axes with variation is not supported." ) @@ -490,9 +507,10 @@ def instantiateVARC(varfont, axisLimits): loc = limits.renormalizeValue(loc, extrapolate=False) newLocation[tag] = loc component.location = newLocation + """ - if varc.MultiVarStore: - store = varc.MultiVarStore + store = varc.MultiVarStore + if store: store.prune_regions() # Needed? fvar = varfont["fvar"] diff --git a/Tests/ttLib/data/varc-ac00-ac01-500upem.ttx b/Tests/ttLib/data/varc-ac00-ac01-500upem.ttx index da7980037..a4931bcdf 100644 --- a/Tests/ttLib/data/varc-ac00-ac01-500upem.ttx +++ b/Tests/ttLib/data/varc-ac00-ac01-500upem.ttx @@ -288,84 +288,44 @@ - - + + - + + + + + + - - - - - - - - + + - - - - - - - - - - - - + + + - - - - - + - - - - - - - + - - - - - - - - - + - - - - - - - + - - - - - - - + @@ -563,7 +523,7 @@ - + @@ -593,7 +553,7 @@ - + @@ -608,7 +568,7 @@ - + @@ -640,7 +600,7 @@ - + @@ -680,7 +640,7 @@ - + @@ -703,7 +663,7 @@ - + @@ -749,7 +709,7 @@ - + @@ -795,7 +755,7 @@ - + @@ -819,7 +779,7 @@ - + @@ -843,7 +803,7 @@ - + @@ -890,8 +850,8 @@ - - + + @@ -915,7 +875,7 @@ - + @@ -939,7 +899,7 @@ - + @@ -963,8 +923,8 @@ - - + + @@ -989,7 +949,7 @@ - + @@ -1014,7 +974,7 @@ - + @@ -1038,8 +998,8 @@ - - + + @@ -1064,8 +1024,8 @@ - - + + @@ -1135,7 +1095,7 @@ - + @@ -1150,7 +1110,7 @@ - +