mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-28 09:09:13 +01:00
[subset] Harden VARC closure handling
Propagate allocation and component-decoding failures from VARC closure instead of continuing with an incomplete glyph set. Treat malformed VARC records as dependency-extraction failures as well. Document VARC dependency edges and exercise subset variation-store remapping at non-default coordinates. Tested with: - meson test -C build - standalone lean and world syntax checks - CMake harfbuzz-subset build Assisted-by: OpenAI Codex <openai-codex@users.noreply.github.com>
This commit is contained in:
1 parent
5343bf4019
commit
cfe86ce5e7
9 files changed
+54
-15
No files matched your search
+2
-2
@@ -126,7 +126,7 @@ for (unsigned int i = 0; i < total; i++) {
|
||||
printf("GID %u -> %u via GSUB feature '%c%c%c%c'\n",
|
||||
gid, entry.dependent, HB_UNTAG(entry.layout_tag));
|
||||
} else {
|
||||
// Other dependencies (glyf, CFF, COLR, MATH)
|
||||
// Other dependencies (glyf, CFF, COLR, MATH, VARC)
|
||||
printf("GID %u -> %u via %c%c%c%c\n",
|
||||
gid, entry.dependent, HB_UNTAG(entry.table_tag));
|
||||
}
|
||||
@@ -319,7 +319,7 @@ Each `hb_subset_depend_entry_t` filled by `hb_subset_depend_lookup_glyph()` cont
|
||||
|
||||
- **table_tag**: Source table (e.g., `HB_OT_TAG_GSUB`,
|
||||
`HB_TAG('g','l','y','f')`, `HB_TAG('C','F','F',' ')`, `HB_TAG('C','O','L','R')`,
|
||||
`HB_TAG('M','A','T','H')`)
|
||||
`HB_TAG('M','A','T','H')`, `HB_TAG('V','A','R','C')`)
|
||||
- **dependent**: The dependent glyph ID
|
||||
- **layout_tag**:
|
||||
- For GSUB: the feature tag (e.g., `HB_TAG('l','i','g','a')`)
|
||||
|
||||
@@ -45,7 +45,7 @@ function demonstrates proper handling of:
|
||||
- Feature filtering (only following edges for active GSUB features)
|
||||
- Ligature sets (only adding ligature outputs when all components present)
|
||||
- Context sets (only following edges when positional requirements satisfied)
|
||||
- Non-GSUB dependencies (glyf, CFF, COLR, MATH)
|
||||
- Non-GSUB dependencies (glyf, CFF, COLR, MATH, VARC)
|
||||
- UVS handling (via `hb_font_get_variation_glyph()`, separate from depend graph)
|
||||
|
||||
Key aspects of the implementation:
|
||||
|
||||
@@ -372,7 +372,8 @@ This keeps related code together and makes it easier to maintain consistency.
|
||||
|
||||
## Future Considerations
|
||||
|
||||
The depend API currently focuses on GSUB, glyf, CFF, COLR, and MATH tables. Future extensions could include:
|
||||
The depend API currently focuses on GSUB, glyf, CFF, COLR, MATH, and VARC
|
||||
tables. Future extensions could include:
|
||||
|
||||
- **GPOS dependencies**: Some GPOS rules reference glyphs (e.g., mark-to-base positioning)
|
||||
- **MORX dependencies**: Apple Advanced Typography morph tables
|
||||
|
||||
+16
-3
@@ -145,16 +145,23 @@ VarComponent::decompile_record (const VARC &varc,
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
VARC::closure_glyphs (hb_set_t *glyphset) const
|
||||
{
|
||||
if (unlikely (glyphset->in_error ()))
|
||||
return false;
|
||||
|
||||
hb_set_t visited;
|
||||
while (true)
|
||||
{
|
||||
hb_set_t pending = *glyphset;
|
||||
pending.subtract (visited);
|
||||
if (unlikely (pending.in_error ()))
|
||||
return false;
|
||||
if (!pending) break;
|
||||
visited.union_ (pending);
|
||||
if (unlikely (visited.in_error ()))
|
||||
return false;
|
||||
|
||||
for (hb_codepoint_t gid : pending)
|
||||
{
|
||||
@@ -167,12 +174,15 @@ VARC::closure_glyphs (hb_set_t *glyphset) const
|
||||
VarComponent::record_t component;
|
||||
if (unlikely (!VarComponent::decompile_record (*this, record,
|
||||
nullptr, nullptr, &component)))
|
||||
break;
|
||||
return false;
|
||||
glyphset->add (component.gid);
|
||||
if (unlikely (glyphset->in_error ()))
|
||||
return false;
|
||||
record = record.sub_array (component.size);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -189,7 +199,10 @@ VARC::depend (hb_depend_data_builder_t *depend_data) const
|
||||
VarComponent::record_t component;
|
||||
if (unlikely (!VarComponent::decompile_record (*this, record,
|
||||
nullptr, nullptr, &component)))
|
||||
break;
|
||||
{
|
||||
depend_data->fail ();
|
||||
return;
|
||||
}
|
||||
depend_data->add_depend (gid, tableTag, component.gid);
|
||||
record = record.sub_array (component.size);
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ struct VARC
|
||||
hb_codepoint_t parent_gid = HB_CODEPOINT_INVALID,
|
||||
hb_scalar_cache_t *parent_cache = nullptr) const;
|
||||
|
||||
HB_INTERNAL void closure_glyphs (hb_set_t *glyphset) const;
|
||||
HB_INTERNAL bool closure_glyphs (hb_set_t *glyphset) const;
|
||||
HB_INTERNAL void depend (hb_depend_data_builder_t *depend_data) const;
|
||||
HB_INTERNAL bool subset (hb_subset_context_t *c) const;
|
||||
|
||||
@@ -235,10 +235,11 @@ struct VARC
|
||||
return ret;
|
||||
}
|
||||
|
||||
void closure_glyphs (hb_set_t *glyphset) const
|
||||
bool closure_glyphs (hb_set_t *glyphset) const
|
||||
{
|
||||
if (table->has_data ())
|
||||
table->closure_glyphs (glyphset);
|
||||
return table->closure_glyphs (glyphset);
|
||||
return true;
|
||||
}
|
||||
|
||||
void depend (hb_depend_data_builder_t *depend_data) const
|
||||
|
||||
@@ -61,7 +61,7 @@ HB_MARK_AS_FLAG_T (hb_subset_depend_edge_flags_t);
|
||||
* Records that glyph A depends on glyph B through a specific OpenType
|
||||
* mechanism (table_tag), with additional metadata:
|
||||
*
|
||||
* - table_tag: Source table (GSUB, glyf, CFF, COLR, MATH)
|
||||
* - table_tag: Source table (GSUB, glyf, CFF, COLR, MATH, VARC)
|
||||
* - dependent: Target glyph ID
|
||||
* - layout_tag: Feature tag (for GSUB), else 0
|
||||
* - ligature_set: Index into sets array for ligature components, else INVALID
|
||||
|
||||
+2
-2
@@ -108,8 +108,8 @@ hb_depend_data_builder_t::compile (hb_face_t *face)
|
||||
* @face: font face to collect dependencies from
|
||||
*
|
||||
* Calculates the dependencies between glyphs in the supplied face.
|
||||
* Extracts dependency information from GSUB, glyf, CFF, COLR,
|
||||
* and MATH tables. UVS (Unicode Variation Sequence) dependencies
|
||||
* Extracts dependency information from GSUB, glyf, CFF, COLR, MATH,
|
||||
* and VARC tables. UVS (Unicode Variation Sequence) dependencies
|
||||
* are not included; handle those via hb_font_get_variation_glyph().
|
||||
*
|
||||
* Example:
|
||||
|
||||
@@ -479,7 +479,11 @@ _populate_gids_to_retain (hb_subset_plan_t* plan,
|
||||
#ifndef HB_NO_VAR_COMPOSITES
|
||||
if (!drop_tables->has (OT::VARC::tableTag))
|
||||
{
|
||||
plan->source->table.VARC->closure_glyphs (&cur_glyphset);
|
||||
if (unlikely (!plan->source->table.VARC->closure_glyphs (&cur_glyphset)))
|
||||
{
|
||||
plan->check_success (false);
|
||||
return;
|
||||
}
|
||||
_remove_invalid_gids (&cur_glyphset, plan->source->get_num_glyphs ());
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -61,9 +61,11 @@ draw_close_path (hb_draw_funcs_t *funcs HB_UNUSED, void *data,
|
||||
{ g_string_append_c ((GString *) data, 'Z'); }
|
||||
|
||||
static char *
|
||||
draw_unicode (hb_face_t *face, hb_codepoint_t unicode)
|
||||
draw_unicode_at (hb_face_t *face, hb_codepoint_t unicode,
|
||||
const hb_variation_t *variations, unsigned variation_count)
|
||||
{
|
||||
hb_font_t *font = hb_font_create (face);
|
||||
hb_font_set_variations (font, variations, variation_count);
|
||||
hb_codepoint_t gid;
|
||||
g_assert_true (hb_font_get_nominal_glyph (font, unicode, &gid));
|
||||
|
||||
@@ -81,6 +83,10 @@ draw_unicode (hb_face_t *face, hb_codepoint_t unicode)
|
||||
return g_string_free (path, false);
|
||||
}
|
||||
|
||||
static char *
|
||||
draw_unicode (hb_face_t *face, hb_codepoint_t unicode)
|
||||
{ return draw_unicode_at (face, unicode, NULL, 0); }
|
||||
|
||||
static void
|
||||
assert_has_varc (hb_face_t *face, hb_bool_t expected)
|
||||
{
|
||||
@@ -136,10 +142,24 @@ test_subset_varc_draw_equivalence (void)
|
||||
hb_face_t *subset = subset_varc (face, 0xAC01);
|
||||
char *source_path = draw_unicode (face, 0xAC01);
|
||||
char *subset_path = draw_unicode (subset, 0xAC01);
|
||||
hb_variation_t variations[] = {
|
||||
{HB_TAG ('w','g','h','t'), 840.3f},
|
||||
{HB_TAG ('o','p','s','z'), 1.f},
|
||||
};
|
||||
char *varied_source_path = draw_unicode_at (face, 0xAC01,
|
||||
variations,
|
||||
G_N_ELEMENTS (variations));
|
||||
char *varied_subset_path = draw_unicode_at (subset, 0xAC01,
|
||||
variations,
|
||||
G_N_ELEMENTS (variations));
|
||||
|
||||
g_assert_cmpstr (source_path, !=, "");
|
||||
g_assert_cmpstr (subset_path, ==, source_path);
|
||||
g_assert_cmpstr (varied_source_path, !=, source_path);
|
||||
g_assert_cmpstr (varied_subset_path, ==, varied_source_path);
|
||||
|
||||
g_free (varied_subset_path);
|
||||
g_free (varied_source_path);
|
||||
g_free (subset_path);
|
||||
g_free (source_path);
|
||||
hb_face_destroy (subset);
|
||||
|
||||
Reference in new issue
Block a user