mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-22 15:31:05 +01:00
[instancer] Fix HVAR partial instancing for map-less advance mappings (#6070)
* [instancer] Don't dedup VarStore rows when not optimizing as_item_varstore dropped duplicate delta rows even with optimize=false, where varidx_map is left empty and callers rely on original VariationIndex values staying valid. HVAR/VVAR subsetting uses that mode when the source table has an implicit (map-less) advance mapping: any two glyphs sharing identical deltas shifted every following row, so the synthesized identity map pointed at wrong rows and past the end of the VarData — advances silently froze or took neighbors' deltas when partially instancing such fonts (e.g. Source Han fonts). Fixes https://github.com/harfbuzz/harfbuzz/issues/6068 * [subset] Drop identity advance maps for map-less HVAR/VVAR sources When the source table uses implicit glyph-id indexing, the subsetter synthesized an advance DeltaSetIndexMap whose content was the identity over every output glyph — equivalent to the implicit indexing it replaced, just bigger. Recognize that case in is_identity () and keep the output map-less, like fontTools does. Sources that carry a real map keep one, preserving their form; truncated maps don't qualify since glyphs past their end share the last value. retain-num-glyphs expected files regenerated: NotoSansJP-VF.subset.otf is map-less, and its redundant identity map is now dropped (verified against fontTools output). * [test/subset] Test partial instancing of map-less HVAR ImplicitHVAR.ttf carries an HVAR with implicit (map-less) advance indexing and deliberately duplicated delta rows, the combination that broke before the row-dedup fix: rows shifted or fell off the end of the rebuilt VarData and advances silently froze. Expected outputs are cross-checked against fontTools varLib.instancer + subset.
This commit is contained in:
1 parent
8c9307b59a
commit
f26e0cd4ed
10 files changed
+43
-4
No files matched your search
@@ -1964,10 +1964,16 @@ struct item_variations_t
|
||||
if (!front_mapping.set ((major<<16) + minor, &row))
|
||||
return false;
|
||||
|
||||
if (delta_rows_map.has (&row))
|
||||
continue;
|
||||
/* Duplicate rows may only be dropped when optimizing: without a
|
||||
* varidx_map the caller relies on original VariationIndex values
|
||||
* staying valid (e.g. HVAR/VVAR with an implicit advance mapping). */
|
||||
if (optimize)
|
||||
{
|
||||
if (delta_rows_map.has (&row))
|
||||
continue;
|
||||
|
||||
delta_rows_map.set (&row, 1);
|
||||
delta_rows_map.set (&row, 1);
|
||||
}
|
||||
|
||||
major_rows.push (&row);
|
||||
}
|
||||
|
||||
@@ -49,6 +49,12 @@ struct index_map_subset_plan_t
|
||||
bool bypass_empty = true)
|
||||
{
|
||||
map_count = 0;
|
||||
full_map_count = plan->new_to_old_gid_list.length ?
|
||||
plan->new_to_old_gid_list.tail ().first + 1 : 0;
|
||||
/* Only the advance mapping may be dropped in favor of implicit
|
||||
* glyph-id indexing (for the others a null offset means no deltas),
|
||||
* and only when the source was map-less too, preserving its form. */
|
||||
can_drop_to_implicit = !bypass_empty && !index_map;
|
||||
max_inners.init ();
|
||||
output_map.init ();
|
||||
|
||||
@@ -187,11 +193,24 @@ struct index_map_subset_plan_t
|
||||
DeltaSetIndexMap::min_size);
|
||||
}
|
||||
|
||||
bool is_identity () const { return get_output_map ().length == 0; }
|
||||
bool is_identity () const
|
||||
{
|
||||
if (!output_map) return true;
|
||||
/* An advance map whose entries are the identity over every output
|
||||
* glyph is equivalent to implicit glyph-id indexing; drop it. A
|
||||
* truncated map doesn't qualify: glyphs past its end share its last
|
||||
* value, not their own ids. */
|
||||
if (!can_drop_to_implicit || map_count != full_map_count) return false;
|
||||
for (unsigned i = 0; i < map_count; i++)
|
||||
if (output_map.arrayZ[i] != i) return false;
|
||||
return true;
|
||||
}
|
||||
hb_array_t<const uint32_t> get_output_map () const { return output_map.as_array (); }
|
||||
|
||||
protected:
|
||||
unsigned int map_count;
|
||||
unsigned int full_map_count;
|
||||
bool can_drop_to_implicit;
|
||||
hb_vector_t<unsigned int> max_inners;
|
||||
unsigned int outer_bit_count;
|
||||
unsigned int inner_bit_count;
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,13 @@
|
||||
FONTS:
|
||||
ImplicitHVAR.ttf
|
||||
|
||||
PROFILES:
|
||||
default.txt
|
||||
|
||||
SUBSETS:
|
||||
*
|
||||
ABC
|
||||
|
||||
INSTANCES:
|
||||
wght=300:600
|
||||
wght=200:400:800
|
||||
@@ -76,6 +76,7 @@ tests = [
|
||||
'instantiate_cff2_update_metrics',
|
||||
'layout.empty_ligature_offset',
|
||||
'glyf_partial_instancing',
|
||||
'hvar_partial_instance_implicit_map',
|
||||
'mvar_partial_instance',
|
||||
'update_def_wght',
|
||||
'feature_variations_partial_instance',
|
||||
|
||||
Reference in new issue
Block a user