avar: Axis mappings
fonttools varLib.avar.map maps variation coordinates through avar version
1 or 2. fonttools varLib.avar.reverse inverts it, finding pre-fvar
coordinates for a post-avar target:
fonttools varLib.avar.reverse -i Font.ttf wght=0.6 wdth=-0.2
-i selects normalized targets; by default the result uses pre-fvar units.
Add -o for normalized input coordinates in the result. An omitted target
axis means normalized zero while its input is free; a pinned or hidden axis is
left unconstrained, since its input cannot move. Hidden input axes are
always held at their fvar defaults. To fix another input axis, use --pin
with a pre-fvar value (independent of -i and -o):
fonttools varLib.avar.reverse -i --pin opsz=14 Font.ttf wght=0.6
Omit the value to pin an axis at its fvar default. Repeat --pin or
comma-separate to fix more axes:
fonttools varLib.avar.reverse -i --pin opsz,wdth=100 Font.ttf wght=0.6
By default every non-hidden axis may vary. To restrict the result to a chosen
set of input axes, use --vary (comma-separated or repeated); every other
axis is pinned to its fvar default, overriding hidden flags:
fonttools varLib.avar.reverse -i --vary wght,wdth,opsz Font.ttf wght=0.6 wdth=-0.2
fonttools varLib.avar.roundtrip takes a pre-fvar source, forward-maps it
through avar, and reverses the result. This checks how well a design location
survives the round trip. -i selects normalized source coordinates and
-o selects normalized recovered inputs; --pin, --vary, and
--show-error work as in the reverse command:
fonttools varLib.avar.roundtrip -o Font.ttf wght=700 wdth=125
The residual measures post-avar output differences, including the outputs of hidden and pinned axes. A non-injective map can recover different but equivalent inputs.
Inspecting structure and reachability
fonttools varLib.avar.analyze reports structural features as JSON in the
user-facing input space, with hidden and collapsed input axes fixed at their
fvar defaults:
fonttools varLib.avar.analyze Font.ttf
The report includes per-axis knots, segment-map slope changes, active avar2 region boundaries pulled back through the segment maps, and regions containing cross-axis products. Boundary patches are described by a fixed axis coordinate and unions of intervals on other axes. Intervals describe support closures; their endpoints may have zero contribution. Hidden outputs are retained. These are structural candidates: overlapping regions, cancellation, and output clipping can make some candidates invisible. This is not a complete classification of critical points or topology.
Extract a normalized output level set on a one- or two-axis input slice:
fonttools varLib.avar.analyze Font.ttf --axes wght,wdth --contour XOPQ=0.3 --at opsz=14
Unspecified inputs stay at default. Slice coordinates and --at use user
units. The result contains isolated points, polylines, and constant cells.
One-dimensional roots use SciPy, and two-dimensional polylines use ContourPy.
Curves describe the continuous map before avar2 quantization and clipping;
levels -1 and +1 describe saturation boundaries. Two-dimensional curves are
sampled approximations, with avar knots inserted into the grid. Slices with
jumps are rejected to avoid interpolating across discontinuities. The grid
is limited to 65,536 points.
fonttools varLib.avar.reachability checks output targets and returns JSON:
fonttools varLib.avar.reachability -i Font.ttf XOPQ=0.3
Only explicitly supplied outputs are constrained; omitted outputs are free.
-i selects normalized targets; otherwise targets use pre-fvar units.
Hidden inputs remain at default even when a hidden output is targeted. A
reachable result contains a user-coordinate witness verified with the
rounded/clipped forward map. Its input dictionary omits axes at their
fvar defaults; omitted inputs implicitly use those defaults. Conservative
marginal bounds can establish
unreachable. Other failed searches return undetermined, with the best
fit found and its normalized Euclidean error. Marginal bounds do not describe
joint reachability. --tolerance sets the accepted output error (default:
one F2Dot14 unit).
Python callers can reuse a prepared checker:
from fontTools.varLib.avar.analyze import analyze, contours
from fontTools.varLib.avar.reachability import ReachabilityMapper
structure = analyze(font)
geometry = contours(font, ["wght", "wdth"], "XOPQ", 0.3, location={"opsz": 14})
checker = ReachabilityMapper(font)
result = checker.check({"XOPQ": 0.3}, inputNormalized=True)
Plotting slices
fonttools varLib.avar.plot uses the analyzer’s structural boundaries and
contour geometry to plot an input slice next to its mapped output grid:
fonttools varLib.avar.plot Font.ttf wght wdth --output XOPQ --at opsz=14 -o avar.svg
It also supports a single input axis. Omitting -o opens a Matplotlib
window. Input coordinates use user units; colors and projected output axes
use normalized units. Hidden inputs and other unspecified inputs stay at
default. The mapped view shows the projected image of this particular slice,
not the complete reachable space. Jumps in either projected output are
rejected rather than connected by grid segments. Install
fonttools[avar,plot] for the optional numerical, contour, and plotting
dependencies:
from fontTools.varLib.avar.plot import plot
figure = plot(font, ["wght", "wdth"], output="XOPQ", location={"opsz": 14})
figure.savefig("avar.svg")
Prepared mapping
For repeated forward evaluations, prepare a mapper once:
from fontTools.varLib.avar.map import ForwardMapper
mapper = ForwardMapper(font)
first = mapper.map({"wght": 600}, outputNormalized=True)
second = mapper.map({"wght": 700}, outputNormalized=True)
This retains axis metadata and the VarStore region-support cache. It requires
no NumPy or SciPy. Construct a new mapper after changing the font’s fvar or
avar tables. The module-level map() function remains available for
individual calls.
Prepare a reverse mapper to solve several targets with the same constraints:
from fontTools.varLib.avar.reverse import ReverseMapper
mapper = ReverseMapper(font, pinned={"opsz": None})
first, error = mapper.reverse({"wght": 0.6}, inputNormalized=True)
second, error = mapper.reverse({"wght": 0.8}, inputNormalized=True)
The solver retains its unrounded mapping, Jacobian data, starting points,
and exact forward evaluator. It memoizes up to 128 target solutions by default;
cache_size=0 disables memoization, and clear_cache() discards cached
solutions. Unit and output-filtering options share cached solutions, but
explicitly specified fixed-axis targets and sparsity tolerances remain distinct.
Each call returns a fresh location dictionary. Pins and vary are fixed at
construction, and changing the font’s fvar or avar tables requires a new mapper.
The module-level reverse() function remains available for individual calls.
The Python reverse APIs also accept partial=True to leave every omitted
output unconstrained, as in the reachability checker.
Collapsed region-support edges can introduce jumps even before rounding. The solver tests their exact boundaries with the affected inputs fixed, then searches adjacent intervals with bounds that prevent crossing those jumps. Boundaries are pulled back through the avar1 segment maps, including multiple preimages and plateau endpoints. Region contexts also test intersections of jump planes. This does not exhaustively enumerate combinations of intervals across all axes, so a global optimum is still not guaranteed.
Reverse mapping requires the optional fonttools[avar] dependencies.
It minimizes normalized output error, then prefers fewer non-default input
axes among solutions within one F2Dot14 unit of the best error found. A greedy
search seeks sparse solutions; neither global optimality nor the minimum
possible number of axes is guaranteed. Unreachable targets return an
approximation; --show-error prints the residual, and the Python API returns
it as the error alongside the location. CLI output is rounded to the font’s
F2Dot14 resolution for readability. The font is not modified.
Find pre-fvar coordinates that approximate a post-avar location.
The numerical solver uses an unrounded forward map and its local Jacobian. Candidates are ranked using the actual forward map, including avar2 rounding and clipping. SciPy is optional and is imported when a solver is constructed.
- fontTools.varLib.avar.reverse.reverse(font, location, *, inputNormalized=False, outputNormalized=False, dropZeroes=False, pinned=None, vary=None, tolerance=6.103515625e-05, partial=False)[source]
Approximately invert an avar (version 1 or 2) mapping.
Returns
(location, error), whereerroris the residual output error in normalized coordinates (Euclidean distance over the scored axes). It is about one F2Dot14 unit or less when the search reaches the target, and larger when the target is unreachable. Returns None for a font without fvar.locationspecifies post-avar targets. An omitted axis targets normalized zero while its input is free; when its input is pinned or hidden it is left unconstrained, since the caller cannot move it. Input and output units follow avar.map: by default both are in pre-fvar units, withinputNormalizedandoutputNormalizedselecting normalized target and result coordinates, respectively.Hidden axes are held at their fvar defaults.
pinnedoptionally maps other axis tags to fixed PRE-FVAR values, regardless of the unit flags. A pinned value of None means the axis’s fvar default.varyoptionally restricts the inputs that may move to a set of axis tags, pinning every other axis to its default and overriding hidden flags; by default all non-hidden axes may vary. Returned coordinates stay within the fvar ranges.With
partial=True, only explicitly supplied output axes are scored; omitted outputs are unconstrained. This is useful for reachability queries.Output error is Euclidean distance in normalized coordinates. Among candidates within
toleranceof the smallest error found, prefer fewer non-default input axes, then smaller error and normalized distance from default.toleranceis only this sparsity budget, not an accuracy threshold. Sparsity is sought by greedy elimination, not exhaustive subset search. Multiple starts reduce local-minimum sensitivity but do not guarantee a global optimum. Requires SciPy. For repeated targets with the same font and input constraints, use ReverseMapper.
- class fontTools.varLib.avar.reverse.ReverseMapper(font, *, pinned=None, vary=None, cache_size=128)[source]
Bases:
objectPrepare an avar inverse solver for multiple targets.
Pin and vary constraints are fixed at construction. reverse() takes the target, unit flags, output filtering, and sparsity tolerance, returning the same (location, error) pair as the module-level reverse() function.
The unrounded mapping/Jacobian, exact forward evaluator, axis bounds, and target-independent starting points are reused. Up to cache_size target solutions are memoized per instance; zero disables this cache. Output dictionaries are fresh, so callers may modify them safely.
The font must contain fvar. Do not change its fvar or avar tables while using a mapper; build a new mapper after such changes.
- fontTools.varLib.avar.reverse.main(args=None)[source]
Find pre-fvar inputs that produce post-avar targets (invert avar).
- class fontTools.varLib.avar.map.ForwardMapper(font)[source]
Bases:
objectPrepare a font’s axis mappings for repeated forward evaluations.
map() accepts the same location and unit options as the module-level map() function. Axis metadata, segment maps, delta-set indices, and the VarStore evaluator are prepared once; the evaluator retains its region support cache between locations. No NumPy or SciPy dependency is needed.
The font must contain fvar. Construct a new mapper after changing its fvar or avar tables.
- fontTools.varLib.avar.map.map(font, location, *, inputNormalized=False, outputNormalized=False, dropZeroes=False, reverse=False, pinned=None, vary=None)[source]
Map coordinates through avar, or approximately invert it.
Omitted axes use their fvar defaults in user coordinates, or zero when inputNormalized is True. dropZeroes omits normalized-zero OUTPUT axes, independently of the input/output units and the avar version.
With
reverse=True, return the(location, error)tuple fromfontTools.varLib.avar.reverse.reverse(); otherwise return the mapped location.pinnedandvaryare only supported for reverse mapping. For repeated forward evaluations use ForwardMapper to reuse prepared state.
- fontTools.varLib.avar.map.main(args=None)[source]
Map variation coordinates through the avar table.
Forward-map a location through avar, then recover equivalent inputs.
- fontTools.varLib.avar.roundtrip.roundtrip(font, location, *, inputNormalized=False, outputNormalized=False, dropZeroes=False, pinned=None, vary=None, tolerance=6.103515625e-05)[source]
Map a pre-fvar source through avar and reverse the resulting location.
Return
(location, error)as infontTools.varLib.avar.reverse.reverse(), or None for a font without fvar.inputNormalizeddescribes the source units;outputNormalizeddescribes the recovered input units.All forward-mapped output axes, including hidden and pinned axes, are scored during reversal. The error measures post-avar output differences, so a non-injective map may recover a different but equivalent input.
- fontTools.varLib.avar.roundtrip.main(args=None)[source]
Map pre-fvar inputs through avar, then recover equivalent inputs.
Inspect avar features on the slice with hidden inputs at their defaults.
Structural features are candidates: overlapping regions can cancel them. Coordinates describing their loci use user units; deltas and output bounds use normalized coordinates. Quantization steps are not structural features.
- fontTools.varLib.avar.analyze.analyze(font)[source]
Return JSON-compatible structural features in the public input space.
Hidden and collapsed input axes stay at default. Hidden outputs are retained. A boundary fixes one input coordinate, with the other coordinates restricted to the listed unions of closed intervals. Those intervals are support closures; a tent may be zero at an endpoint. Features are structural candidates, not a claim that every boundary survives cancellation or clipping. Interaction regions identify products of at least two varying input factors.
- fontTools.varLib.avar.analyze.contours(font, axes, output, level=0, *, location=None, samples=33)[source]
Extract an unrounded output level set on a one- or two-axis slice.
Input geometry uses user units;
leveluses normalized output units. Other inputs stay atlocationor their defaults; hidden inputs must stay at default. One-dimensional roots use SciPy; two-dimensional curves use ContourPy. Knots are inserted in the sampling grid. Curves approximate the continuous map before avar2 rounding and clipping; levels +/-1 describe saturation boundaries. Constant intervals/cells are returned separately. Slices with jumps are rejected rather than interpolated across.
- fontTools.varLib.avar.analyze.main(args=None)[source]
Inspect avar structure or extract an output contour as JSON.
Check post-avar targets with hidden input axes held at default.
- class fontTools.varLib.avar.reachability.ReachabilityMapper(font)[source]
Bases:
objectPrepare repeated target checks against a font’s public input space.
Only explicitly supplied outputs are constrained, including any hidden outputs in the target. Results contain normalized targets and outputs and a witness in user units, omitting inputs at their fvar defaults.
reachablemeans that forward evaluation of that witness meets the requested tolerance.unreachablemeans marginal bounds exclude the target. Otherwise the result isundetermined: a numerical search does not establish non-reachability.Construct a new mapper after changing fvar or avar.
- check(location, *, inputNormalized=False, tolerance=6.103515625e-05)[source]
Check a possibly partial output target; omitted axes are unconstrained.
Targets use user units unless
inputNormalizedis true.toleranceis Euclidean output distance in normalized coordinates. A hidden axis inlocationconstrains its output, never its input.
- fontTools.varLib.avar.reachability.check(font, location, *, inputNormalized=False, tolerance=6.103515625e-05)[source]
Check one target; use ReachabilityMapper to reuse preparation and caching.
- fontTools.varLib.avar.reachability.main(args=None)[source]
Check output reachability and print a verified input witness as JSON.
Plot avar structure and the mapped image of a public-input slice.
- fontTools.varLib.avar.plot.plot(font, axes, *, output=None, location=None, samples=33, levels=None, figure=None)[source]
Return a Matplotlib figure for a one- or two-axis slice.
Calls analyze() for structural boundaries, contours() for continuous output level sets, and ForwardMapper for rounded/clipped mapped samples. Hidden inputs and other unspecified inputs stay at default. Input axes use user units; colors and projected outputs use normalized units.
The mapped grid shows the image of this slice projected onto two output axes. It is sampled geometry, not a certificate of global reachability.