From bd76b4a24bbd8c06f1b96d9303c5a89bf966390e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 2 Aug 2024 18:16:11 -0600 Subject: [PATCH] [varLib.avar] Handle default location mapping somewhere else --- Lib/fontTools/varLib/avar.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Lib/fontTools/varLib/avar.py b/Lib/fontTools/varLib/avar.py index ccb9b8cbe..eccfb8cba 100644 --- a/Lib/fontTools/varLib/avar.py +++ b/Lib/fontTools/varLib/avar.py @@ -30,7 +30,7 @@ def mappings_from_avar(font, denormalize=True): if seg and seg != {-1: -1, 0: 0, 1: 1} } mappings = [] - poles = dict() # Just using it as an ordered set + poles = {(): None} # Just using it as an ordered set if getattr(avar, "majorVersion", 1) == 2: varStore = avar.table.VarStore @@ -72,7 +72,7 @@ def mappings_from_avar(font, denormalize=True): model = VariationModel(inputLocations, axisTags) modelMapping = model.mapping modelSupports = model.supports - pins = set(poles.keys()) + pins = poles.copy() for pole in poles.keys(): location = dict(pole) i = inputLocations.index(location) @@ -81,7 +81,7 @@ def mappings_from_avar(font, denormalize=True): supportAxes = set(support.keys()) for supportIndex, (axisTag, (minV, _, maxV)) in enumerate(support.items()): for v in (minV, maxV): - for pin in pins: + for pin in pins.keys(): pinLocation = dict(pin) pinAxes = set(pinLocation.keys()) if pinAxes != supportAxes: @@ -101,8 +101,8 @@ def mappings_from_avar(font, denormalize=True): if axisTag not in candidateAxes: continue if candidateLocation[axisTag] == v: - pins.add(tuple(candidateLocation.items())) - inputLocations = [dict(t) for t in pins] + pins[tuple(candidateLocation.items())] = None + inputLocations = [dict(t) for t in pins.keys()] # Find the output locations varIdxMap = avar.table.VarIdxMap @@ -123,6 +123,11 @@ def mappings_from_avar(font, denormalize=True): outputLocation[axisTag] = v mappings.append((location, outputLocation)) + # Remove base master we added, if it mapped to the default location + assert mappings[0][0] == {} + if mappings[0][1] == {}: + mappings.pop(0) + if denormalize: for tag, seg in axisMaps.items(): if tag not in axisMap: