diff options
Diffstat (limited to 'Lib/fontTools/varLib/models.py')
-rw-r--r-- | Lib/fontTools/varLib/models.py | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/Lib/fontTools/varLib/models.py b/Lib/fontTools/varLib/models.py index 207e30f3..9a990b7b 100644 --- a/Lib/fontTools/varLib/models.py +++ b/Lib/fontTools/varLib/models.py @@ -189,19 +189,22 @@ class VariationModel(object): 7: 0.6666666666666667}] """ - def __init__(self, locations, axisOrder=[]): + def __init__(self, locations, axisOrder=None): + if len(set(tuple(sorted(l.items())) for l in locations)) != len(locations): + raise ValueError("locations must be unique") + self.origLocations = locations - self.axisOrder = axisOrder + self.axisOrder = axisOrder if axisOrder is not None else [] locations = [{k:v for k,v in loc.items() if v != 0.} for loc in locations] - keyFunc = self.getMasterLocationsSortKeyFunc(locations, axisOrder=axisOrder) - axisPoints = keyFunc.axisPoints + keyFunc = self.getMasterLocationsSortKeyFunc(locations, axisOrder=self.axisOrder) self.locations = sorted(locations, key=keyFunc) - # TODO Assert that locations are unique. - self.mapping = [self.locations.index(l) for l in locations] # Mapping from user's master order to our master order - self.reverseMapping = [locations.index(l) for l in self.locations] # Reverse of above - self._computeMasterSupports(axisPoints, axisOrder) + # Mapping from user's master order to our master order + self.mapping = [self.locations.index(l) for l in locations] + self.reverseMapping = [locations.index(l) for l in self.locations] + + self._computeMasterSupports(keyFunc.axisPoints) self._subModels = {} def getSubModel(self, items): @@ -252,18 +255,6 @@ class VariationModel(object): ret.axisPoints = axisPoints return ret - @staticmethod - def lowerBound(value, lst): - if any(v < value for v in lst): - return max(v for v in lst if v < value) - else: - return value - @staticmethod - def upperBound(value, lst): - if any(v > value for v in lst): - return min(v for v in lst if v > value) - else: - return value def reorderMasters(self, master_list, mapping): # For changing the master data order without # recomputing supports and deltaWeights. @@ -276,7 +267,7 @@ class VariationModel(object): self._subModels = {} return new_list - def _computeMasterSupports(self, axisPoints, axisOrder): + def _computeMasterSupports(self, axisPoints): supports = [] deltaWeights = [] locations = self.locations @@ -444,6 +435,7 @@ def main(args): pprint(locs) doc.normalize() print("Normalized locations:") + locs = [s.location for s in doc.sources] pprint(locs) else: axes = [chr(c) for c in range(ord('A'), ord('Z')+1)] |