[varLib.avar] Do less work
No need to compute outputLocation for unneeded inputLocations.
This commit is contained in:
parent
9f19a19c4e
commit
34e38c3d03
@ -67,26 +67,8 @@ def mappings_from_avar(font, denormalize=True):
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
varIdxMap = avar.table.VarIdxMap
|
# Now we have all the input locations, find which ones are
|
||||||
instancer = VarStoreInstancer(varStore, fvarAxes)
|
# not needed and remove them.
|
||||||
for location in inputLocations:
|
|
||||||
instancer.setLocation(location)
|
|
||||||
outputLocation = {}
|
|
||||||
for axisIndex, axisTag in enumerate(axisTags):
|
|
||||||
varIdx = axisIndex
|
|
||||||
if varIdxMap is not None:
|
|
||||||
varIdx = varIdxMap[varIdx]
|
|
||||||
delta = instancer[varIdx]
|
|
||||||
if delta != 0:
|
|
||||||
v = location.get(axisTag, 0)
|
|
||||||
v = v + fi2fl(delta, 14)
|
|
||||||
# See https://github.com/fonttools/fonttools/pull/3598#issuecomment-2266082009
|
|
||||||
# v = max(-1, min(1, v))
|
|
||||||
outputLocation[axisTag] = v
|
|
||||||
mappings.append((location, outputLocation))
|
|
||||||
|
|
||||||
# Now we have all the mappings, find which ones are redundant
|
|
||||||
# and remove them.
|
|
||||||
model = VariationModel(inputLocations, axisTags)
|
model = VariationModel(inputLocations, axisTags)
|
||||||
modelMapping = model.mapping
|
modelMapping = model.mapping
|
||||||
modelSupports = model.supports
|
modelSupports = model.supports
|
||||||
@ -120,11 +102,26 @@ def mappings_from_avar(font, denormalize=True):
|
|||||||
continue
|
continue
|
||||||
if candidateLocation[axisTag] == v:
|
if candidateLocation[axisTag] == v:
|
||||||
pins.add(tuple(candidateLocation.items()))
|
pins.add(tuple(candidateLocation.items()))
|
||||||
mappings = [
|
inputLocations = [dict(t) for t in pins]
|
||||||
(inputLoc, outputLoc)
|
|
||||||
for inputLoc, outputLoc in mappings
|
# Find the output locations
|
||||||
if tuple(inputLoc.items()) in pins
|
varIdxMap = avar.table.VarIdxMap
|
||||||
]
|
instancer = VarStoreInstancer(varStore, fvarAxes)
|
||||||
|
for location in inputLocations:
|
||||||
|
instancer.setLocation(location)
|
||||||
|
outputLocation = {}
|
||||||
|
for axisIndex, axisTag in enumerate(axisTags):
|
||||||
|
varIdx = axisIndex
|
||||||
|
if varIdxMap is not None:
|
||||||
|
varIdx = varIdxMap[varIdx]
|
||||||
|
delta = instancer[varIdx]
|
||||||
|
if delta != 0:
|
||||||
|
v = location.get(axisTag, 0)
|
||||||
|
v = v + fi2fl(delta, 14)
|
||||||
|
# See https://github.com/fonttools/fonttools/pull/3598#issuecomment-2266082009
|
||||||
|
# v = max(-1, min(1, v))
|
||||||
|
outputLocation[axisTag] = v
|
||||||
|
mappings.append((location, outputLocation))
|
||||||
|
|
||||||
if denormalize:
|
if denormalize:
|
||||||
for tag, seg in axisMaps.items():
|
for tag, seg in axisMaps.items():
|
||||||
@ -195,7 +192,6 @@ def main(args=None):
|
|||||||
segments, mappings = mappings_from_avar(font)
|
segments, mappings = mappings_from_avar(font)
|
||||||
pprint(segments)
|
pprint(segments)
|
||||||
pprint(mappings)
|
pprint(mappings)
|
||||||
print(len(mappings))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
axisTags = [a.axisTag for a in font["fvar"].axes]
|
axisTags = [a.axisTag for a in font["fvar"].axes]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user