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 30, 2024
1 parent 5b48d95 commit ad1628e
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions Lib/fontTools/varLib/instancer/avar.py
Expand Up @@ -4,10 +4,15 @@
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 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
else:
return -16384, 16384

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L15 was not covered by tests

if cache is None:
cache = {}

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

View check run for this annotation

Codecov / codecov/patch

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

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

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#L53-L56

Added lines #L53 - L56 were not covered by tests
if skip:
continue

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
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 60 in Lib/fontTools/varLib/instancer/avar.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L60 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 67 in Lib/fontTools/varLib/instancer/avar.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/instancer/avar.py#L62-L67

Added lines #L62 - L67 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 71 in Lib/fontTools/varLib/instancer/avar.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L71 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 74 in Lib/fontTools/varLib/instancer/avar.py

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L73 - L74 were not covered by tests

assert thisAxes, "Empty region in VarStore!"
minOther, maxOther = self.getExtremes(

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L76 - L77 were not covered by tests
varIdx, identityAxisIndex, nullAxes | thisAxes, cache
)

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

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

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/instancer/avar.py#L81-L82

Added lines #L81 - L82 were not covered by tests

cache[key] = (minV, maxV)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L84 was not covered by tests

Expand Down Expand Up @@ -92,5 +113,7 @@ def VarStore_getExtremes(self, varIdx, nullAxes=set(), cache=None):
varIdx = axisIdx
if varIdxMap is not None:
varIdx = varIdxMap[varIdx]
minV, maxV = varStore.getExtremes(varIdx)
# Only for public axes
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 ad1628e

Please sign in to comment.