Open anthrotype opened 2 years ago
A variable COLR table contains a VarStore and an optional (but present more often than not) VarIndexMap (also known as DeltaSetIndexMap). We already have a method to instantiateItemVariationStore, which takes a VarStore, a list of fvar axes, and the desired axis limits; updates the VarStore in-place (removing regions for which all axes are pinned, or which fall outside the limits, or scaling the deltas of remaining regions), and returns a Dict[int, float] of deltas keyed by VarIndex that the caller must add to the default instance. The method keeps unchanged the number of VarData and items within each (to not invalidate the existing VarIndexes).
So what we need to implement partial instancing of variable COLR is the following:
1) a way to traverse the COLR table to add these default deltas to all the variable fields, and if needed (ie. varstore has no more regions left) downgrade variable tables to their static counterpart. A similar thing is done in the varLib.instancer.instantiateOTL for the GDEF and GPOS tables, via the MutatorMerger class. We may use Behdad's new "visitor" API for this.
2) if COLR has a VarIndexMap (99% of the time), then need to run VarStore.optimize() method to compact the VarStore and use the returned mapping from old to new VarIndices to remap the VarIndexMap. If COLR has no VarIndexMap we keep VarStore unoptimized. Instancer does something like that for HVAR/VVAR.
since there's already an large outstanding PR for L4 instancing that touches the same codebase, it makes sense that I review/merge that first before embarking on this one here. I'll do that now
L4 instancing is merged now.
yes, I'd like to get back to this at some point. Ginger already implemented full instancing of COLRv1 in hb-subset so fonttools is now lagging behind.
in varLib.instancer, we already have facilities to partially instantiate ItemVariationStore, like the one found in a variable COLRv1 table, we just need to hook this up for COLR, and also do something with DeltaSetIndexMap, plus remapping the remaining VarIndexBases. still need to figure out the details, filing this issue to track this lest I forget.