[fonttools/fonttools] 8a7e2c: [instancer] avar2: collect interior avar1 breakpoi...

1 view
Skip to first unread message

Behdad Esfahbod

unread,
Jul 2, 2026, 9:10:03 PM (13 days ago) Jul 2
to fontto...@googlegroups.com
Branch: refs/heads/avar2-instancing
Home: https://github.com/fonttools/fonttools
Commit: 8a7e2ce6a5fc4767ac0198503e0bb9a72c488009
https://github.com/fonttools/fonttools/commit/8a7e2ce6a5fc4767ac0198503e0bb9a72c488009
Author: Behdad Esfahbod <beh...@behdad.org>
Date: 2026-07-02 (Thu, 02 Jul 2026)

Changed paths:
M Lib/fontTools/varLib/instancer/__init__.py
M Tests/varLib/instancer/instancer_test.py
M partial-instancing-avar2-design.md

Log Message:
-----------
[instancer] avar2: collect interior avar1 breakpoints for offset compensation

Partial-instancing offset compensation sampled offset(z) only at
{-1, 0, +1, z_old}. When the retained range spans an interior avar v1
segment breakpoint, offset(z) has a further kink at that breakpoint's
new-intermediate image, which the anchors alone miss — so the compensation
was approximate there, worst under a moved default on an asymmetric axis
(tens of F2Dot14 units in near-edge cases).

_instantiateAvarV2 now also iterates the retained (renormalized) avar v1
segment map — which keeps exactly the in-range old breakpoints — and adds
each breakpoint's (z, old-intermediate) to the offset model, so the
VariationModel reproduces offset(z) at every kink. Iterating the retained
map lands each sample on the F2Dot14-quantized kink location. The change is
additive: with no avar v1 map (or none in range) the retained map carries
only {-1, 0, +1}, offset_by_z is unchanged, and the classic bias+two-tents
encoding results — existing output is byte-identical.

This removes the structural error. A smaller residual can remain from
F2Dot14 requantization of a steep retained segment when a moved default
compresses part of the axis into a narrow z band; that is inherent to
avar v1 partial instancing, not the avar2 offset math.

Adds a regression test (fails without the collection: worst 4 and 14) and
updates the design doc (§4.3, §4.4, §9.2).

Co-Authored-By: Claude Opus 4.8 (1M context) <nor...@anthropic.com>


Commit: 36064574e484e11098025b62858179be1656a79b
https://github.com/fonttools/fonttools/commit/36064574e484e11098025b62858179be1656a79b
Author: Behdad Esfahbod <beh...@behdad.org>
Date: 2026-07-02 (Thu, 02 Jul 2026)

Changed paths:
M Lib/fontTools/varLib/instancer/__init__.py

Log Message:
-----------
[instancer] avar2: warn when offset compensation can't be bit-exact

The retained avar v1 map is stored in F2Dot14, so a steep segment (a moved
default compressing part of the axis into a narrow z band) leaves a
slope-amplified residual that offset compensation cannot remove. After
building the per-axis offset model, estimate the residual
|old-avar1-final - (new-avar1 + offset)| across the retained range and warn,
listing the affected axes and the max F2Dot14 error, when it exceeds a
threshold (~2 is the quantization floor). Clean cases (no avar v1 map, gentle
maps, fixed defaults) stay silent.

Co-Authored-By: Claude Opus 4.8 (1M context) <nor...@anthropic.com>


Commit: 8f14554d98bd2ee3b8d436621619d8a508c466d5
https://github.com/fonttools/fonttools/commit/8f14554d98bd2ee3b8d436621619d8a508c466d5
Author: Behdad Esfahbod <beh...@behdad.org>
Date: 2026-07-02 (Thu, 02 Jul 2026)

Changed paths:
M Lib/fontTools/varLib/instancer/__init__.py

Log Message:
-----------
[instancer] avar2: keep interior breakpoints only when they reduce residual

Collecting interior avar v1 breakpoints adds one offset tent per breakpoint,
and each tent's delta is rounded to F2Dot14. For a steep retained segment
(a moved default compressing the axis into a narrow z band) the added
rounding could exceed the structural error removed, so blind collection
regressed some near-vertical maps (e.g. 15 -> 20 F2Dot14 in a sweep).

Estimate the residual both with and without the interior breakpoints
(_estimateAvar2OffsetError) and keep them only when they do not increase it.
The collection is now a strict, never-worse improvement over the
{-1, 0, +1, z_old} anchors: across a 100-case sweep, 32 improved (up to
16 -> 4), 59 unchanged, and the max regression fell from 5 to 1 F2Dot14 unit
(quantization noise). Real fonts benefit substantially (AmstelvarA2 opsz with
the default moved to 117: 18 -> 2).

Also raise the warning threshold to 8 F2Dot14 units: a few units of residual
are common and imperceptible for real avar v1 maps (silent on AmstelvarA2's
16-breakpoint opsz map even with a moved default), so only a clearly larger,
genuinely approximate residual is flagged.

Co-Authored-By: Claude Opus 4.8 (1M context) <nor...@anthropic.com>


Compare: https://github.com/fonttools/fonttools/compare/d83ecfb89917...8f14554d98bd

To unsubscribe from these emails, change your notification settings at https://github.com/fonttools/fonttools/settings/notifications
Reply all
Reply to author
Forward
0 new messages