models

Variation fonts interpolation models.

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

Locations must be in normalized space. Ie. base master is at origin (0). >>> 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)[source]
getDeltasAndSupports(items)[source]
static getMasterLocationsSortKeyFunc(locations, axisOrder=[])[source]
getScalars(loc)[source]
getSubModel(items)[source]
interpolateFromDeltas(loc, deltas)[source]
static interpolateFromDeltasAndScalars(deltas, scalars)[source]
interpolateFromMasters(loc, masterValues)[source]
interpolateFromMastersAndScalars(masterValues, scalars)[source]
reorderMasters(master_list, mapping)[source]
fontTools.varLib.models.allEqual(lst, mapper=None)[source]
fontTools.varLib.models.allEqualTo(ref, lst, mapper=None)[source]
fontTools.varLib.models.allNone(lst)[source]
fontTools.varLib.models.nonNone(lst)[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.subList(truth, lst)[source]
fontTools.varLib.models.supportScalar(location, support, ot=True)[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