[VARC] Finish drawing!

This commit is contained in:
Behdad Esfahbod 2023-12-16 01:45:34 -07:00
parent bbad70ef8a
commit 950d39b9d3
2 changed files with 31 additions and 4 deletions

View File

@ -328,10 +328,7 @@ class VarComponent:
def getComponentValues(self):
flags = self.flags
if flags & VarComponentFlags.AXIS_VALUES_HAVE_VARIATION:
locationValues = [fl2fi(v, 14) for v in self.location.values()]
else:
locationValues = []
locationValues = [fl2fi(v, 14) for v in self.location.values()]
transformValues = []
@ -349,6 +346,34 @@ class VarComponent:
return Vector(locationValues), Vector(transformValues)
def setComponentValues(self, locationValues, transformValues):
flags = self.flags
assert len(locationValues) == len(self.location), (
len(locationValues),
len(self.location),
)
self.location = {
tag: fi2fl(v, 14) for tag, v in zip(self.location.keys(), locationValues)
}
self.transform = DecomposedTransform(self.transform)
i = 0
def read_transform_component(values):
nonlocal transformValues, i
if flags & values.flag:
v = fi2fl(transformValues[i], values.fractionalBits) * values.scale
i += 1
return v
else:
return values.defaultValue
for attr_name, mapping_values in VAR_COMPONENT_TRANSFORM_MAPPING.items():
value = read_transform_component(mapping_values)
setattr(self.transform, attr_name, value)
assert i == len(transformValues), (i, len(transformValues))
class VarCompositeGlyph(BaseTable):
def populateDefaults(self, propagator=None):

View File

@ -310,6 +310,8 @@ class _TTGlyphVARC(_TTGlyph):
transformDeltas = instancer[comp.transformVarIndex]
transformValues = list(transformValues + transformDeltas)
comp.setComponentValues(locationValues, transformValues)
with self.glyphSet.glyphSet.pushLocation(
comp.location, comp.flags & VarComponentFlags.RESET_UNSPECIFIED_AXES
):