diff --git a/docs/depend-api.md b/docs/depend-api.md index 974ce6f5a..06ae215ec 100644 --- a/docs/depend-api.md +++ b/docs/depend-api.md @@ -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')`) diff --git a/docs/depend-for-closure.md b/docs/depend-for-closure.md index e971f1929..f119289db 100644 --- a/docs/depend-for-closure.md +++ b/docs/depend-for-closure.md @@ -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: diff --git a/docs/depend-implementation.md b/docs/depend-implementation.md index 6380817bf..a8b2cd30e 100644 --- a/docs/depend-implementation.md +++ b/docs/depend-implementation.md @@ -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 diff --git a/src/OT/Var/VARC/VARC.cc b/src/OT/Var/VARC/VARC.cc index 390ad6f49..6c1611f0c 100644 --- a/src/OT/Var/VARC/VARC.cc +++ b/src/OT/Var/VARC/VARC.cc @@ -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); } diff --git a/src/OT/Var/VARC/VARC.hh b/src/OT/Var/VARC/VARC.hh index 17f0da3c0..20866ddaf 100644 --- a/src/OT/Var/VARC/VARC.hh +++ b/src/OT/Var/VARC/VARC.hh @@ -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 diff --git a/src/hb-depend-data.hh b/src/hb-depend-data.hh index 939e5c73b..db4157570 100644 --- a/src/hb-depend-data.hh +++ b/src/hb-depend-data.hh @@ -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 diff --git a/src/hb-depend.cc b/src/hb-depend.cc index 5c02e4966..697032766 100644 --- a/src/hb-depend.cc +++ b/src/hb-depend.cc @@ -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: diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index cdefb2682..e62156bf0 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -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 diff --git a/test/api/test-subset-varc.c b/test/api/test-subset-varc.c index a194ba192..621f61315 100644 --- a/test/api/test-subset-varc.c +++ b/test/api/test-subset-varc.c @@ -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);