[subset] Fix avar2 self-contained pins destroying CFF2/VARC variation

Adversarial review of the self-contained axis change found that the
"present the pins as ordinary partial instancing" premise does not hold
for two tables:

- CFF2 has no partial-pin instancing path: its 'pinned' path flattens
  EVERY blend at plan->normalized_coords and drops the CFF2
  VariationStore. With a self-contained pin detected, an avar2 CFF2
  font's outlines were silently frozen at the default location while
  fvar/HVAR kept live axes (reproduced end to end on AdobeVFPrototype
  with a synthesized avar2).
- VARC passes through verbatim with explicit fvar axis indices, which
  removing an axis would desynchronize.

Suppress self-contained detection when the face has either table; such
pinned axes stay in fvar as ordinary hidden pins with offset
compensation, the previously-correct behavior.

Also from the review:
- Compute the self-contained final coordinate by rounding the delta
  alone and adding it to the exact quantized intermediate, matching the
  runtime (map_coords_2_14) and fontTools; rounding the sum diverged by
  one F2Dot14 unit on exact halves of opposite sign.
- Size the serialized DeltaSetIndexMap by the entries the write loop
  actually emits, so a malformed font whose avar has fewer axes than
  fvar cannot claim unwritten (zero) entries as varIdx mappings.
- Replace a stale comment describing the abandoned rebased-store
  detection design.

Verified: pinning an axis on the synthesized avar2 CFF2 font now keeps
the axis hidden and preserves the CFF2 VariationStore; differential
tests, fontTools oracle, full suite, and reduced-config builds pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Behdad EsfahbodandClaude Opus 4.8 committed 2026-07-03 19:03:08 -06:00
1 parent 62f6ad0bb3
commit bbca76d21b
3 files changed
+45 -14

No files matched your search

+6
View File
@@ -337,6 +337,12 @@ This mirrors fontTools' `selfContainedAxes` +
`_instantiateFvarForAvar2` + second instancing pass, folded into HarfBuzz's
single-pass architecture.
Detection is suppressed (such pins stay in fvar as ordinary hidden axes)
when the face has a CFF2 table -- CFF2 has no partial-pin instancing path;
its `pinned` path flattens ALL blends and drops the CFF2 VariationStore --
or a VARC table, which passes through verbatim with explicit fvar axis
indices that axis removal would desynchronize.
### Chunk 8: Variation Culling
+13 -6
View File
@@ -776,10 +776,12 @@ struct avar
c->plan->axes_triple_distances))
return false;
/* 4. Detect self-contained pinned axes.
* A pinned axis is self-contained if after IVS rebasing, no remaining
* TupleVariation has a non-zero delta at that axis's inner position. */
/* (For now, skip self-contained detection -- all pinned axes kept as hidden) */
/* 4. Self-contained pinned axes (whose final coordinate is constant over
* the retained box) were detected at plan time
* (_compute_avar2_reachable_ranges) and removed from axes_index_map.
* They are skipped below; their constant contribution is baked into the
* other variation tables by standard instancing at the plan's
* axes_location/normalized_coords. */
/* 5. Build per-axis varIdx mapping (may create new VarDatas) */
hb_vector_t<uint32_t> new_varidx_mapping;
@@ -1071,8 +1073,13 @@ struct avar
/* Serialize DeltaSetIndexMap (push a new object). Entries cover the
* RETAINED axes only (self-contained pinned axes are removed from
* fvar), in their retained order. */
unsigned retained_axis_count = c->plan->axes_index_map.get_population ();
* fvar), in their retained order. Count what the write loop below will
* actually emit: a malformed font's avar may have fewer axes than fvar,
* and claiming unwritten entries would map those axes to varIdx 0. */
unsigned retained_axis_count = 0;
for (unsigned i = 0; i < axisCount; i++)
if (c->plan->axes_index_map.has (i))
retained_axis_count++;
hb_serialize_context_t::objidx_t packed_map;
{
/* Compute width and inner_bit_count for the mapping.
+26 -8
View File
@@ -100,7 +100,8 @@
static void
_compute_avar2_reachable_ranges (hb_subset_plan_t *plan,
hb_array_t<const OT::AxisRecord> axes,
const OT::avar *avar_table)
const OT::avar *avar_table,
bool detect_self_contained)
{
const OT::ItemVariationStore *var_store;
const OT::DeltaSetIndexMap *varidx_map;
@@ -182,14 +183,17 @@
/* A pinned axis whose delta is constant over the box is self-contained:
* its final coordinate is a constant. It can be removed from fvar/avar
* and its contribution baked into the variation tables like an ordinary
* pin at that coordinate (in old final space). */
* pin at that coordinate (in old final space). Round the delta alone
* and add it to the exact quantized intermediate, matching the runtime
* (map_coords_2_14) and fontTools. */
Triple *user;
if (dmin == dmax &&
if (detect_self_contained && dmin == dmax &&
plan->user_axes_location.has (tag, &user) && user->is_point ())
{
double v = hb_clamp (identity->first + dmin / 16384.0, -1.0, +1.0);
v = (double) roundf ((float) (v * 16384.0)) / 16384.0;
if (!plan->avar2_self_contained.set (tag, v)) return;
int v_int = (int) roundf ((float) identity->first * 16384.f) +
(int) roundf ((float) dmin);
v_int = hb_clamp (v_int, -(1 << 14), +(1 << 14));
if (!plan->avar2_self_contained.set (tag, v_int / 16384.0)) return;
continue; /* axis is dropped; no region can reference it afterwards */
}
@@ -446,8 +450,22 @@ normalize_axes_location (hb_face_t *face, hb_subset_plan_t *plan)
}
/* Reachable-range computation also detects self-contained pinned
* axes: pinned axes whose final coordinate is constant. */
_compute_avar2_reachable_ranges (plan, axes, avar_table);
* axes: pinned axes whose final coordinate is constant. Those are
* removed from fvar, so suppress the detection when the face has
* tables that cannot follow: CFF2 has no partial-pin instancing path
* (its 'pinned' path flattens ALL blends), and VARC passes through
* verbatim with explicit fvar axis indices that renumbering would
* desynchronize. Such axes stay in fvar as ordinary hidden pins. */
bool detect_self_contained = true;
for (hb_tag_t table_tag : { HB_TAG ('C','F','F','2'), HB_TAG ('V','A','R','C') })
{
hb_blob_t *blob = hb_face_reference_table (face, table_tag);
if (hb_blob_get_length (blob))
detect_self_contained = false;
hb_blob_destroy (blob);
}
_compute_avar2_reachable_ranges (plan, axes, avar_table,
detect_self_contained);
/* Keep all axes in fvar (pinned ones as hidden), EXCEPT self-contained
* pinned axes, which are removed entirely. */