Commit Graph
21394 Commits
Author SHA1 Message Date
Skef IterumandClaude ec97c40d5f Fix CI: Filter depend API symbols from exports when depend_api=false
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>
2026-06-05 15:09:11 -07:00
Skef IterumandClaude 3648c61cb0 Fix CI: Only build depend fuzzers when depend_api is enabled
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>
2026-06-05 15:09:11 -07:00
Skef Iterum 504afe5a26 Use LayerList::get_paint() instead of std::addressof
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.
2026-06-05 15:09:11 -07:00
Skef Iterum 975948b728 Validate ligature set contents in SourceSansPro test
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.
2026-06-05 15:09:11 -07:00
Skef IterumandClaude 236a5822b1 Add full ligature set validation to SourceSansPro test
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>
2026-06-05 15:09:11 -07:00
Skef IterumandClaude f3b51aad3f Enhance depend fuzzer to exercise full API
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>
2026-06-05 15:09:11 -07:00
Skef IterumandClaude f62ac68532 Convert parity checker to use glib option parsing
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>
2026-06-05 15:09:11 -07:00
Skef IterumandClaude 02e80df2eb Adopt struct-based edge deduplication pattern
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>
2026-06-05 15:09:11 -07:00
Skef IterumandClaude f298400085 Address code review feedback for depend API
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>
2026-06-05 15:09:11 -07:00
Skef IterumandClaude Opus 4.5 b351a2dc9c Fix under-approximation in context set filtering and update edge flag docs
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>
2026-06-05 15:09:11 -07:00
Skef IterumandClaude Opus 4.5 f034f90629 Fix ligature processing bugs in depend parity checker
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>
2026-06-05 15:09:11 -07:00
Skef IterumandClaude 24540b24c4 Update function comments to document hit_flagged_edge parameter
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>
2026-06-05 15:09:11 -07:00
Skef IterumandClaude ce4564da0d Add edge flags to detect over-approximation from contextual positions
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>
2026-06-05 15:09:11 -07:00
Skef Iterum d0cee3ca7e Update depend API docs and add explicit test mode to fuzzer
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.
2026-06-05 15:09:11 -07:00
Skef Iterum 83b887cda1 Rename depend fuzzers and add security fuzzer
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.
2026-06-05 15:09:11 -07:00
Skef Iterum 29cf3aa519 Add depend API: graph extraction with contextual filtering
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.
2026-06-05 15:09:11 -07:00
Skef Iterum 4ea82e1afc Add comprehensive documentation for depend API
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.
2026-06-05 15:09:11 -07:00
Skef Iterum 8299b0b2d1 Fix depend code for wrapped format structs
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)
2026-06-05 15:09:11 -07:00
Skef Iterum 5bf964a211 Finishing up draft 2026-06-05 15:09:11 -07:00
Skef Iterum c263ee16f5 Add colrv1-depend
first try making support conditional on HB_DEPEND_API
2026-06-05 15:09:10 -07:00
Skef Iterum 8c2c627faa extraction API 2026-06-05 15:09:10 -07:00
Skef Iterum fe59e7c5cd Math, COLR, and glyf dependencies 2026-06-05 15:09:10 -07:00
Skef Iterum 65447f9cbb Initial playing around with dependencies 2026-06-05 15:09:10 -07:00
Garret Rieger 8647a429ce Fix subset fuzzer timeout. (#6019)
https://oss-fuzz.com/testcase-detail/5440786836815872
2026-06-04 04:37:23 -06:00
Khaled Hosny 56feae4035 14.2.1 14.2.1 2026-06-02 14:30:59 +03:00
Behdad Esfahbod 8beb229a4c [gen-tag-table] Generate bytes instead of str in rust output (#6017) 2026-06-02 03:11:23 -06:00
Fuqiao Xue 6dda1a083c Add HB_SCRIPT_KATAKANA_OR_HIRAGANA (#5995)
* Add HB_SCRIPT_KATAKANA_OR_HIRAGANA

Fix #1473.

* Refactor HB_SCRIPT_KATAKANA_OR_HIRAGANA
2026-06-02 02:33:52 -06:00
Behdad Esfahbod 2575326527 [rust] Bulk-populate HarfRust input buffer (#6016)
Use the HarfRust bulk UnicodeBuffer glyph-info append API to populate
the shaping buffer from HarfBuzz glyph infos after one slice cast. This
avoids per-codepoint add calls in the HarfBuzz-to-HarfRust bridge.

Testing: ninja -C build src/rust/libharfbuzz_rust.a

Assisted-by: OpenAI Codex
2026-06-02 01:46:23 -06:00
Behdad Esfahbod a4eb9e25d3 [rust] Avoid parsing HarfRust language tags (#6015)
HarfBuzz language tags are already available as C string bytes.
Pass those bytes directly to HarfRust Language::new instead of
converting through UTF-8 and FromStr.

Testing: ninja -C build src/rust/libharfbuzz_rust.a

Assisted-by: OpenAI Codex
2026-06-01 10:35:24 -06:00
Behdad Esfahbod 97650e50e2 [rust] Use SmallVec for HarfRust features (#6014)
Most shaping calls pass maximum a couple of user features. Store the
converted HarfRust feature list in a SmallVec with the same inline
capacity that HarfRust uses for shape-plan user features, avoiding
a heap allocation for common cases.

Testing: ninja -C build src/rust/libharfbuzz_rust.a

Assisted-by: OpenAI Codex
2026-06-01 09:53:23 -06:00
Behdad Esfahbod 8987443bd3 [rust] Bulk-copy HarfRust shape results (#6013)
HarfRust glyph infos and positions are layout-compatible with the
corresponding HarfBuzz buffer structs. Assert that size, alignment,
and visible field offsets match, then copy both arrays directly into
the HarfBuzz buffer instead of translating each glyph field-by-field.

Also, don't truncate hb buffer before resizing it to populate. This
would not zero the private fields (var1/var2, var), but that's not
visible to user nor used later.

Assisted-by: OpenAI Codex
2026-06-01 08:49:52 -06:00
Behdad EsfahbodandClaude Opus 4.8 d639197ed5 [COLR] Fix glyph extents for .notdef in COLRv1 fonts (#6012)
get_base_glyph_paintrecord() looked up the BaseGlyphList with the
reference-returning bsearch(), which yields the all-zero Null object
when the glyph is absent, and then rejected non-matches by comparing
record->glyphId against the requested gid. For glyph 0 the Null
object's glyphId (0) equals the requested gid, so the sentinel was
taken for a real record. .notdef then resolved to a bogus empty paint,
and COLR::get_extents() returned success with 0,0,0,0 instead of
letting hb_ot_get_glyph_extents() fall back to the glyf outline.

Use bfind(), which reports presence directly, so a missing glyph
(including glyph 0) returns nullptr and extents fall back correctly.

This surfaced as a mark-positioning difference: fallback mark
positioning centers a mark using the base and mark glyph extents, so a
.notdef mark over a space was positioned differently from shapers that
report the real outline extents (e.g. fontations/HarfRust).

Testing:
- test/api/test-extents.c: glyph 0 (.notdef, has an outline) now
  reports its outline extents; updated the expectation accordingly.
- b/util/hb-shape Noto-COLRv1.ttf -u 0020,0650 now matches
  --font-funcs=fontations.
- meson test -C build  (246 passed, 1 skipped)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 03:23:05 -06:00
Behdad Esfahbod 27734f01dc Fix unused-warning error
https://github.com/harfbuzz/harfbuzz/pull/6009#issuecomment-4590976488
2026-06-01 10:54:05 +02:00
Behdad Esfahbod 0efc579fc4 [config] Fix CFF closure with HB_NO_DRAW (#6009)
HB_NO_DRAW only disables the draw-dependent OT-font CFF extents
path.  It should not imply full HB_NO_CFF for downstream builds
that independently disable CFF subsetting.

Keep the HB_TINY behavior by making HB_NO_CFF conditional on the
combination of HB_TINY and HB_NO_DRAW.  Also avoid calling the CFF2
instance-metrics helper when OT-font CFF support is disabled, since
that helper needs the CFF2 extents implementation.

Context:
https://github.com/harfbuzz/harfbuzz/pull/5958#discussion_r3121421428
https://github.com/harfbuzz/harfbuzz/issues/5955#issuecomment-4289771142
https://github.com/harfbuzz/harfbuzz/issues/5955#issuecomment-4345573851

Tested by compiling src/harfbuzz-subset.cc directly with
-DHB_NO_DRAW -DHB_NO_SUBSET_CFF and checking the CFF2 extents symbol
is no longer undefined.  Also direct-compiled src/harfbuzz.cc with the
same defines, plus src/harfbuzz-subset.cc for plain HB_TINY and
HB_TINY with HAVE_CONFIG_OVERRIDE_H using util/gpu/web.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-06-01 02:32:21 -06:00
Dominik RöttschesandBehdad Esfahbod 30bde663e7 Pass codepoints for context directly to HarfRust shaper (#6008)
Avoid unnecessary round-trip of converting pre- and post-context from
Unicode codepoints to UTF-8 in C++ (hb-harfrust.cc) and back to Rust
&str (and eventually back to codepoints) in Rust (shape.rs).
Instead, use the new codepoint-based context setters in HarfRust.

Verified locally against CJK_article.html blink_perf menchmark to
gain approximately 2-4%.

Requires https://github.com/harfbuzz/harfrust/pull/371 and a newly
released HarfRust version.

Assisted-by: Google Antigravity

Co-authored-by: Behdad Esfahbod <behdad@behdad.org>
2026-06-01 02:32:01 -06:00
Behdad Esfahbod bc4cd305ca [rust] Use new harfrust GlyphFlags getter (#6011)
* [rust] Reinstate commented-out git branch for harfrust

For development purposes.

* [rust] Use new HarfRust GlyphFlags getter

Faster.

* [rust] Pin to new harfrust 0.8.2
2026-06-01 02:23:26 -06:00
Behdad Esfahbod fd707f8151 [fontations] Map default variations
https://github.com/servo/servo/pull/38707#issuecomment-4587826343
2026-05-31 21:26:19 +02:00
Behdad Esfahbod 2353415a37 [rust] Reinstate commented-out git branch for harfrust
For development purposes.
2026-05-30 23:23:59 +02:00
Behdad Esfahbod e020ac487e [buffer] Harden verification after non-monotone clusters (#6010)
When buffer verification detects non-monotone clusters, skip the
unsafe-to-break and unsafe-to-concat checks that rely on monotone
cluster order.  Keep reporting the monotone-cluster failure as the
underlying verifier error.

Also turn the unsafe-to-break text range assertion into a verifier
failure so malformed intermediate verifier state does not abort the
process.

Testing:
meson test -C build

Assisted-by: OpenAI Codex
2026-05-30 08:48:03 -06:00
Behdad Esfahbod abc3b1a363 [avar] Avoid float-to-int overflow UB in avar2 mapping
map_coords_16_16() converted roundf(delta * 4) back to int without
bounding the float first. With attacker-controlled avar2 long-word
(32-bit) ItemVariationStore deltas, delta * 4 can exceed INT_MAX, and
the implicit float-to-int conversion is undefined behavior per the C++
standard (out-of-range floating-to-integral conversion). The result was
clamped immediately afterwards, so there was no memory-safety impact,
but the conversion itself trips UBSan.

Clamp the float to the 16.16 normalized range before the conversion so
the narrowing can never go out of range.

Fixes: https://github.com/harfbuzz/harfbuzz/security/advisories/GHSA-xxfv-x2x5-8992

Assisted-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-30 15:41:53 +02:00
Takeru Suzuki 689383d05b [subset] keep East Asian spacing palt by default (#6007)
`palt` (Proportional Alternate Widths) is widely used in Japanese
typography but was not retained in the default subset layout features,
unlike its vertical counterpart `vpal` and the closely related `halt`
/ `vhal` / `chws` / `vchw` already kept by default. As a result,
subsetting silently stripped `palt` data, and downstream CSS
`font-feature-settings: "palt"` had no effect.

Add `palt` to the default layout features list alongside the other
East Asian spacing features.

Verified locally with `meson test -C build` (240/240 OK, 0 failures)
and by subsetting NotoSansJP-Bold.ttf with `hb-subset`: `palt` is
stripped on main and retained with this patch, while the other CJK
spacing features (`halt`, `vpal`, `vhal`) are unaffected.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6006

Assisted-by: Claude
2026-05-29 03:19:18 -06:00
Behdad EsfahbodandChad Brokaw 77abf89986 [harfrust] Honor hb font funcs during shaping (#6002)
Wire the HarfRust shaper through the active hb_font_t callback
surface so custom hb_font_funcs_t are respected during shaping.
Add a harfrust-specific test-shape invocation to cover that path.

Tested: meson test -C build test-shape-harfrust
Tested: HB_SHAPER_LIST=harfrust meson test -C build harfbuzz:shape_threads
Tested: HB_SHAPER_LIST=harfrust meson test -C build test-shape
Assisted-by: OpenAI Codex

---------

Co-authored-by: Chad Brokaw <cbrokaw@gmail.com>
2026-05-28 13:33:21 -04:00
Qunxin Liu 1e434eb7fd [subset-repack] increase the MAX_SPACES limit (#5996)
This fixes: https://github.com/harfbuzz/harfbuzz/issues/5980
2026-05-27 16:43:47 -06:00
Behdad Esfahbod 2326d8cc49 Merge pull request #6005 from harfbuzz/fontations-paint-match-more
Match more paint tests across backends (ot, ft, fontations)
2026-05-27 11:42:23 -06:00
Behdad Esfahbod 719a1d3c10 [paint] Round COLRv1 alpha consistently
Round COLRv1 alpha values when packing them into 8-bit colors in the
native OpenType and FreeType paint paths.

This removes the old downward truncation bias and aligns native output
with the backend behavior expected by the updated paint fixtures.

Update the affected test-paint fixtures for the rounded alpha values.

Testing:
CCACHE_DISABLE=1 meson test -C build --print-errorlogs

Assisted-by: OpenAI Codex
2026-05-27 12:42:55 +02:00
Behdad Esfahbod 788706d568 [test] Normalize linear paint transcripts
Reduce linear gradient anchors and normalize color lines before
printing them in test-paint. This makes the transcript reflect the
renderer-facing gradient geometry instead of backend-specific raw
COLRv1 anchors and stop ranges.

Also normalize signed zero in transform output so the fixtures stay
stable across backends.

Testing:
CCACHE_DISABLE=1 meson test -C build test-paint --print-errorlogs

Assisted-by: OpenAI Codex
2026-05-27 12:40:44 +02:00
Behdad Esfahbod 88adc6437e Merge pull request #6004 from harfbuzz/fontations-colr-match
[hb/ft] Match COLRv1 paint order to fontations
2026-05-27 04:17:23 -06:00
Behdad Esfahbod 56ac9c925f [paint] Push COLRv1 root clip under font transform
Make the native COLRv1 paint paths report the root clip in font
units under the font transform. This matches the order used by
fontations and removes the need to pre-scale the HB-OT clip extents.

For the FreeType path, add a helper to convert FT_ClipBox values
back to font units before pushing them under the font transform, and
share that conversion with nested COLR glyph clip boxes.

Update paint and vector expectations for the new transform/clip stack.

Testing:
CCACHE_DISABLE=1 meson test -C build --print-errorlogs

Assisted-by: OpenAI Codex
2026-05-27 10:48:19 +02:00
Behdad Esfahbod 202202b349 [test] Disable stale beyond-64k API checks
The disabled assertions cover behavior from an older beyond-64k proposal.
That proposal has since changed, and current backends should not be
required to implement the stale loca-derived glyph count and metrics rules.

Keep the checks visible as disabled reminders until the library code is
adapted to the updated design.

Tested with:
CCACHE_DISABLE=1 HB_FONT_FUNCS=fontations meson test -C build test-be-glyph-advance test-be-num-glyphs

Assisted-by: OpenAI Codex
2026-05-27 09:38:31 +02:00
Behdad Esfahbod c6ebdf6520 [font] Adjust extents rounding to be inclusive 2026-05-26 22:40:38 +02:00