[VARC] Take a stab at instancing
This commit is contained in:
parent
902b2a194e
commit
e88e47f8ff
@ -475,70 +475,31 @@ def instantiateVARC(varfont, axisLimits):
|
|||||||
|
|
||||||
varc = varfont["VARC"].table
|
varc = varfont["VARC"].table
|
||||||
fvarAxes = varfont["fvar"].axes if "fvar" in varfont else []
|
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]
|
location = axisLimits.pinnedLocation()
|
||||||
axisValues = comp.axisValues
|
axisMap = [i for i, axis in enumerate(fvarAxes) if axis.axisTag not in location]
|
||||||
|
reverseAxisMap = {i: j for j, i in enumerate(axisMap)}
|
||||||
|
|
||||||
comp.axisValues = []
|
if varc.AxisIndicesList:
|
||||||
for axisIndex, axisValue in zip(axisIndices, axisValues):
|
axisIndicesList = varc.AxisIndicesList.Item
|
||||||
tag = fvarAxes[axisIndex].axisTag
|
for i, axisIndices in enumerate(axisIndicesList):
|
||||||
if tag in axisLimits:
|
if any(fvarAxes[j].axisTag in axisLimits for j in axisIndices):
|
||||||
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 comp.flags & VarComponentFlags.AXIS_VALUES_HAVE_VARIATION:
|
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"Instancing accross VarComponent axes with variation is not supported."
|
"Instancing across VarComponent axes is not supported."
|
||||||
)
|
)
|
||||||
limits = axisLimits[tag]
|
axisIndicesList[i] = [reverseAxisMap[j] for j in axisIndices]
|
||||||
loc = limits.renormalizeValue(loc, extrapolate=False)
|
|
||||||
newLocation[tag] = loc
|
|
||||||
component.location = newLocation
|
|
||||||
"""
|
|
||||||
|
|
||||||
store = varc.MultiVarStore
|
store = varc.MultiVarStore
|
||||||
if store:
|
if store:
|
||||||
store.prune_regions() # Needed?
|
|
||||||
|
|
||||||
fvar = varfont["fvar"]
|
|
||||||
location = axisLimits.pinnedLocation()
|
|
||||||
for region in store.SparseVarRegionList.Region:
|
for region in store.SparseVarRegionList.Region:
|
||||||
newRegionAxis = []
|
newRegionAxis = []
|
||||||
for regionRecord in region.SparseVarRegionAxis:
|
for regionRecord in region.SparseVarRegionAxis:
|
||||||
tag = fvar.axes[regionRecord.AxisIndex].axisTag
|
tag = fvarAxes[regionRecord.AxisIndex].axisTag
|
||||||
if tag in location:
|
|
||||||
continue
|
|
||||||
if tag in axisLimits:
|
if tag in axisLimits:
|
||||||
limits = axisLimits[tag]
|
raise NotImplementedError(
|
||||||
triple = (
|
"Instancing across VarComponent axes is not supported."
|
||||||
regionRecord.StartCoord,
|
|
||||||
regionRecord.PeakCoord,
|
|
||||||
regionRecord.EndCoord,
|
|
||||||
)
|
)
|
||||||
triple = tuple(
|
regionRecord.AxisIndex = reverseAxisMap[regionRecord.AxisIndex]
|
||||||
limits.renormalizeValue(v, extrapolate=False) for v in triple
|
|
||||||
)
|
|
||||||
(
|
|
||||||
regionRecord.StartCoord,
|
|
||||||
regionRecord.PeakCoord,
|
|
||||||
regionRecord.EndCoord,
|
|
||||||
) = triple
|
|
||||||
newRegionAxis.append(regionRecord)
|
|
||||||
region.VarRegionAxis = newRegionAxis
|
|
||||||
region.VarRegionAxisCount = len(newRegionAxis)
|
|
||||||
|
|
||||||
|
|
||||||
def instantiateTupleVariationStore(
|
def instantiateTupleVariationStore(
|
||||||
|
@ -1699,12 +1699,18 @@ class InstantiateVariableFontTest(object):
|
|||||||
|
|
||||||
def test_varComposite(self):
|
def test_varComposite(self):
|
||||||
input_path = os.path.join(
|
input_path = os.path.join(
|
||||||
TESTDATA, "..", "..", "..", "ttLib", "data", "varc-ac00-ac01.ttf"
|
TESTDATA, "..", "..", "..", "ttLib", "data", "varc-6868.ttf"
|
||||||
)
|
)
|
||||||
varfont = ttLib.TTFont(input_path)
|
varfont = ttLib.TTFont(input_path)
|
||||||
|
|
||||||
location = {"wght": 600}
|
location = {"wght": 600}
|
||||||
|
|
||||||
|
# We currently do not allow this either; although in theory
|
||||||
|
# it should be possible.
|
||||||
|
with pytest.raises(
|
||||||
|
NotImplementedError,
|
||||||
|
match="is not supported.",
|
||||||
|
):
|
||||||
instance = instancer.instantiateVariableFont(
|
instance = instancer.instantiateVariableFont(
|
||||||
varfont,
|
varfont,
|
||||||
location,
|
location,
|
||||||
@ -1714,7 +1720,7 @@ class InstantiateVariableFontTest(object):
|
|||||||
|
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
NotImplementedError,
|
NotImplementedError,
|
||||||
match="Instancing accross VarComponent axes with variation is not supported.",
|
match="is not supported.",
|
||||||
):
|
):
|
||||||
instance = instancer.instantiateVariableFont(
|
instance = instancer.instantiateVariableFont(
|
||||||
varfont,
|
varfont,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user