[subset] Fix avar2 offset compensation bugs

Fix two bugs in _subset_avar2():

1. Deduplicate default-delta bias for shared varIdx entries.
   When multiple axes share the same (outer,inner) in VarIdxMap,
   the free-axis loop was adding the default_delta bias once per
   axis, causing double/triple-counting. Track processed varIdx
   values and skip duplicates.

2. Fix DeltaSetIndexMap serialization for NO_VARIATION_INDEX.
   When any axis has NO_VARIATION_INDEX (0xFFFFFFFF), use 4-byte
   width to avoid truncation of the sentinel value.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Behdad EsfahbodandClaude Opus 4.6 committed 2026-07-01 12:42:56 -06:00
1 parent d171d444b1
commit 455c5a11d4
1 file changed
+35 -11
+35 -11
View File
@@ -608,7 +608,10 @@ struct avar
for (unsigned i = 0; i < axisCount; i++)
new_varidx_mapping[i] = varidx_map.map (i);
/* 6. Add offset compensation tuples */
/* 6. Add offset compensation tuples.
* Track processed (outer,inner) pairs to avoid adding duplicate biases
* when multiple axes share the same varIdx. */
hb_set_t processed_varidxes;
for (unsigned i = 0; i < axisCount; i++)
{
hb_tag_t *axis_tag_ptr;
@@ -687,11 +690,16 @@ struct avar
else
{
/* Free or private axis — not being restricted.
* If it has a non-zero default delta, add it back as a bias. */
* If it has a non-zero default delta, add it back as a bias.
* Skip if this (outer,inner) was already processed (shared varIdx). */
uint32_t varidx = new_varidx_mapping[i];
if (varidx == HB_OT_LAYOUT_NO_VARIATIONS_INDEX)
continue;
if (processed_varidxes.has (varidx))
continue;
processed_varidxes.add (varidx);
unsigned outer = varidx >> 16;
unsigned inner = varidx & 0xFFFF;
int dd = (int) roundf (default_deltas[i]);
@@ -732,28 +740,44 @@ struct avar
/* Serialize DeltaSetIndexMap (push a new object) */
hb_serialize_context_t::objidx_t packed_map;
{
/* Compute width and inner_bit_count for the mapping */
/* Compute width and inner_bit_count for the mapping.
* If any entry is NO_VARIATION_INDEX (0xFFFFFFFF), we need full
* 4-byte width to represent it. */
bool has_no_variation = false;
unsigned max_outer = 0, max_inner = 0;
for (unsigned i = 0; i < axisCount; i++)
{
uint32_t varidx = new_varidx_mapping[i];
if (varidx == HB_OT_LAYOUT_NO_VARIATIONS_INDEX)
{
has_no_variation = true;
continue;
}
unsigned o = varidx >> 16;
unsigned in = varidx & 0xFFFF;
if (o > max_outer) max_outer = o;
if (in > max_inner) max_inner = in;
}
unsigned inner_bit_count = hb_max (1u, hb_bit_storage (max_inner));
unsigned outer_bit_count = hb_max (1u, hb_bit_storage (max_outer));
unsigned width = (inner_bit_count + outer_bit_count + 7) / 8;
width = hb_max (width, 1u);
width = hb_min (width, 4u);
unsigned inner_bit_count, width;
if (has_no_variation)
{
/* Need 4 bytes to encode NO_VARIATION_INDEX = 0xFFFFFFFF */
width = 4;
inner_bit_count = 16;
}
else
{
inner_bit_count = hb_max (1u, hb_bit_storage (max_inner));
unsigned outer_bit_count = hb_max (1u, hb_bit_storage (max_outer));
width = (inner_bit_count + outer_bit_count + 7) / 8;
width = hb_max (width, 1u);
width = hb_min (width, 4u);
/* Recalculate inner_bit_count based on width */
if (inner_bit_count + outer_bit_count > width * 8)
inner_bit_count = width * 8 - outer_bit_count;
/* Recalculate inner_bit_count based on width */
if (inner_bit_count + outer_bit_count > width * 8)
inner_bit_count = width * 8 - outer_bit_count;
}
/* Serialize DeltaSetIndexMap format 0 (HBUINT16 mapCount) */
c->serializer->push ();