From 9a5d99f8504decd66f047f0e265ea548370420f4 Mon Sep 17 00:00:00 2001 From: Skef Iterum Date: Thu, 23 Apr 2026 19:57:16 -0700 Subject: [PATCH] [depend] Address review feedback: preprocessor guards, minor API and naming fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace HB_DEPEND_API with HB_NO_SUBSET_DEPEND gated on HB_EXPERIMENTAL_API and HB_LEAN in hb-config.hh, with HB_SUBSET_DEPEND_API opt-in to allow enabling without full experimental API. Remove depend_api meson option; depend tests now build under experimental_api=true. Fold depend symbols into experimental symbols in gen-def.py. Internal fixes: use free_set_list.pop(), push_or_fail() for allocation safety, return const hb_set_t* from internal get_set_from_index. Ligature.hh: use hb_sink iterator, rename ligset→ligset_idx, source→gid. Remove stale test_depend_cmap unit test (cmap extraction was removed in d4d4c635). Co-Authored-By: Claude Sonnet 4.6 --- meson.build | 4 -- meson_options.txt | 2 - src/OT/Color/COLR/COLR.hh | 60 +++++++++---------- src/OT/Color/COLR/colrv1-depend.hh | 2 +- src/OT/Layout/GSUB/AlternateSet.hh | 2 +- src/OT/Layout/GSUB/AlternateSubstFormat1.hh | 2 +- src/OT/Layout/GSUB/Ligature.hh | 21 ++++--- src/OT/Layout/GSUB/LigatureSet.hh | 2 +- src/OT/Layout/GSUB/LigatureSubstFormat1.hh | 2 +- src/OT/Layout/GSUB/MultipleSubstFormat1.hh | 2 +- .../GSUB/ReverseChainSingleSubstFormat1.hh | 2 +- src/OT/Layout/GSUB/Sequence.hh | 2 +- src/OT/Layout/GSUB/SingleSubstFormat1.hh | 2 +- src/OT/Layout/GSUB/SingleSubstFormat2.hh | 2 +- src/OT/Layout/GSUB/SubstLookup.hh | 4 +- src/gen-def.py | 10 +--- src/hb-config.hh | 6 ++ src/hb-depend-data.hh | 28 ++++----- src/hb-depend.cc | 9 ++- src/hb-depend.h | 2 +- src/hb-depend.hh | 8 +-- src/hb-ot-layout-gsub-table.hh | 2 +- src/hb-ot-layout-gsubgpos.hh | 40 ++++++------- src/hb-ot-math-table.hh | 12 ++-- src/meson.build | 4 -- test/api/meson.build | 2 +- test/api/test-ot-depend.c | 42 +------------ test/fuzzing/hb-depend-closure-parity.cc | 8 +-- test/fuzzing/meson.build | 4 +- 29 files changed, 119 insertions(+), 169 deletions(-) diff --git a/meson.build b/meson.build index 910987c89..97ae4ce1b 100644 --- a/meson.build +++ b/meson.build @@ -273,10 +273,6 @@ if not get_option('subset').disabled() conf.set('HAVE_SUBSET', 1) endif -if get_option('depend_api') - conf.set('HB_DEPEND_API', 1) -endif - if freetype_dep.found() conf.set('HAVE_FREETYPE', 1) check_freetype_funcs = [ diff --git a/meson_options.txt b/meson_options.txt index 522e21389..3feffeab7 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -64,8 +64,6 @@ option('with_libstdcxx', type: 'boolean', value: false, description: 'Allow linking with libstdc++') option('experimental_api', type: 'boolean', value: false, description: 'Enable experimental APIs') -option('depend_api', type: 'boolean', value: false, - description: 'Enable dependency analysis APIs (highly experimental, API will change)') option('ragel_subproject', type: 'boolean', value: false, description: 'Build Ragel subproject if no suitable version is found') option('fuzzer_ldflags', type: 'string', diff --git a/src/OT/Color/COLR/COLR.hh b/src/OT/Color/COLR/COLR.hh index 06a22b193..1e2de4f7a 100644 --- a/src/OT/Color/COLR/COLR.hh +++ b/src/OT/Color/COLR/COLR.hh @@ -226,7 +226,7 @@ struct hb_colrv1_closure_context_t : {} }; -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND struct hb_colrv1_depend_context_t : hb_dispatch_context_t @@ -262,7 +262,7 @@ struct hb_colrv1_depend_context_t : source_gid (0) {} }; -#endif /* HB_DEPEND_API */ +#endif /* !HB_NO_SUBSET_DEPEND */ struct LayerRecord { @@ -325,7 +325,7 @@ struct Variable return_trace (c->embed (this)); } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void dependv1 (hb_colrv1_depend_context_t* c) const { value.dependv1 (c); } #endif @@ -405,7 +405,7 @@ struct NoVariable return_trace (c->embed (this)); } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void dependv1 (hb_colrv1_depend_context_t* c) const { value.dependv1 (c); } #endif @@ -453,7 +453,7 @@ struct NoVariable struct ColorStop { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void dependv1 (hb_colrv1_depend_context_t * c) const {} #endif @@ -519,7 +519,7 @@ struct Extend : HBUINT8 template class Var> struct ColorLine { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void dependv1 (hb_colrv1_depend_context_t * c) const { for (const auto &stop : stops.iter ()) @@ -672,7 +672,7 @@ struct Affine2x3 return_trace (c->check_struct (this)); } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void dependv1 (hb_colrv1_depend_context_t* c) const {} #endif @@ -722,7 +722,7 @@ struct Affine2x3 struct PaintColrLayers { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void dependv1 (hb_colrv1_depend_context_t* c) const; #endif void closurev1 (hb_colrv1_closure_context_t* c) const; @@ -756,7 +756,7 @@ struct PaintColrLayers struct PaintSolid { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void dependv1 (hb_colrv1_depend_context_t* c) const {} #endif void closurev1 (hb_colrv1_closure_context_t* c) const @@ -811,7 +811,7 @@ struct PaintSolid template class Var> struct PaintLinearGradient { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void dependv1 (hb_colrv1_depend_context_t* c) const { (this+colorLine).dependv1 (c); @@ -888,7 +888,7 @@ struct PaintLinearGradient template class Var> struct PaintRadialGradient { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void dependv1 (hb_colrv1_depend_context_t* c) const { (this+colorLine).dependv1 (c); @@ -965,7 +965,7 @@ struct PaintRadialGradient template class Var> struct PaintSweepGradient { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void dependv1 (hb_colrv1_depend_context_t* c) const { (this+colorLine).dependv1 (c); @@ -1036,7 +1036,7 @@ struct PaintSweepGradient // Paint a non-COLR glyph, filled as indicated by paint. struct PaintGlyph { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void dependv1 (hb_colrv1_depend_context_t* c) const; #endif void closurev1 (hb_colrv1_closure_context_t* c) const; @@ -1082,7 +1082,7 @@ struct PaintGlyph struct PaintColrGlyph { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void dependv1 (hb_colrv1_depend_context_t* c) const; #endif void closurev1 (hb_colrv1_closure_context_t* c) const; @@ -1115,7 +1115,7 @@ struct PaintColrGlyph template class Var> struct PaintTransform { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const; #endif HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const; @@ -1157,7 +1157,7 @@ struct PaintTransform struct PaintTranslate { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const; #endif HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const; @@ -1209,7 +1209,7 @@ struct PaintTranslate struct PaintScale { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const; #endif HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const; @@ -1261,7 +1261,7 @@ struct PaintScale struct PaintScaleAroundCenter { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const; #endif HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const; @@ -1319,7 +1319,7 @@ struct PaintScaleAroundCenter struct PaintScaleUniform { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const; #endif HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const; @@ -1366,7 +1366,7 @@ struct PaintScaleUniform struct PaintScaleUniformAroundCenter { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const; #endif HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const; @@ -1421,7 +1421,7 @@ struct PaintScaleUniformAroundCenter struct PaintRotate { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const; #endif HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const; @@ -1468,7 +1468,7 @@ struct PaintRotate struct PaintRotateAroundCenter { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const; #endif HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const; @@ -1523,7 +1523,7 @@ struct PaintRotateAroundCenter struct PaintSkew { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const; #endif HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const; @@ -1575,7 +1575,7 @@ struct PaintSkew struct PaintSkewAroundCenter { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const; #endif HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const; @@ -1633,7 +1633,7 @@ struct PaintSkewAroundCenter struct PaintComposite { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void dependv1 (hb_colrv1_depend_context_t* c) const; #endif void closurev1 (hb_colrv1_closure_context_t* c) const; @@ -1746,7 +1746,7 @@ struct ClipBoxFormat2 : Variable } } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void dependv1 (hb_colrv1_depend_context_t* c) const; #endif void closurev1 (hb_colrv1_closure_context_t* c) const @@ -1766,7 +1766,7 @@ struct ClipBox } } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void dependv1 (hb_colrv1_depend_context_t* c) const { switch (u.format.v) { @@ -1831,7 +1831,7 @@ struct ClipRecord int cmp (hb_codepoint_t g) const { return g < startGlyphID ? -1 : g <= endGlyphID ? 0 : +1; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void dependv1 (hb_colrv1_depend_context_t* c, const void *base) const { (base+clipBox).dependv1 (c); @@ -2335,7 +2335,7 @@ struct COLR bool is_valid () { return colr.get_blob ()->length; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void depend (hb_depend_data_t *depend_data) const { colr->depend (depend_data); } #endif @@ -2401,7 +2401,7 @@ struct COLR mutable hb_atomic_t cached_scratch; }; -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void depend (hb_depend_data_t *depend_data) const { // v0 diff --git a/src/OT/Color/COLR/colrv1-depend.hh b/src/OT/Color/COLR/colrv1-depend.hh index 696bbf15e..17ada53f2 100644 --- a/src/OT/Color/COLR/colrv1-depend.hh +++ b/src/OT/Color/COLR/colrv1-depend.hh @@ -35,7 +35,7 @@ */ namespace OT { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND HB_INTERNAL void PaintColrLayers::dependv1 (hb_colrv1_depend_context_t* c) const { diff --git a/src/OT/Layout/GSUB/AlternateSet.hh b/src/OT/Layout/GSUB/AlternateSet.hh index 09a8960e3..5009ef416 100644 --- a/src/OT/Layout/GSUB/AlternateSet.hh +++ b/src/OT/Layout/GSUB/AlternateSet.hh @@ -29,7 +29,7 @@ struct AlternateSet void closure (hb_closure_context_t *c) const { c->output->add_array (alternates.arrayZ, alternates.len); } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void depend (hb_depend_context_t *c, hb_codepoint_t source) const { + hb_iter (alternates) diff --git a/src/OT/Layout/GSUB/AlternateSubstFormat1.hh b/src/OT/Layout/GSUB/AlternateSubstFormat1.hh index eaac2e5e0..e8088f71e 100644 --- a/src/OT/Layout/GSUB/AlternateSubstFormat1.hh +++ b/src/OT/Layout/GSUB/AlternateSubstFormat1.hh @@ -34,7 +34,7 @@ struct AlternateSubstFormat1_2 bool may_have_non_1to1 () const { return false; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND bool depend (hb_depend_context_t *c) const { // Filter by parent_active_glyphs like closure does diff --git a/src/OT/Layout/GSUB/Ligature.hh b/src/OT/Layout/GSUB/Ligature.hh index c0fa2818f..11a5c549c 100644 --- a/src/OT/Layout/GSUB/Ligature.hh +++ b/src/OT/Layout/GSUB/Ligature.hh @@ -38,34 +38,33 @@ struct Ligature c->output->add (ligGlyph); } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void depend (hb_depend_context_t *c, hb_codepoint_t first) const { // Build the complete ligature set upfront before adding any edges hb_set_t complete_ligset; - complete_ligset.add(first); - for (const auto &source : component) - complete_ligset.add(source); + complete_ligset.add (first); + + hb_iter (component) | hb_sink (complete_ligset); - hb_codepoint_t ligset = c->depend_data->new_ligature_set(complete_ligset); + hb_codepoint_t ligset_idx = c->depend_data->new_ligature_set(complete_ligset); - // Track whether any edge using this ligset was actually added + // Track whether any edge using this ligset_idx was actually added bool any_added = false; // Now add all edges with the complete, immutable set - if (c->depend_data->add_gsub_lookup (first, c->lookup_index, ligGlyph, ligset)) + if (c->depend_data->add_gsub_lookup (first, c->lookup_index, ligGlyph, ligset_idx)) any_added = true; + hb_iter (component) - | hb_apply ([&] (const hb_codepoint_t &source) { - if (c->depend_data->add_gsub_lookup (source, c->lookup_index, ligGlyph, ligset)) + | hb_apply ([&] (const hb_codepoint_t &gid) { + if (c->depend_data->add_gsub_lookup (gid, c->lookup_index, ligGlyph, ligset_idx)) any_added = true; }) ; - // If no edges were added, the ligset is unused - free it for reuse + // If no edges were added, the ligset_idx is unused - free it for reuse if (!any_added) - c->depend_data->free_ligature_set(ligset); + c->depend_data->free_ligature_set(ligset_idx); } #endif diff --git a/src/OT/Layout/GSUB/LigatureSet.hh b/src/OT/Layout/GSUB/LigatureSet.hh index b81aa21d8..305c5b668 100644 --- a/src/OT/Layout/GSUB/LigatureSet.hh +++ b/src/OT/Layout/GSUB/LigatureSet.hh @@ -54,7 +54,7 @@ struct LigatureSet ; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void depend (hb_depend_context_t *c, hb_codepoint_t first) const { + hb_iter (ligature) diff --git a/src/OT/Layout/GSUB/LigatureSubstFormat1.hh b/src/OT/Layout/GSUB/LigatureSubstFormat1.hh index 568b6fd86..e45247f52 100644 --- a/src/OT/Layout/GSUB/LigatureSubstFormat1.hh +++ b/src/OT/Layout/GSUB/LigatureSubstFormat1.hh @@ -43,7 +43,7 @@ struct LigatureSubstFormat1_2 bool may_have_non_1to1 () const { return true; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND bool depend (hb_depend_context_t *c) const { + hb_zip (this+coverage, ligatureSet) diff --git a/src/OT/Layout/GSUB/MultipleSubstFormat1.hh b/src/OT/Layout/GSUB/MultipleSubstFormat1.hh index 046b6c345..b0eed2d5c 100644 --- a/src/OT/Layout/GSUB/MultipleSubstFormat1.hh +++ b/src/OT/Layout/GSUB/MultipleSubstFormat1.hh @@ -44,7 +44,7 @@ struct MultipleSubstFormat1_2 ; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND bool depend (hb_depend_context_t *c) const { // Filter by parent_active_glyphs like closure does diff --git a/src/OT/Layout/GSUB/ReverseChainSingleSubstFormat1.hh b/src/OT/Layout/GSUB/ReverseChainSingleSubstFormat1.hh index 4be50c46a..ceff125e4 100644 --- a/src/OT/Layout/GSUB/ReverseChainSingleSubstFormat1.hh +++ b/src/OT/Layout/GSUB/ReverseChainSingleSubstFormat1.hh @@ -67,7 +67,7 @@ struct ReverseChainSingleSubstFormat1 bool may_have_non_1to1 () const { return false; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND bool depend (hb_depend_context_t *c) const { // Filter by intersects and parent_active_glyphs like closure does (lines 83-95) if (!intersects (c->glyphs)) return true; diff --git a/src/OT/Layout/GSUB/Sequence.hh b/src/OT/Layout/GSUB/Sequence.hh index 5f32b1d74..c3c8d4df2 100644 --- a/src/OT/Layout/GSUB/Sequence.hh +++ b/src/OT/Layout/GSUB/Sequence.hh @@ -28,7 +28,7 @@ struct Sequence void closure (hb_closure_context_t *c) const { c->output->add_array (substitute.arrayZ, substitute.len); } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void depend (hb_depend_context_t *c, hb_codepoint_t source) const { + hb_iter (substitute) diff --git a/src/OT/Layout/GSUB/SingleSubstFormat1.hh b/src/OT/Layout/GSUB/SingleSubstFormat1.hh index 077b0d12d..c18d76763 100644 --- a/src/OT/Layout/GSUB/SingleSubstFormat1.hh +++ b/src/OT/Layout/GSUB/SingleSubstFormat1.hh @@ -45,7 +45,7 @@ struct SingleSubstFormat1_3 bool may_have_non_1to1 () const { return false; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND bool depend (hb_depend_context_t *c) const { hb_codepoint_t d = deltaGlyphID; diff --git a/src/OT/Layout/GSUB/SingleSubstFormat2.hh b/src/OT/Layout/GSUB/SingleSubstFormat2.hh index fff3590f1..329a42906 100644 --- a/src/OT/Layout/GSUB/SingleSubstFormat2.hh +++ b/src/OT/Layout/GSUB/SingleSubstFormat2.hh @@ -34,7 +34,7 @@ struct SingleSubstFormat2_4 bool may_have_non_1to1 () const { return false; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND bool depend (hb_depend_context_t *c) const { auto &cov = this+coverage; diff --git a/src/OT/Layout/GSUB/SubstLookup.hh b/src/OT/Layout/GSUB/SubstLookup.hh index a7348ef9e..53a451580 100644 --- a/src/OT/Layout/GSUB/SubstLookup.hh +++ b/src/OT/Layout/GSUB/SubstLookup.hh @@ -61,7 +61,7 @@ struct SubstLookup : Lookup return ret; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND hb_depend_context_t::return_t depend (hb_depend_context_t *c) const { c->set_recurse_func (dispatch_depend_recurse_func); @@ -213,7 +213,7 @@ struct SubstLookup : Lookup return ret; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND static inline typename hb_depend_context_t::return_t depend_glyphs_recurse_func (hb_depend_context_t *c, unsigned lookup_index, hb_set_t *covered_seq_indices, unsigned seq_index, unsigned end_index); static inline hb_depend_context_t::return_t dispatch_depend_recurse_func (hb_depend_context_t *c, unsigned lookup_index, hb_set_t *covered_seq_indices, unsigned seq_index, unsigned end_index) diff --git a/src/gen-def.py b/src/gen-def.py index 29f31ec11..5e4e6fafe 100755 --- a/src/gen-def.py +++ b/src/gen-def.py @@ -25,19 +25,13 @@ hb_subset_cff_get_charstring_data hb_subset_cff_get_charstrings_index hb_subset_cff2_get_charstring_data hb_subset_cff2_get_charstrings_index -""".splitlines () - symbols = [x for x in symbols if x not in experimental_symbols] - -if '--depend-api' not in sys.argv: - # Depend API symbols - only included when depend_api=true - depend_symbols = \ -"""hb_depend_from_face_or_fail +hb_depend_from_face_or_fail hb_depend_get_glyph_entry hb_depend_get_set_from_index hb_depend_print hb_depend_destroy """.splitlines () - symbols = [x for x in symbols if x not in depend_symbols] + symbols = [x for x in symbols if x not in experimental_symbols] symbols = "\n".join (symbols) result = symbols if os.getenv ('PLAIN_LIST', '') else """EXPORTS diff --git a/src/hb-config.hh b/src/hb-config.hh index 677360bee..e7195e2ab 100644 --- a/src/hb-config.hh +++ b/src/hb-config.hh @@ -38,6 +38,11 @@ #ifndef HB_EXPERIMENTAL_API #define HB_NO_BEYOND_64K #define HB_NO_CUBIC_GLYF +#define HB_NO_SUBSET_DEPEND +#endif + +#ifdef HB_SUBSET_DEPEND_API +#undef HB_NO_SUBSET_DEPEND #endif #ifdef HB_TINY @@ -78,6 +83,7 @@ #define HB_NO_OT_FONT_GLYPH_NAMES #define HB_NO_SETLOCALE #define HB_NO_STYLE +#define HB_NO_SUBSET_DEPEND #define HB_NO_VERTICAL #define HB_NO_VAR diff --git a/src/hb-depend-data.hh b/src/hb-depend-data.hh index 9d6cf7efb..b91f383bc 100644 --- a/src/hb-depend-data.hh +++ b/src/hb-depend-data.hh @@ -31,7 +31,7 @@ #include "hb-multimap.hh" -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND /** * Edge flags for hb_depend_data_record_t. @@ -227,7 +227,7 @@ struct hb_lookup_feature_record_t { struct hb_depend_data_t { hb_depend_data_t () -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND : current_context_set_index (HB_CODEPOINT_INVALID), current_edge_flags (0) #endif @@ -270,8 +270,7 @@ struct hb_depend_data_t if (free_set_list.length > 0) { /* Reuse freed set */ - set_index = free_set_list[free_set_list.length - 1]; - free_set_list.resize (free_set_list.length - 1); + set_index = free_set_list.pop (); sets[set_index]->set (set); } else @@ -282,7 +281,8 @@ struct hb_depend_data_t if (unlikely (!new_set)) return HB_CODEPOINT_INVALID; new_set->set (set); - sets.push (hb::unique_ptr {new_set}); + if (unlikely (!sets.push_or_fail (hb::unique_ptr {new_set}))) + return HB_CODEPOINT_INVALID; } return set_index; @@ -315,7 +315,7 @@ struct hb_depend_data_t return new_idx; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND /* Build a context set from context information. * Encodes backtrack and lookahead requirements as a flattened set. * Returns HB_CODEPOINT_INVALID if no context. @@ -454,13 +454,11 @@ struct hb_depend_data_t return false; } - bool get_set_from_index(hb_codepoint_t index, hb_set_t *out) + const hb_set_t *get_set_from_index (hb_codepoint_t index) { - if (index < sets.length) { - out->set(*sets[index]); - return true; - } - return false; + if (index < sets.length) + return sets[index].get (); + return nullptr; } bool add_depend_layout (hb_codepoint_t target, hb_tag_t table_tag, @@ -495,7 +493,7 @@ struct hb_depend_data_t hb_codepoint_t lig_set = HB_CODEPOINT_INVALID, hb_codepoint_t context_set = HB_CODEPOINT_INVALID) { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND /* Use pre-computed context set index for the current rule */ if (context_set == HB_CODEPOINT_INVALID) context_set = current_context_set_index; @@ -548,7 +546,7 @@ struct hb_depend_data_t /* Edge deduplication: struct-based hashing via edge_key_t */ hb_hashmap_t seen_edges; -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND /* Temporary: Context set index for the current rule. * Built once per rule by context_depend_lookup/chain_context_depend_lookup, * then used by all edges recorded from nested lookups. */ @@ -562,6 +560,6 @@ struct hb_depend_data_t #endif }; -#endif /* HB_DEPEND_API */ +#endif /* !HB_NO_SUBSET_DEPEND */ #endif /* HB_DEPEND_DATA_HH */ diff --git a/src/hb-depend.cc b/src/hb-depend.cc index f5f1dbca6..eae4e1ec2 100644 --- a/src/hb-depend.cc +++ b/src/hb-depend.cc @@ -37,7 +37,7 @@ #include "OT/Color/COLR/COLR.hh" #include "OT/Color/COLR/colrv1-depend.hh" -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND /** * SECTION:hb-depend @@ -387,7 +387,10 @@ hb_depend_get_glyph_entry(hb_depend_t *depend, hb_codepoint_t gid, hb_bool_t hb_depend_get_set_from_index(hb_depend_t *depend, hb_codepoint_t index, hb_set_t *out) { - return depend->get_set_from_index(index, out); + const hb_set_t *s = depend->get_set_from_index (index); + if (!s) return false; + out->set (*s); + return true; } /** @@ -428,4 +431,4 @@ hb_depend_destroy (hb_depend_t *depend) hb_free (depend); } -#endif /* HB_DEPEND_API */ +#endif /* !HB_NO_SUBSET_DEPEND */ diff --git a/src/hb-depend.h b/src/hb-depend.h index 664eec960..32937f82a 100644 --- a/src/hb-depend.h +++ b/src/hb-depend.h @@ -34,7 +34,7 @@ HB_BEGIN_DECLS -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND /** * hb_depend_t: diff --git a/src/hb-depend.hh b/src/hb-depend.hh index 3c7b59c1d..8df3c1bad 100644 --- a/src/hb-depend.hh +++ b/src/hb-depend.hh @@ -32,7 +32,7 @@ #include "hb-depend.h" #include "hb-depend-data.hh" -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND /** * hb_depend_t: @@ -72,9 +72,9 @@ struct hb_depend_t return data.get_glyph_entry(gid, index, table_tag, dependent, layout_tag, ligature_set, context_set, flags); } - bool get_set_from_index(hb_codepoint_t index, hb_set_t *out) + const hb_set_t *get_set_from_index (hb_codepoint_t index) { - return data.get_set_from_index(index, out); + return data.get_set_from_index (index); } HB_INTERNAL void get_gsub_dependencies (); @@ -88,6 +88,6 @@ struct hb_depend_t hb_depend_data_t data; }; -#endif /* HB_DEPEND_API */ +#endif /* !HB_NO_SUBSET_DEPEND */ #endif /* HB_DEPEND_HH */ diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index 7e36ead07..7644210ba 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -58,7 +58,7 @@ template return l.dispatch (c); } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND /*static*/ typename hb_depend_context_t::return_t SubstLookup::depend_glyphs_recurse_func (hb_depend_context_t *c, unsigned lookup_index, hb_set_t *covered_seq_indices, unsigned seq_index, unsigned end_index) { const SubstLookup &l = c->face->table.GSUB.get_relaxed ()->table->get_lookup (lookup_index); diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 813fc13db..5474812cc 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -376,7 +376,7 @@ struct hb_collect_glyphs_context_t : void set_recurse_func (recurse_func_t func) { recurse_func = func; } }; -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND struct hb_depend_context_t : hb_dispatch_context_t { @@ -1895,7 +1895,7 @@ static void context_closure_recurse_lookups (hb_closure_context_t *c, } } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND template static void context_depend_recurse_lookups (hb_depend_context_t *c, unsigned inputCount, const HBUINT input[], @@ -1954,15 +1954,15 @@ static void context_depend_recurse_lookups (hb_depend_context_t *c, elem = HB_SET_VALUE_INVALID; while (disjunctive_indices.next (&elem)) { hb_codepoint_t set_idx = elem & 0x7FFFFFFF; - hb_set_t original_set; - c->depend_data->get_set_from_index (set_idx, &original_set); + const hb_set_t *original_set = c->depend_data->get_set_from_index (set_idx); + if (unlikely (!original_set)) continue; /* Make local copy and subtract direct requirements */ hb_set_t filtered; - filtered.set (original_set); + filtered.set (*original_set); filtered.subtract (position_context); - if (filtered == original_set) { + if (filtered == *original_set) { /* No overlap with position_context - add full requirement */ filtered_disjunctive_indices.add (elem); } @@ -2251,7 +2251,7 @@ struct ContextClosureLookupContext void *intersected_glyphs_cache; }; -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND struct ContextDependLookupContext { ContextClosureFuncs funcs; @@ -2309,7 +2309,7 @@ static inline void context_closure_lookup (hb_closure_context_t *c, lookup_context.intersected_glyphs_cache); } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND template static inline void context_depend_lookup (hb_depend_context_t *c, unsigned int inputCount, /* Including the first glyph (not matched) */ @@ -2487,7 +2487,7 @@ struct Rule lookup_context); } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void depend (hb_depend_context_t *c, unsigned value, ContextDependLookupContext &lookup_context) const { const auto &lookupRecord = StructAfter> @@ -2632,7 +2632,7 @@ struct RuleSet ; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void depend (hb_depend_context_t *c, unsigned value, ContextDependLookupContext &lookup_context) const { + hb_iter (rule) @@ -2882,7 +2882,7 @@ struct ContextFormat1_4 bool may_have_non_1to1 () const { return true; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND bool depend (hb_depend_context_t *c) const { hb_set_t* cur_active_glyphs = c->push_cur_active_glyphs (); @@ -3079,7 +3079,7 @@ struct ContextFormat2_5 bool may_have_non_1to1 () const { return true; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND bool depend (hb_depend_context_t *c) const { if (!(this+coverage).intersects (c->glyphs)) @@ -3358,7 +3358,7 @@ struct ContextFormat3 bool may_have_non_1to1 () const { return true; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND bool depend (hb_depend_context_t *c) const { if (!(this+coverageZ[0]).intersects (c->glyphs)) @@ -3566,7 +3566,7 @@ struct ChainContextClosureLookupContext void *intersected_glyphs_cache; }; -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND struct ChainContextDependLookupContext { ContextClosureFuncs funcs; @@ -3646,7 +3646,7 @@ static inline void chain_context_closure_lookup (hb_closure_context_t *c, lookup_context.intersected_glyphs_cache); } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND template static inline void chain_context_depend_lookup (hb_depend_context_t *c, unsigned int backtrackCount, @@ -3900,7 +3900,7 @@ struct ChainRule lookup_context); } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void depend (hb_depend_context_t *c, unsigned value, ChainContextDependLookupContext &lookup_context) const { const auto &input = StructAfter (backtrack); @@ -4110,7 +4110,7 @@ struct ChainRuleSet | hb_any ; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void depend (hb_depend_context_t *c, unsigned value, ChainContextDependLookupContext &lookup_context) const { + hb_iter (rule) @@ -4381,7 +4381,7 @@ struct ChainContextFormat1_4 bool may_have_non_1to1 () const { return true; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND bool depend (hb_depend_context_t *c) const { hb_set_t* cur_active_glyphs = c->push_cur_active_glyphs (); @@ -4580,7 +4580,7 @@ struct ChainContextFormat2_5 bool may_have_non_1to1 () const { return true; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND bool depend (hb_depend_context_t *c) const { if (!(this+coverage).intersects (c->glyphs)) @@ -4920,7 +4920,7 @@ struct ChainContextFormat3 bool may_have_non_1to1 () const { return true; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND bool depend (hb_depend_context_t *c) const { const auto &input = StructAfter (backtrack); diff --git a/src/hb-ot-math-table.hh b/src/hb-ot-math-table.hh index 875cfd766..80dd954f8 100644 --- a/src/hb-ot-math-table.hh +++ b/src/hb-ot-math-table.hh @@ -663,7 +663,7 @@ struct MathGlyphVariantRecord return_trace (c->check_struct (this)); } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void depend (hb_depend_data_t *depend_data, unsigned source) const { depend_data->add_depend(source, HB_OT_TAG_MATH, variantGlyph); } #endif @@ -729,7 +729,7 @@ struct MathGlyphPartRecord (partFlags & PartFlags::Defined); } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void depend (hb_depend_data_t *depend_data, unsigned source) const { depend_data->add_depend(source, HB_OT_TAG_MATH, glyph); } #endif @@ -801,7 +801,7 @@ struct MathGlyphAssembly return partRecords.len; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void depend (hb_depend_data_t *depend_data, unsigned source) const { for (const auto& _ : partRecords.iter ()) @@ -874,7 +874,7 @@ struct MathGlyphConstruction return mathGlyphVariantRecord.len; } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void depend (hb_depend_data_t *depend_data, unsigned source) const { (this+glyphAssembly).depend (depend_data, source); @@ -906,7 +906,7 @@ struct MathGlyphConstruction struct MathVariants { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void depend (hb_depend_data_t *depend_data) const { const hb_array_t> glyph_construction_offsets = glyphConstruction.as_array (vertGlyphCount + horizGlyphCount); @@ -1132,7 +1132,7 @@ struct MATH bool has_data () const { return version.to_int (); } -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND void depend (hb_depend_data_t *depend_data) const { if (mathVariants) diff --git a/src/meson.build b/src/meson.build index e30febdf1..58b13f673 100644 --- a/src/meson.build +++ b/src/meson.build @@ -630,10 +630,6 @@ gen_def_cmd = [gen_def, '@OUTPUT@', '@INPUT@'] if get_option('experimental_api') gen_def_cmd += '--experimental-api' endif -if get_option('depend_api') - gen_def_cmd += '--depend-api' -endif - # harfbuzz harfbuzz_def = custom_target('harfbuzz.def', command: gen_def_cmd, diff --git a/test/api/meson.build b/test/api/meson.build index 7a177bda4..c42f1376a 100644 --- a/test/api/meson.build +++ b/test/api/meson.build @@ -92,7 +92,7 @@ if conf.get('HAVE_PTHREAD', 0) == 1 tests += 'test-multithread.c' endif -if conf.get('HB_DEPEND_API', 0) == 1 +if conf.get('HB_EXPERIMENTAL_API', 0) == 1 tests += 'test-ot-depend.c' endif diff --git a/test/api/test-ot-depend.c b/test/api/test-ot-depend.c index 4d98f971d..af6b0182a 100644 --- a/test/api/test-ot-depend.c +++ b/test/api/test-ot-depend.c @@ -27,7 +27,7 @@ #include #include -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND /* * ============================================================================ @@ -275,45 +275,6 @@ find_dependency (hb_depend_t *depend, return FALSE; } -/* Test cmap (character mapping) dependency extraction */ -static void -test_depend_cmap (void) -{ - /* ===== UNDERSTANDING cmap DEPENDENCIES ===== */ - /* - * IMPORTANT: Nominal cmap mappings (Unicode → glyph) are NOT stored as - * glyph→glyph dependencies. They're collected in a separate nominal_glyphs - * map for lookup purposes. - * - * Only Unicode Variation Sequences (UVS) with NonDefault mappings create - * glyph dependencies. The model is: - * - Unicode U nominally maps to glyph G - * - U + selector S → variant glyph V (NonDefault UVS) - * - This creates dependency: G depends on V with layout_tag=S - * - * Default UVS entries (where selector uses the nominal glyph) do NOT - * create dependencies. - */ - - /* ===== UNICODE VARIATION SEQUENCES (UVS) ===== */ - - /* base.ttf has NonDefault UVS entries: - * U+904D nominally maps to cid00007 (GID 7) - * U+904D + selector 0xE01E5 → cid00010 (GID 10) via NonDefault UVS - * This creates dependency: GID 7 → GID 10 with layout_tag=0xE01E5 */ - - hb_face_t *face = hb_test_open_font_file ("fonts/base.ttf"); - hb_depend_t *depend = hb_depend_from_face_or_fail (face); - g_assert_nonnull (depend); - - g_test_message ("Testing cmap NonDefault UVS: cid00007 (7) → cid00010 (10) with selector 0xE01E5"); - hb_tag_t layout_tag = 0xE01E5; /* UVS selector stored in layout_tag */ - g_assert_true (find_dependency (depend, 7, 10, HB_TAG('c','m','a','p'), - &layout_tag, NULL)); - - hb_depend_destroy (depend); - hb_face_destroy (face); -} /* Test glyf (composite glyph) dependency extraction */ static void @@ -637,7 +598,6 @@ main (int argc, char **argv) { hb_test_init (&argc, &argv); - hb_test_add (test_depend_cmap); hb_test_add (test_depend_glyf); hb_test_add (test_depend_cff); hb_test_add (test_depend_colr); diff --git a/test/fuzzing/hb-depend-closure-parity.cc b/test/fuzzing/hb-depend-closure-parity.cc index 1adba9330..c2f55147f 100644 --- a/test/fuzzing/hb-depend-closure-parity.cc +++ b/test/fuzzing/hb-depend-closure-parity.cc @@ -12,7 +12,7 @@ #include #include -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND #include /** @@ -1533,11 +1533,11 @@ compare_closures (hb_face_t *face, hb_depend_t *depend, return match; } -#endif /* HB_DEPEND_API */ +#endif /* !HB_NO_SUBSET_DEPEND */ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) { -#ifdef HB_DEPEND_API +#ifndef HB_NO_SUBSET_DEPEND alloc_state = _fuzzing_alloc_state (data, size); /* Initialize configuration on first run */ @@ -1735,7 +1735,7 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) hb_depend_destroy (depend); hb_face_destroy (face); hb_blob_destroy (blob); -#endif /* HB_DEPEND_API */ +#endif /* !HB_NO_SUBSET_DEPEND */ return 0; } diff --git a/test/fuzzing/meson.build b/test/fuzzing/meson.build index d97d85446..ef1b0c234 100644 --- a/test/fuzzing/meson.build +++ b/test/fuzzing/meson.build @@ -74,7 +74,7 @@ foreach file_name : tests endforeach # Build depend-related fuzzers only if depend_api is enabled -if conf.get('HB_DEPEND_API', 0) == 1 +if conf.get('HB_EXPERIMENTAL_API', 0) == 1 foreach file_name : depend_tests test_name = file_name.split('.')[0] @@ -227,7 +227,7 @@ if not get_option('subset').disabled() endforeach endif -if conf.get('HB_DEPEND_API', 0) == 1 +if conf.get('HB_EXPERIMENTAL_API', 0) == 1 i = 0 foreach chunk : api_fonts_glob_chunks test('depend-closure-parity-chunk-@0@'.format(i),