gtk-doc couldn't find the HB_SUBSET_DEPEND_EDGE_FLAG_* enum constants
because they were wrapped in #ifndef HB_SUBSET_DEPEND_EDGE_FLAGS_T_DEFINED.
The guard exists so that the duplicate definition in hb-depend-data.hh
(for internal code) doesn't conflict.
Fix: remove the #ifndef/#endif around the typedef in the public header
and place the #define after it. gtk-doc now sees the unguarded typedef;
hb-depend-data.hh's guarded copy is still suppressed when both headers
are included in the same TU.
Also add /*< flags >*/ gtk-doc annotation to the enum.
Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
In context_depend_lookup and chain_context_depend_lookup, the
ClassBasedContext case at position 0 collected all class members
via collect_class without intersecting with the coverage. For a
ContextSubst/ChainContextSubst to fire, the first glyph must be
in BOTH the class AND the coverage. Class members outside the
coverage can never trigger the rule, so their edges are spurious.
Fix: intersect pos0_glyphs with parent_active_glyphs (which the
ContextFormat2/ChainContextFormat2 caller sets to coverage ∩ glyphs)
after collecting class members.
Found via parity checker testing with AOTS font classdef1_font3.otf
(ContextSubst format 2 with coverage smaller than class membership).
Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
SingleSubstFormat1 applies (glyph + delta) mod mask, which can wrap
to glyph IDs beyond num_glyphs. The closure code produces these too,
but the subsetter later removes them via _remove_invalid_gids. The
depend graph should never contain edges to non-existent glyphs, so
filter them at the source.
Reproducer: test/shape/data/aots/fonts/gsub1_1_modulo_f1.otf
(delta wraps all four covered glyphs past num_glyphs=100)
Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
hb_depend_context_t::recurse had no cycle detection, unlike the
closure and closure_lookups contexts which use nesting_level_left
and visited_lookups guards respectively. A font with a
ChainContextSubst lookup that references itself (or an indirect
cycle A→B→A) caused infinite recursion and a stack overflow crash
in the parity checker.
Fix: use call-stack semantics on the existing lookups_seen field —
add the lookup index on entry to recurse(), remove it on exit.
This blocks re-entry of any lookup currently on the execution
stack while allowing the same lookup to appear again once it has
returned (necessary for rules that iterate over multiple sequence
positions sequentially).
Cutting a cycle is safe because the active glyph set can only stay
the same or shrink as we recurse deeper. Any edges a re-entry
would add are a subset of what the lookup is already registering
on its current (broader-context) call.
Also seed lookups_seen with the top-level lookup index before the
direct depend() call in GSUB_accelerator_t::depend, so that
indirect cycles of the form A→B→A are caught inside recurse().
Reproducer: test/subset/data/fonts/gsub_chaining1_multiple_subrules_f1.otf
(lookup 0 is a ChainContextSubst format 1 that references itself)
Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
hb-depend.cc was added to hb_subset_sources in meson.build when the
depend API landed, but harfbuzz-world.cc (generated from
harfbuzz-world.cc.in via gen-harfbuzz-world.py) was not regenerated
and committed at that time.
Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Split the former "test generation infrastructure" section into three
labelled subsections:
- Random sampling utilities (rng_range / rng_select_distinct / rng_select_from_set)
- Font and input queries (get_gsub_features / parse_unicodes / parse_gids / parse_features)
- Test parameter generation (test_params / generate_test_from_explicit / generate_test_from_seed)
get_gsub_features was previously stranded between the RNG helpers and the
parsers; the new header makes clear it belongs with the input queries.
No logic changes.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Reorder the file so a reader encounters code in the order they need to
understand it:
1. Overview comment explaining the two-closure comparison approach
2. Configuration globals and init_parity_config()
3. Closure algorithm (depend side): deferred_ligature_t, depend_closure_ctx_t,
check_context_satisfied, process_edges_for_tables, compute_depend_closure
4. Closure algorithm (subset side): compute_subset_closure
5. Comparison and reporting: print_test_params, compare_closures
6. Test generation infrastructure: rng helpers, get_gsub_features,
parse_unicodes/gids/features, test_params, generate_test_from_*
7. LLVMFuzzerTestOneInput
Previously the test generation infrastructure (hundreds of lines of seed and
parser code) appeared before the parity checking logic, forcing a reader to
hold a lot of context before seeing what the file was for. The forward
declaration of get_gsub_features() is also removed since it now precedes
parse_features(). No logic changes.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add `rng_prob_hit()` helper to replace three repeated injection-check
patterns, each of which was 4–6 lines of std::uniform_real_distribution
boilerplate.
- Add `depend_closure_ctx_t` struct to group the parameters that were
threaded individually through `process_edges_for_tables` (10 params)
and `compute_depend_closure` (9 params); both now take 2–3 params.
- Remove dead `vs_to_gid` map that was created, passed through three
call layers, and never read.
- Fix GSUB-stage indentation in `compute_depend_closure`: the old code
had a spurious outer `{ }` block containing all five table stages,
with the `if (!skip_gsub)` body indented at the wrong level.
- Move `ligature_set_glyphs` into the GSUB stage block where it belongs.
No behaviour change; all tests pass.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
VARC closure and subsetting are not yet implemented in hb-subset-plan.cc,
so the right traversal architecture for VarComponent records hasn't been
established. Adding depend() for VARC in isolation risks being redone when
closure is implemented. Defer to the same commit that adds VARC closure.
Note: component conditions should be treated as over-approximations
(include all components regardless), consistent with FeatureVariations.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- ContextDependLookupContext / ChainContextDependLookupContext: replace
duplicate struct definitions with typedefs of their Closure counterparts,
removing the now-unnecessary reinterpret_casts and layout-identity comments
- test/fuzzing/meson.build: switch depend-closure-parity from api_fonts_glob
to subset_fonts_glob; remove api_fonts_glob (the fuzzer produces malformed
fonts anyway, per behdad review)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- hb_subset_depend_t: drop face field; only needed during construction
- hb-ot-cmap-table.hh: remove stale hb-depend-data.hh include (cmap depend was removed)
- hb-ot-layout-gsubgpos.hh: clarify dispatch return type; use push_or_fail() in push_cur_active_glyphs()
- docs/harfbuzz-docs.xml: remove premature api-index-12-4-0 entry (added at release time)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add uninstalled util/hb-subset-depend that prints the glyph dependency
graph for a font. Supports filtering by GID range (--gids), showing only
flagged edges (--flagged), suppressing context output (--no-context), and
using numeric IDs instead of glyph names (--no-glyph-names). Registered
in util/meson.build under experimental_api + subset guards.
Also fix a bug in hb_subset_depend_lookup_glyph where the flags field of
hb_subset_depend_entry_t (a 4-byte enum) was written via a uint8_t*,
leaving the upper 3 bytes uninitialized. Use a local uint8_t variable and
assign it properly to entries[i].flags.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Update all doc files to reflect the hb_subset_depend_* rename, the
removal of print from the public API, the new struct-based entry type,
the array-getter signature for lookup_glyph, and the switch from the
old depend_api/HB_DEPEND_API build controls to experimental_api /
HB_NO_SUBSET_DEPEND / HB_SUBSET_DEPEND_API.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Follows HarfBuzz convention: return total count, take start_offset +
entry_count IN/OUT + entries array. This allows callers to query the
total without filling, page through entries, or fetch all at once.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Rename all public symbols hb_depend_* → hb_subset_depend_*
- Rename hb_depend_t → hb_subset_depend_t
- Replace get_glyph_entry (multi out-param) with lookup_glyph (fills
hb_subset_depend_entry_t struct; fields use ligature_set_index /
context_set_index)
- Rename get_set_from_index → lookup_set
- Remove hb_depend_print from public API (util/hb-subset-depend TODO)
- Move hb_subset_depend_edge_flags_t to hb-depend.h; apply
HB_MARK_AS_FLAG_T in hb-depend-data.hh (internal header only, since
hb-algs.hh is not available in public headers)
- Rename HB_DEPEND_EDGE_FLAG_* → HB_SUBSET_DEPEND_EDGE_FLAG_*
- Update gen-def.py, check-symbols.py, and all test callers
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove HB_NO_SUBSET_DEPEND guards from all internal implementation:
hb-depend-data.hh, hb-depend.hh, table depend() methods in COLR, GSUB,
glyf, CFF, MATH, and gsubgpos. The guard is now kept only around the
public hb_depend_* C API functions in hb-depend.cc (and hb-depend.h).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Switch hb_colrv1_depend_context_t from bool-returning to void-style
dispatch (matching closure context pattern)
- Replace const void *base with const COLR *colr (typed, no reinterpret_cast)
- Empty gradient dependv1 methods (ColorLine/ColorStop hold palette indices,
not glyph IDs)
- Remove dead clip dependv1 code (ClipRecord/ClipBox/ClipBoxFormat2 never
called from COLR::depend())
- Add HB_INTERNAL to out-of-class dependv1/closurev1 declarations for
PaintColrLayers, PaintGlyph, PaintColrGlyph, PaintComposite
- Remove no-op (this+transform).dependv1(c) from PaintTransform::dependv1
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add GSUB_accelerator_t::depend() to GSUB.hh (declaration) and
hb-ot-layout-gsub-table.hh (inline definition), so per-table depend
logic lives alongside the table code per review feedback.
In compile(), use hb_ot_layout_has_substitution() to force GSUB
lazy-loader initialization via libharfbuzz, then access the already-
constructed accelerator via get_relaxed(). This avoids instantiating
the GSUB_accelerator_t constructor (which references the hidden
is_blocklisted symbol) in hb-depend.cc.o.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add depend(hb_depend_data_builder_t *) to glyf_accelerator_t and
cff1_subset_accelerator_t. COLR::accelerator_t::depend gains a has_data()
guard. compile() now calls face->table.MATH/COLR/glyf directly; CFF uses
a temporary cff1_subset_accelerator_t since get_seac_components is on the
subset accelerator. Removes four get_*_dependencies wrappers from
hb_depend_data_builder_t.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
hb_depend_context_t switches to hb_dispatch_context_t<hb_depend_context_t>
(void-style, return_t = hb_empty_t). All bool depend() methods in gsubgpos.hh
and GSUB subtype files become void, matching the closure convention. Recurse
functions retain hb_depend_context_t::return_t signatures (= hb_empty_t) to
satisfy the recurse_func_t typedef, consistent with the closure pattern.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove nullptr check in hb_depend_t constructor per HarfBuzz convention
(crashing on null is fine). Convert HB_DEPEND_EDGE_FLAG_* #defines to
an hb_depend_edge_flags_t enum with HB_MARK_AS_FLAG_T, updating all
flag fields and parameters to use the enum type. Add
HB_DEPEND_CONTEXT_SET_FLAG for the 0x80000000 sentinel that marks
set-index references in context element sets; replace all raw literals
across depend-data.hh, gsubgpos.hh, and ReverseChain. Remove stale line
number reference from a comment in ReverseChain.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Following the hb_ot_map_builder_t pattern, add a compile(face) method to
the builder that owns all per-table dependency extraction. The five
get_*_dependencies() methods move from hb_depend_t to the builder, taking
face as a parameter rather than using hb_depend_t members. The builder
now tracks its own success state and returns it from compile().
hb_depend_t::hb_depend_t() simplifies to a single compile() call after
setup, and hb_depend_t loses the features set (now a local in
get_gsub_dependencies) and the five method declarations.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Split hb_depend_data_t into a slim query-time struct and a temporary
hb_depend_data_builder_t following the hb_ot_map_t/hb_ot_map_builder_t
pattern. The builder holds all construction state (lookup_features,
seen_edges, set_to_index, etc.) and is scoped within the hb_depend_t
constructor, freeing that state once the graph is built.
Also rename internal types to follow HarfBuzz conventions:
hb_depend_data_record_t -> hb_depend_edge_t
edge_key_t -> hb_depend_edge_key_t
hb_glyph_depend_record_t -> hb_depend_glyph_record_t
hb_lookup_feature_record_t -> hb_depend_lookup_revmap_t
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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 <noreply@anthropic.com>
Replace bare assert(blob) with a proper error message when
hb_blob_create_from_file_or_fail returns NULL. This gives users
a clear indication of which file couldn't be loaded instead of
a cryptic assertion failure.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
With UVS (Unicode Variation Sequence) closure now handled directly via
hb_font_get_variation_glyph() query API, the cmap depend extraction code
is no longer needed. This commit removes all cmap-related depend code:
Code removals:
- src/hb-depend.cc: Remove get_cmap_dependencies() function
- src/hb-depend.hh: Remove get_cmap_dependencies() declaration
- src/hb-ot-cmap-table.hh: Remove 4 depend() methods (NonDefaultUVS,
VariationSelectorRecord, CmapSubtableFormat14, cmap)
Documentation updates:
- docs/depend-api.md: Remove cmap from table list, add UVS note
- docs/depend-for-closure.md: Update closure steps, reference impl notes
- docs/depend-implementation.md: Update table list in Future Considerations
The old cmap depend code only extracted format 14 (UVS) edges, so removing
it does not affect fonts without UVS mappings.
Testing: 153 fonts in test/api/fonts (10k iterations each), 10 fonts with
UVS mappings (1M iterations each) - all pass.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
UVS (Unicode Variation Sequence) edges in the depend graph couldn't
properly represent the filtering requirement that BOTH the base unicode
AND variation selector must be in the input unicodes. This caused
over-approximation in depend closure vs subset closure.
Solution: Handle UVS separately using existing query APIs
- Skip all cmap edges during depend closure processing
- Use hb_font_get_variation_glyph() to query UVS mappings directly
- For GSUB tests: Use input codepoints directly for UVS queries
- For non-GSUB tests: Build unicodes from starting glyphs via forward
cmap iteration (hb_face_collect_nominal_glyph_mapping)
This correctly matches subset's UVS handling while keeping the depend
graph focused on non-UVS dependencies.
Also fixes -t parameter to support full 64-bit test seeds by parsing
as string before converting to uint64_t.
Test results:
- NotoSansMath-Regular.ttf: 100,000 tests pass
- Padauk-Bold.ttf: 100,000 tests pass
- ReemKufiInk-Regular.ttf: 100,000 tests pass
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The doc check was failing with:
"Parameter description for hb_depend_get_glyph_entry::flags is missing
in source code comment block."
Added documentation for the @flags parameter explaining that it returns
edge flags indicating whether the dependency came from a contextual
substitution, and that it's nullable.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Per reviewer feedback, use "XSince: REPLACEME" instead of
"Since: REPLACEME" to prevent the documentation build system from
trying to generate api-index-REPLACEME.xml files.
The X prefix marks these as placeholders that will be updated at
release time when the API version is finalized.
Updated all 6 instances:
- src/hb-depend.h: hb_depend_t typedef
- src/hb-depend.cc: 5 function documentations
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Address reviewer feedback and fix remaining doc build errors:
1. Revert "Since: 12.4.0" back to "Since: REPLACEME" per reviewer
comment - version numbers are assigned at release time, not in PRs
2. Remove premature api-index-12-4-0 entry from harfbuzz-docs.xml -
this is also done at release time
3. Add hb-depend chapter to harfbuzz-docs.xml to include the
generated xml/hb-depend.xml file
This fixes the three doc check errors:
- "1 undocumented or incomplete symbols"
- "doesn't appear to include xml/hb-depend.xml"
- "doesn't appear to include xml/api-index-REPLACEME.xml"
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
The documentation build was failing with two errors:
1. "6 unused declarations" - depend API functions weren't listed in
harfbuzz-sections.txt
2. "doesn't appear to include xml/api-index-REPLACEME.xml" - the
version placeholder needed to be replaced with an actual version
Changes:
- Add hb-depend section to docs/harfbuzz-sections.txt with all 6 API
symbols (hb_depend_t, hb_depend_from_face_or_fail,
hb_depend_get_glyph_entry, hb_depend_get_set_from_index,
hb_depend_print, hb_depend_destroy)
- Replace "REPLACEME" with "12.4.0" in src/hb-depend.h
- Add api-index-12-4-0 entry to docs/harfbuzz-docs.xml
This fixes the harfbuzz:harfbuzz-doc-check test failure.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Three related fixes for depend API and check-symbols test:
1. Add HB_INTERNAL to hb_depend_t private methods
The get_*_dependencies() methods are internal implementation
details and should not be exported. Adding HB_INTERNAL ensures
they're hidden symbols.
2. Fix function declaration formatting in hb-depend.h
Added space before opening parenthesis to match HarfBuzz style
and allow gen-def.py regex to detect all function names. Without
the space, only 2 of 5 functions were found.
3. Update check-symbols.py to allow hb_depend_* in subset library
The depend API is intentionally part of libharfbuzz-subset with
its own prefix. Updated the internal symbols check to allow
hb_depend_* symbols when checking libharfbuzz-subset.
With these changes, check-symbols passes both with and without
depend_api enabled.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
The depend API follows the same pattern as experimental_api: the code
is always compiled (guarded by #ifdef HB_DEPEND_API), but symbols
should only be exported when the option is enabled.
Changes:
1. gen-def.py: Add --depend-api flag and filter list (like --experimental-api)
2. src/meson.build: Pass --depend-api flag when option is enabled
This ensures depend symbols are excluded from .def files when depend_api=false
(the CI default), fixing macOS check-symbols test failures.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
The depend fuzzers (hb-depend-fuzzer and hb-depend-closure-parity)
use the depend API which is only available when the depend_api build
option is enabled. However, the fuzzing meson.build was unconditionally
building these fuzzers for all configurations, causing CI build failures
when depend_api was disabled (the default).
This change:
- Splits the fuzzers list into regular tests and depend_tests
- Only builds depend-related fuzzers when HB_DEPEND_API is defined
- Maintains existing behavior for all other fuzzers
- Keeps the test execution conditional as before (lines 142-166)
This fixes all CI build failures across Linux, macOS, Windows (MSVC/MinGW),
and sanitizer builds.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Replace manual pointer arithmetic with std::addressof with the
cleaner get_paint() method that LayerList provides.
Changes:
- colrv1-depend.hh: Use paint_offset_lists.get_paint(i)
- colrv1-closure.hh: Use paint_offset_lists.get_paint(i)
Both files now use the same clean pattern: get_paint() encapsulates
the offset arithmetic (this+(*this)[i]) in a single method call.
Instead of just checking that the ligature set is non-empty, now verify
it contains the expected component glyphs (1823 and 1829) that form the
ligature 1910 (uni03020300).
This matches the validation pattern used in the NotoSans-Bold test and
provides proper regression testing.
Enhance test_depend_gsub_formats to fully exercise the ligature set API
for SourceSansPro-Regular.otf, not just check that a set index is returned.
Changes:
- Create temporary set to retrieve ligature set contents
- Call hb_depend_get_set_from_index to retrieve the set
- Verify the set is non-empty (contains component glyphs)
- Log the number of components found
- Destroy temporary set
This matches the validation pattern used in the NotoSans-Bold test and
ensures the full depend API is exercised consistently across all
ligature tests.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Update hb-depend-fuzzer to fully exercise the depend API by actually
retrieving and validating sets, not just accessing edge values.
Changes:
- Retrieve ligature sets when present using hb_depend_get_set_from_index
- Retrieve context sets when present using hb_depend_get_set_from_index
- Handle nested context sets (indirect references with 0x80000000 bit)
- Check all sets for sanity using hb_set_get_population
- Warn if empty sets are encountered (which shouldn't happen)
This catches bugs in set storage, retrieval, and the encoding of nested
context set references.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Replace manual command-line parsing with glib's GOptionContext/GOptionEntry
system to match other HarfBuzz test tools.
Changes:
- Add glib_dep to meson.build for hb-depend-closure-parity
- Use G_OPTION_ARG_INT64 for hex test seeds (requires 0x prefix)
- Implement parse_inject_rate callback for optional float args with defaults
- Update help text to require 0x prefix for hex values
- Call print_usage() on argument validation errors
- All test seed output verified to use 0x prefix
Benefits:
- Automatic --help generation by glib
- Consistent with other HarfBuzz utilities
- Simpler error handling and validation
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Refactor edge deduplication to follow HarfBuzz's established pattern
(as used in hb-serialize.hh and elsewhere), using struct-based hashing
instead of manual hash computation.
Changes:
1. Add operator== and hash() to hb_depend_data_record_t
- Self-contained equality comparison of all identity fields
- FNV-1a hash implementation
- Flags intentionally excluded (metadata about discovery, not identity)
- Documents why flags are excluded from equality
2. Add edge_key_t struct for deduplication
- Combines source glyph with edge record
- Simple operators that delegate to record's operator== and hash()
- Requires default constructor for hashmap usage
3. Remove manual hash code (~110 lines deleted)
- Delete get_edge_components() (~37 lines)
- Delete compute_edge_hash() (~37 lines)
- Delete edges_equal() (~33 lines)
4. Simplify add_depend_layout() (from ~50 to ~25 lines)
- Create key, check hashmap, add if new
- No collision handling needed (hashmap handles it)
- No component vector storage
5. Replace storage
- Old: hb_hashmap_t<uint64_t, hb_vector_t<uint32_t>> edge_hashes
- New: hb_hashmap_t<edge_key_t, bool> seen_edges
- Update cleanup in hb-depend.cc
Semantic change:
- Old: Compared set CONTENTS (iterated through set elements)
- New: Compares set INDICES directly
- Safe because: context sets deduplicated (same contents = same index),
ligature sets intentionally unique (different rules = different indices)
- In practice: no real fonts have identical ligature components with
different indices for the same layout_tag
Benefits:
- Follows established HarfBuzz pattern
- Simpler semantic (index-based comparison)
- Less code (~110 lines eliminated)
- Less memory (no component vector storage)
- More maintainable (single source of truth in record struct)
- Better separation of concerns (hashing logic in struct)
All tests pass.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit addresses multiple code review comments:
1. Switch RNG to std::mt19937 for deterministic tests
- Replace std::rand/srand with std::mt19937 in parity checker
- Use std::uniform_int_distribution for all random number generation
- Ensures test determinism across platforms for non-error-injection tests
2. Convert debug fprintf to DEBUG_MSG_LEVEL
- Convert GSUB lookup processing prints to DEBUG_MSG_LEVEL(DEPEND, nullptr, 1, 0, ...)
- Visible at HB_DEBUG_DEPEND=2 or higher for detailed per-lookup debugging
3. Rename function for consistency
- hb_depend_from_face → hb_depend_from_face_or_fail
- Follows HarfBuzz convention for functions returning nullptr on failure
- Update all call sites, documentation, and code comments
4. Adopt established set deduplication pattern
- Change from hb_vector_t<hb_set_t> to hb_vector_t<hb::unique_ptr<hb_set_t>>
- Use pointer-based hashmap: hb_hashmap_t<const hb_set_t*, hb_codepoint_t>
- Leverages hb_hash's content-based deduplication via pointer dereferencing
- Follows pattern established elsewhere in HarfBuzz codebase
5. Separate ligature and context set semantics
- Rename free_set → free_ligature_set (no hashmap manipulation)
- Rename new_set → new_ligature_set (no hashmap manipulation)
- Rename find_or_create_set → find_or_create_context_set (only function using hashmap)
- Makes it explicit which sets are deduplicated (context) vs unique (ligature)
- Update all call sites in Ligature.hh, ReverseChainSingleSubstFormat1.hh, hb-ot-layout-gsubgpos.hh
6. Code cleanup
- Remove unused add_to_ligature_set function (dead code)
- Refactor new_ligature_set(cp) to delegate to new_ligature_set(set)
- Move set_to_index declaration near sets/free_set_list for better organization
All tests pass.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Two related fixes:
1. Context set under-approximation fix (hb-ot-layout-gsubgpos.hh):
When a direct requirement (from input positions) overlapped with a
disjunctive set (backtrack/lookahead), the code incorrectly added
the filtered (remaining) set as an additional requirement. Fix:
if position_context intersects with original_set at all, the
disjunctive requirement is already satisfied - don't add anything.
2. Parity checker ligature fix (hb-depend-closure-parity.cc):
When processing deferred ligatures, store {dependent, ligature_set,
flags} at deferral time instead of re-scanning edges later. This
preserves the feature filtering that was already done and correctly
propagates edge flags.
Also updates edge flag documentation to correctly explain the mechanism:
- Depend extraction records edges based on static input coverage/class
- During closure, lookups within a rule are applied sequentially
- Lookups at earlier positions may transform later positions
- Multiple lookups at same position may interact (one produces a glyph,
another immediately consumes it as an "intermediate")
- So a glyph matching coverage might not persist when closure traverses
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Two bugs were fixed in the closure parity checker:
1. Feature filtering for ligatures: When processing deferred ligatures,
the code re-scanned all edges to find satisfying ligature sets but
forgot to filter by active features. This allowed ligatures to be
added via edges from inactive features if their ligature set happened
to be satisfied.
2. Flag checking for ligatures: When adding ligatures, we weren't
checking or propagating the edge flags (FROM_CONTEXT_POSITION,
FROM_NESTED_CONTEXT), so flagged ligature edges weren't being
reported as expected over-approximation.
Also includes related changes to the depend extraction:
- Add FROM_NESTED_CONTEXT flag for nested contextual lookups
- Add context handling for ReverseChainSingleSubstFormat1
- Remove cmap from glyf/CFF closure stage (UVS edges shouldn't be
followed for glyph-based closure)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Added missing documentation for the hit_flagged_edge output parameter
in process_edges_for_tables() and compute_depend_closure() function
comments. This parameter tracks whether edges marked with
FROM_CONTEXT_POSITION flag are traversed during closure computation.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Edges created from non-zero positions in multi-position contextual rules
can consume intermediate glyphs (glyphs produced then immediately consumed,
never settling in closure). This causes depend's closure to include extra
glyphs compared to subset's closure, which is expected behavior.
Added HB_DEPEND_EDGE_FLAG_FROM_CONTEXT_POSITION flag to mark these edges
at extraction time. Updated parity checker to track when such edges are
hit during closure computation and distinguish between:
- Expected over-approximation (hit flagged edge): informational only
- Unexpected over-approximation (no flagged edge): critical error
This enables detection of genuine bugs (unexpected over-approximation)
while allowing expected cases from intermediate glyphs.
Updated all API callers and documentation to include nullable flags
parameter. Renamed parity checker terminology from "fuzzer" to "parity"
for clarity.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Documentation updates:
- Add comprehensive context_set documentation to depend-api.md with
encoding details and example code for check_context_satisfied()
- Update depend-for-closure.md: remove obsolete over-approximation
analysis, reflect that recent testing shows no over-approximation
with proper context_set filtering
- Update depend-implementation.md: correct descriptions of active
glyph filtering, sequential accumulation, ligature sets, and
context recording to match current implementation
- Fix terminology: change 'binning' to 'segmentation' throughout
- Fix hb-depend-data.hh:557: use HB_CODEPOINT_INVALID instead of 0
for layout_tag default value
Fuzzer enhancements (hb-depend-closure-parity):
- Add explicit test mode with command-line options similar to
hb-subset conventions:
--unicodes=LIST Unicode codepoints (U+XXXX, decimal, ranges)
--gids=LIST Glyph IDs (decimal, ranges)
--no-layout-closure Skip GSUB closure
--layout-features=LIST GSUB features (comma-separated or *)
- Support multiple input formats:
--unicodes=U+0041,U+0042,U+0043
--unicodes=65-90
--gids=10-50 --no-layout-closure
--layout-features=liga,calt or --layout-features='*'
- Add robust input parsing with validation to prevent infinite loops
on invalid input (e.g., --gids=abc or --unicodes=U+GGGG)
- Add error checking for conflicting options
This allows reproducing random test cases manually and testing
specific scenarios without finding the right seed.
Tested: All modes produce identical results to seed-based tests.
Renames:
- hb-depend-fuzzer.cc → hb-depend-closure-parity.cc
- hb-depend-fuzzer-main.cc → hb-depend-closure-parity-main.cc
- hb-depend-security-fuzzer.cc → hb-depend-fuzzer.cc
The closure parity test validates correctness by comparing the depend
API implementation against the battle-tested subset closure calculation,
ensuring the two implementations stay synchronized. It runs on valid
fonts from test/api/fonts/.
The depend fuzzer is a security fuzzer that tests robustness against
malformed input, following the standard HarfBuzz fuzzer pattern. It runs
on malformed fonts from test/fuzzing/fonts/.
Updated test/fuzzing/README.md to document both tools and their distinct
purposes. Updated meson.build to reflect the new naming in test
registration.
This commit implements the experimental depend API for extracting glyph
dependency graphs from OpenType fonts. The depend API provides the foundation
for computing glyph closures and analyzing font structure.
The implementation significantly improves upon the initial draft (commit
3f59433d5) by adding contextual filtering to reduce over-approximation while
still capturing complete dependency graphs.
Core Architecture
-----------------
The depend implementation operates in graph extraction mode: it walks all font
tables once to build a complete dependency graph. The key innovation is
contextual filtering that reduces over-approximation compared to the naive
approach.
Contextual Filtering for Reduced Over-Approximation
----------------------------------------------------
The initial implementation (3f59433d5) recorded dependencies for ALL glyphs in
every lookup's coverage, leading to significant over-approximation. The current
implementation filters dependencies based on context:
**Individual Lookups**: Each lookup's depend() method filters by active glyphs:
// Old approach (3f59433d5)
+ hb_iter (this+coverage) // ALL coverage glyphs
| hb_apply (record_dependency)
// New approach
hb_set_t intersection;
(this+coverage).intersect_set (c->parent_active_glyphs(), intersection);
+ hb_iter (intersection) // ONLY contextually relevant glyphs
| hb_apply (record_dependency)
**Contextual Lookups**: ContextFormat1/2/3 and ChainContextFormat1/2/3 set up
active glyph contexts for nested lookups:
hb_set_t* cur_active_glyphs = c->push_cur_active_glyphs();
get_coverage().intersect_set(*c->glyphs, *cur_active_glyphs);
// Process rules with filtered coverage
+ hb_zip (this+coverage, ruleSet)
| hb_filter ([&] (hb_codepoint_t g) {
return c->parent_active_glyphs().has(g);
}, hb_first)
| hb_apply (process_rule)
This significantly reduces over-approximation for simple cases while maintaining
complete graph coverage.
**Intentional Over-Approximation at Nested Boundaries**: When contextual rules
invoke nested lookups, we pass ALL glyphs to ensure no edges are missed:
// In context_depend_recurse_lookups()
cur_active_glyphs->set (*c->glyphs); // Universe for nested lookups
This design choice prioritizes completeness over precision at contextual
boundaries, which is appropriate for graph extraction.
Edge Deduplication and Performance
-----------------------------------
Dependency extraction can generate millions of potential edges. To maintain
acceptable performance:
- Edge hashing (compute_edge_hash): O(1) duplicate detection via hash table
keyed on (source, table_tag, layout_tag, dependent, ligature_set_contents)
- Hash collision handling: Falls back to O(n) linear search through glyph's
existing dependencies only on collision (rare)
- Component vectors: Stores edge components for collision detection
- Post-extraction cleanup: Frees temporary structures (edge_hashes,
lookup_features) to reduce memory footprint
Table-Specific Extraction
--------------------------
- **cmap**: Unicode → glyph mappings including UVS (Unicode Variation Sequences)
- **GSUB**: All substitution rules with feature tags and ligature set tracking
- Handles all 8 GSUB lookup types including Extension (type 7)
- Records which features reference each dependency
- Groups ligature alternatives via ligature_set indices
- **glyf**: TrueType composite glyph components
- **CFF**: CFF1 SEAC (Standard Encoding Accented Character) composites
- **COLR**: Color layer dependencies for both COLRv0 and COLRv1
- Filters self-referential PaintGlyph to prevent trivial cycles
- **MATH**: Mathematical variant glyphs and assembly components
CFF SEAC dependencies use table_tag='CFF ' with layout_tag=0 and
ligature_set=HB_CODEPOINT_INVALID, matching the pattern used for glyf.
Data Structure: hb_depend_data_record_t
----------------------------------------
Each dependency edge contains:
- table_tag: Source table (GSUB, glyf, CFF, COLR, MATH, cmap)
- dependent: Target glyph ID
- layout_tag: Feature tag (for GSUB) or UVS codepoint (for cmap), else 0
- ligature_set: Index into sets array for ligature alternatives, else INVALID
- context_set: Reserved for future contextual filtering (currently unused)
Graph stored as vector indexed by glyph ID, each containing vector of records.
Testing and Documentation
--------------------------
- test/api/test-ot-depend.c: Comprehensive test suite (645 lines)
- Tests all table types and GSUB substitution formats
- Includes regression tests for edge cases
- Uses ContextFormat2-Depend-Test.ttf (minimized from 486KB to 85KB)
- test/fuzzing/hb-depend-fuzzer.cc: Production-quality closure implementation
- Demonstrates correct ligature set handling
- Includes feature filtering and over-approximation analysis
- Reference implementation for depend-based closure computation
- docs/depend-api.md: Public API documentation with usage examples
- docs/depend-for-closure.md: Guide to using depend for closure computation
- docs/depend-implementation.md: Implementation details and architecture
Build System
-------------
- Meson option: -Ddepend_api=true
- Compile flag: -DHB_DEPEND_API
- Symbols in libharfbuzz-subset.dylib (applications must link both
libharfbuzz and libharfbuzz-subset)
Status: Experimental API, subject to change.
This commit adds complete documentation for the dependency analysis API
at all levels: public API, internal structures, and implementation.
Public API documentation (src/hb-depend.cc, src/hb-depend.h):
- Replaced "XXX Todo" placeholder in SECTION comment with detailed
module description explaining dependency graphs and use cases
- Fixed misleading hb_depend_t description (was only mentioning UVS)
- Added full documentation for hb_depend_print() with debugging notes
- Added usage examples to all three public functions
- Updated all version tags from "?.0.0" to "REPLACEME"
- Added experimental API warnings throughout
Internal documentation (src/hb-depend-data.hh, src/hb-depend.hh):
- Documented 5 internal structures with purpose and ownership semantics
- Added comments explaining data relationships and lifecycle
Algorithm documentation (src/hb-depend.cc):
- Added detailed algorithm comments to 5 extraction methods explaining
how dependencies are collected from each OpenType table (cmap, GSUB,
glyf, COLR, MATH)
User guide (docs/depend-api.md):
- Created comprehensive 250-line API guide with:
* Introduction with mechanism overview
* Basic usage example (iterating dependencies)
* Advanced examples (computing reachable glyphs, ligature sets)
* API details and compilation instructions
* Implementation notes including ownership semantics
* Use cases (subsetting, coverage analysis, binning, testing)
- Prominent experimental API warnings
Build configuration (meson_options.txt):
- Updated option description to emphasize experimental status
All documentation follows HarfBuzz conventions and includes gtk-doc
formatting for API reference generation.
After rebasing onto main, the depend code needs to use format.v
instead of format directly, due to main's "Wrap formats in struct"
change (346b8dcf9).
Updated:
- hb-ot-cmap-table.hh: _.u.format == 14 → _.u.format.v == 14
- COLR.hh: switch (u.format) → switch (u.format.v)