models

Variation fonts interpolation models.

class fontTools.varLib.models.VariationModel(locations, axisOrder=None, extrapolate=False)[source]

Locations must have the base master at the origin (ie. 0).

If the extrapolate argument is set to True, then location values are interpretted in the normalized space, ie. in the [-1,+1] range, and values are extrapolated outside this range.

>>> from pprint import pprint
>>> locations = [       {'wght':100},       {'wght':-100},       {'wght':-180},       {'wdth':+.3},       {'wght':+120,'wdth':.3},       {'wght':+120,'wdth':.2},       {},       {'wght':+180,'wdth':.3},       {'wght':+180},       ]
>>> model = VariationModel(locations, axisOrder=['wght'])
>>> pprint(model.locations)
[{},
 {'wght': -100},
 {'wght': -180},
 {'wght': 100},
 {'wght': 180},
 {'wdth': 0.3},
 {'wdth': 0.3, 'wght': 180},
 {'wdth': 0.3, 'wght': 120},
 {'wdth': 0.2, 'wght': 120}]
>>> pprint(model.deltaWeights)
[{},
 {0: 1.0},
 {0: 1.0},
 {0: 1.0},
 {0: 1.0},
 {0: 1.0},
 {0: 1.0, 4: 1.0, 5: 1.0},
 {0: 1.0, 3: 0.75, 4: 0.25, 5: 1.0, 6: 0.6666666666666666},
 {0: 1.0,
  3: 0.75,
  4: 0.25,
  5: 0.6666666666666667,
  6: 0.4444444444444445,
  7: 0.6666666666666667}]
getDeltas(masterValues, *, round=<function noRound>)[source]
getDeltasAndSupports(items, *, round=<function noRound>)[source]
static getMasterLocationsSortKeyFunc(locations, axisOrder=[])[source]
getScalars(loc)[source]
getSubModel(items)[source]
interpolateFromDeltas(loc, deltas)[source]
static interpolateFromDeltasAndScalars(deltas, scalars)[source]
interpolateFromMasters(loc, masterValues, *, round=<function noRound>)[source]
interpolateFromMastersAndScalars(masterValues, scalars, *, round=<function noRound>)[source]
reorderMasters(master_list, mapping)[source]
fontTools.varLib.models.normalizeLocation(location, axes)[source]

Normalizes location based on axis min/default/max values from axes.

>>> axes = {"wght": (100, 400, 900)}
>>> normalizeLocation({"wght": 400}, axes)
{'wght': 0.0}
>>> normalizeLocation({"wght": 100}, axes)
{'wght': -1.0}
>>> normalizeLocation({"wght": 900}, axes)
{'wght': 1.0}
>>> normalizeLocation({"wght": 650}, axes)
{'wght': 0.5}
>>> normalizeLocation({"wght": 1000}, axes)
{'wght': 1.0}
>>> normalizeLocation({"wght": 0}, axes)
{'wght': -1.0}
>>> axes = {"wght": (0, 0, 1000)}
>>> normalizeLocation({"wght": 0}, axes)
{'wght': 0.0}
>>> normalizeLocation({"wght": -1}, axes)
{'wght': 0.0}
>>> normalizeLocation({"wght": 1000}, axes)
{'wght': 1.0}
>>> normalizeLocation({"wght": 500}, axes)
{'wght': 0.5}
>>> normalizeLocation({"wght": 1001}, axes)
{'wght': 1.0}
>>> axes = {"wght": (0, 1000, 1000)}
>>> normalizeLocation({"wght": 0}, axes)
{'wght': -1.0}
>>> normalizeLocation({"wght": -1}, axes)
{'wght': -1.0}
>>> normalizeLocation({"wght": 500}, axes)
{'wght': -0.5}
>>> normalizeLocation({"wght": 1000}, axes)
{'wght': 0.0}
>>> normalizeLocation({"wght": 1001}, axes)
{'wght': 0.0}
fontTools.varLib.models.normalizeValue(v, triple)[source]

Normalizes value based on a min/default/max triple.

>>> normalizeValue(400, (100, 400, 900))
0.0
>>> normalizeValue(100, (100, 400, 900))
-1.0
>>> normalizeValue(650, (100, 400, 900))
0.5
fontTools.varLib.models.supportScalar(location, support, ot=True, extrapolate=False)[source]

Returns the scalar multiplier at location, for a master with support. If ot is True, then a peak value of zero for support of an axis means “axis does not participate”. That is how OpenType Variation Font technology works.

>>> supportScalar({}, {})
1.0
>>> supportScalar({'wght':.2}, {})
1.0
>>> supportScalar({'wght':.2}, {'wght':(0,2,3)})
0.1
>>> supportScalar({'wght':2.5}, {'wght':(0,2,4)})
0.75
>>> supportScalar({'wght':2.5, 'wdth':0}, {'wght':(0,2,4), 'wdth':(-1,0,+1)})
0.75
>>> supportScalar({'wght':2.5, 'wdth':.5}, {'wght':(0,2,4), 'wdth':(-1,0,+1)}, ot=False)
0.375
>>> supportScalar({'wght':2.5, 'wdth':0}, {'wght':(0,2,4), 'wdth':(-1,0,+1)})
0.75
>>> supportScalar({'wght':2.5, 'wdth':.5}, {'wght':(0,2,4), 'wdth':(-1,0,+1)})
0.75
>>> supportScalar({'wght':4}, {'wght':(0,2,3)}, extrapolate=True)
2.0
>>> supportScalar({'wght':4}, {'wght':(0,2,2)}, extrapolate=True)
2.0