Skip to content

Commit

Permalink
[instancer/avar2] Try adding identity value to main axis
Browse files Browse the repository at this point in the history
  • Loading branch information
behdad committed Apr 19, 2024
1 parent 9a0a19f commit c1a7f99
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions Lib/fontTools/varLib/instancer/avar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
from fontTools.varLib import instancer


def VarStore_getExtremes(self, varIdx, nullAxes=set(), cache=None):
def VarStore_getExtremes(self, varIdx, identityAxisIndex=None, nullAxes=set(), cache=None):

if varIdx == NO_VARIATION_INDEX:
return 0, 0
if identityAxisIndex is None:
return 0, 0

Check warning on line 11 in Lib/fontTools/varLib/instancer/avar.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/instancer/avar.py#L11

Added line #L11 was not covered by tests
else:
return -16384, 16384

Check warning on line 13 in Lib/fontTools/varLib/instancer/avar.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/instancer/avar.py#L13

Added line #L13 was not covered by tests

if cache is None:
cache = {}

Check warning on line 16 in Lib/fontTools/varLib/instancer/avar.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/instancer/avar.py#L16

Added line #L16 was not covered by tests
Expand Down Expand Up @@ -51,14 +54,28 @@ def VarStore_getExtremes(self, varIdx, nullAxes=set(), cache=None):
location[str(i)] = peak

Check warning on line 54 in Lib/fontTools/varLib/instancer/avar.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/instancer/avar.py#L51-L54

Added lines #L51 - L54 were not covered by tests
if skip:
continue

Check warning on line 56 in Lib/fontTools/varLib/instancer/avar.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/instancer/avar.py#L56

Added line #L56 was not covered by tests
varStoreInstancer = VarStoreInstancer(varStore, self._fvar_axes, location)
v = varStoreInstancer[varIdx]

assert thisAxes, "Empty region in VarStore!"
minOther, maxOther = self.getExtremes(varIdx, nullAxes | thisAxes, cache)
locs = [None]

Check warning on line 58 in Lib/fontTools/varLib/instancer/avar.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/instancer/avar.py#L58

Added line #L58 was not covered by tests
if identityAxisIndex in thisAxes:
locs = []
locs.append(-1)
locs.append(region.VarRegionAxis[identityAxisIndex].StartCoord)
locs.append(region.VarRegionAxis[identityAxisIndex].PeakCoord)
locs.append(region.VarRegionAxis[identityAxisIndex].EndCoord)
locs.append(+1)

Check warning on line 65 in Lib/fontTools/varLib/instancer/avar.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/instancer/avar.py#L60-L65

Added lines #L60 - L65 were not covered by tests

minV = min(minV, v + minOther)
maxV = max(maxV, v + maxOther)
for loc in locs:
if loc is not None:
location[str(identityAxisIndex)] = loc

Check warning on line 69 in Lib/fontTools/varLib/instancer/avar.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/instancer/avar.py#L69

Added line #L69 was not covered by tests

varStoreInstancer = VarStoreInstancer(varStore, self._fvar_axes, location)
v = varStoreInstancer[varIdx] + (0 if loc is None else round(loc * 16384))

Check warning on line 72 in Lib/fontTools/varLib/instancer/avar.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/instancer/avar.py#L71-L72

Added lines #L71 - L72 were not covered by tests

assert thisAxes, "Empty region in VarStore!"
minOther, maxOther = self.getExtremes(varIdx, identityAxisIndex, nullAxes | thisAxes, cache)

Check warning on line 75 in Lib/fontTools/varLib/instancer/avar.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/instancer/avar.py#L74-L75

Added lines #L74 - L75 were not covered by tests

minV = min(minV, v + minOther)
maxV = max(maxV, v + maxOther)

Check warning on line 78 in Lib/fontTools/varLib/instancer/avar.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/instancer/avar.py#L77-L78

Added lines #L77 - L78 were not covered by tests

cache[key] = (minV, maxV)

Check warning on line 80 in Lib/fontTools/varLib/instancer/avar.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/instancer/avar.py#L80

Added line #L80 was not covered by tests

Expand Down Expand Up @@ -92,5 +109,6 @@ def VarStore_getExtremes(self, varIdx, nullAxes=set(), cache=None):
varIdx = axisIdx
if varIdxMap is not None:
varIdx = varIdxMap[varIdx]
minV, maxV = varStore.getExtremes(varIdx)
identityAxisIndex = None if axis.flags & 0x1 else axisIdx
minV, maxV = varStore.getExtremes(varIdx, identityAxisIndex)
print(axis.axisTag, defaultDeltas[varIdx] / 16384, (minV / 16384, maxV / 16384))

0 comments on commit c1a7f99

Please sign in to comment.