@simoncozens/fonttypes
    Preparing search index...

    Class VariationModel

    A VariationModel represents an OpenType variation model for a set of masters at specific locations. It is used to compute deltas, scalars, and interpolated values for arbitrary locations.

    import { VariationModel } from "./variationmodel";

    // Define master locations
    const locations = [
    { wght: 0.0 },
    { wght: -1.0 },
    { wght: 1.0 },
    ];

    // Create a variation model
    const model = new VariationModel(locations, ["wght"]);
    // Interpolate!
    const loc: NormalizedLocation = { wght: 0.5 };
    const masterValues = [ 0, -20, 20 ]; // Values at each master
    const value = model.interpolateFromMasters(loc, masterValues);
    console.log(value); // Should print 10
    Index

    Constructors

    Properties

    axisOrder: string[]
    deltaWeights: Record<number, number>[]
    locations: NormalizedLocation[]
    mapping: number[]
    origLocations: NormalizedLocation[]
    reverseMapping: number[]
    supports: Support[]

    Interpolation and Variation Models - Interpolation

    • Interpolate a value at a given location from pre-fetched deltas.

      Parameters

      • loc: NormalizedLocation

        A normalized location to interpolate at

      • deltas: number[]

        A set of deltas returned from getDeltas

      Returns number | null

      The interpolated value

    • Interpolate a set of values from pre-fetched deltas and scalars. This is useful if you need to interpolate multiple values at the same location.

      Parameters

      • deltas: number[]

        A set of deltas returned from getDeltas @param scalars A set of support scalars returned from getScalars`

      • scalars: number[]

      Returns number | null

      The interpolated value, or null if no contribution

    • Interpolate a value at a given location from master values.

      Parameters

      • loc: NormalizedLocation

        A normalized location to interpolate at

      • masterValues: number[]

        A set of master values

      Returns number | null

      The interpolated value

    • Interpolate a value from master values and pre-fetched scalars. This is useful if you need to interpolate multiple values at the same location.

      Parameters

      • masterValues: number[]

        A set of master values

      • scalars: number[]

        A set of support scalars returned from getScalars

      Returns number | null

      The interpolated value

    • Interpolate from values and scalars coefficients.

      If the values are master-values, then the scalars should be fetched from getMasterScalars().

      If the values are deltas, then the scalars should be fetched from getScalars(); in which case this is the same as interpolateFromDeltasAndScalars().

      Parameters

      • values: number[]

        Values to interpolate (either master values or deltas)

      • scalars: number[]

        Scalars in the same order as values

      Returns number | null

      The interpolated value, or null if no contribution

    Interpolation and Variation Models - Variation models

    • Compute the deltas for a set of master values.

      Parameters

      • masterValues: number[]

        A value, at each master location

      Returns number[]

      A list of deltas to be applied

    • Return multipliers for each master, for the given location.

      If interpolating many master-values at the same location, this function allows speed up by fetching the scalars once and using them with interpolateFromValuesAndScalars().

      Note that the scalars used in interpolateFromMastersAndScalars() are not the same as the ones returned here. They are the result of getScalars().

      Parameters

      Returns number[]

      Scalars for each master in the original input order