Commit Graph
618 Commits
Author SHA1 Message Date
Khaled Hosny 36cb489cb0 14.4.0 2026-08-26 22:27:05 +03:00
Behdad Esfahbod 5e75e91ebf [set] Add hb_set_intersects API
Expose the exact set-intersection query so callers can test whether two
sets have any elements in common without copying and mutating a set.
The implementation handles inverted sets through the internal helper.

Document the new API with its release placeholder, add it to the docs
section index, and cover regular and inverted set combinations.

Tested with the full Meson test suite (270/270 passed).

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-19 16:00:05 -06:00
Simon Cozens 32d6e5c491 Update WASM shaper docs (#6138) 2026-08-04 01:41:30 -06:00
Khaled Hosny 4c2aa80467 14.3.0 2026-07-31 17:49:40 +03:00
Khaled Hosny 86e7473f0d [ot] Add hb_ot_fetch_number()
Similar to hb_ot_fetch_bits() but for signed numbers.

The only tags so far are for font bounding box from head table.

Fixes https://github.com/harfbuzz/harfbuzz/issues/6110
2026-07-31 04:31:26 +03:00
Khaled Hosny 6e67c5feed [ot] Add hb_ot_fetch_bits()
For fetching various bit fields scattered around OpenType tables. Many of
these are legacy or unreliable, but applications might need them for
various legacy reasons.

Fixes https://github.com/harfbuzz/harfbuzz/issues/1920
2026-07-31 04:31:26 +03:00
Behdad Esfahbod 25fc94439a Merge pull request #5733 from skef/depend-draft-pr
OpenType font dependency graph support
2026-07-30 11:12:48 -06:00
Garret Rieger 2725565dab Address review comments. 2026-07-14 16:26:49 -06:00
Khaled Hosny 421cc8f5a7 [paint] Add hb_paint_fill_glyph()
Instead of painting COLRv0 and outline fallback layers with
push_clip_glyph + color + pop_clip, add a dedicated callback for this
common paint operation.

The default (*_nil) implementation uses the decomposed sequence, so
existing clients without a fill_glyph implementation continue to work as
before.
2026-07-08 20:29:31 +03:00
Skef Iterum 71984479b1 [depend] Add direct-include guard to hb-subset-depend.h
Add the standard HB_SUBSET_H_IN / HB_NO_SINGLE_HEADER_ERROR guard
to hb-subset-depend.h, matching the pattern used by hb-*.h subheaders
(HB_H_IN) and hb-ot-*.h subheaders (HB_OT_H_IN).

hb-subset.h now defines HB_SUBSET_H_IN around its subheader includes,
and hb.hh defines it permanently for internal library code. Consumers
that include hb-subset-depend.h directly will get a clear error
directing them to use hb-subset.h instead.

Also add HB_SUBSET_H_IN to the Private subsection in
harfbuzz-sections.txt so gtkdoc doesn't flag it.

Assisted-by: Claude <noreply@anthropic.com>
2026-06-05 15:14:28 -07:00
Skef Iterum c0059c1f61 [depend] Fix docs build and add missing hb-subset.h includes
The SECTION annotation in hb-depend.cc used the old name "hb-depend"
which didn't match the "hb-subset-depend" FILE name in sections.txt
after the header rename. This caused gtkdoc to report the section
description as unused and the section symbols as undocumented. Also
add HB_SUBSET_DEPEND_EDGE_FLAGS_T_DEFINED to a Private subsection
so gtkdoc doesn't flag it as an unused declaration.

The header move from hb.h to hb-subset.h (e3e754f9c) also left
util/hb-subset-depend.cc and test/api/test-ot-depend.c without
access to hb-subset-depend.h, causing build failures on sanitizer
CI jobs that build the utility and test. Add the missing
#include <hb-subset.h> to both.

Assisted-by: Claude <noreply@anthropic.com>
2026-06-05 15:09:13 -07:00
Skef Iterum 0b29fc9be4 [depend] Move public header from libharfbuzz to libharfbuzz-subset
Rename hb-depend.h to hb-subset-depend.h and include it from
hb-subset.h instead of hb.h, so the depend API is scoped entirely
to the subset library. The implementation was already compiled into
libharfbuzz-subset; this aligns the public header with that.

Assisted-by: Claude <noreply@anthropic.com>
2026-06-05 15:09:13 -07:00
Skef Iterum b421888ce4 [depend] Fix docs build: remove enum constants from sections.txt
gtk-doc does not expect individual enum constants to be listed in
harfbuzz-sections.txt — only the typedef name.  Other HarfBuzz flag
enums (hb_glyph_flags_t, hb_subset_flags_t, etc.) follow this
pattern.  The three HB_SUBSET_DEPEND_EDGE_FLAG_* entries caused
"undeclared" warnings and doc check failures.

Also keeps the include-guard removal from the previous commit
(moving #define after the typedef so gtk-doc sees the unguarded
declaration).

Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-05 15:09:12 -07:00
Skef Iterum ea668aaa34 [depend] Detect GSUB self-feeding chains in parity checker
When the parity checker finds unexpected over-approximation (depend
closure has extra glyphs without flagged edges), check whether the
font has self-feeding GSUB lookups — lookups whose output coverage
overlaps their input coverage.  These create transitive chains that
the depend closure follows to completion while the subsetter's
iteration-capped closure truncates.

No shaper re-applies a lookup to its own output within a single
feature application, so the extra glyphs are harmless.  The
detection traces extra glyphs through self-feeding feature edges
from the subset closure; if all are explained, the test passes.

Detection runs only on the failure path and is O(edges), so
well-formed fonts (which don't have self-feeding lookups) pay no
cost.

Also document MATH single-pass closure and GSUB self-feeding chains
in depend-for-closure.md and depend-implementation.md.

Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-05 15:09:12 -07:00
Skef IterumandClaude Sonnet 4.6 4753f010c6 [depend] Address review feedback: drop face field, stale include, minor cleanup
- 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>
2026-06-05 15:09:12 -07:00
Skef IterumandClaude Sonnet 4.6 211d7646f0 [depend] Update documentation for public API rename
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>
2026-06-05 15:09:12 -07:00
Skef IterumandClaude Sonnet 4.5 a1114985d6 Remove cmap depend extraction - UVS now handled via query API
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>
2026-06-05 15:09:12 -07:00
Skef IterumandClaude 51caf2b6fa Fix documentation build: Revert version and add hb-depend chapter
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>
2026-06-05 15:09:12 -07:00
Skef IterumandClaude 888e8b3435 Fix CI: Add depend API documentation to harfbuzz-sections.txt
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>
2026-06-05 15:09:12 -07:00
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 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 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 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
Khaled Hosny b0ffab42d4 14.2.0 2026-04-20 05:10:48 +02:00
Behdad Esfahbod b3c3e6a818 [vector] Add public hb_vector_draw_new_path() API
Exposes the path separation as a public function so callers
using the draw funcs directly can separate glyph outlines.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-18 11:41:44 -06:00
Behdad Esfahbod 750df72e2b [NEWS/docs] Update for vector API changes
- Remove draw svg_prefix from New API list and sections.txt
- Document pen_x/pen_y removal, dedup removal, _glyph
  simplification in the Vector library section

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-18 11:36:05 -06:00
Behdad Esfahbod 77b0369078 [hb-vector.png] Fixup 2026-04-17 16:50:36 -06:00
Behdad Esfahbod d689790d5d hb-shape.png: Optimize 2026-04-17 15:58:27 -06:00
Behdad Esfahbod d5819716b3 Add hb-shape.png 2026-04-17 15:53:57 -06:00
Behdad Esfahbod e9c62e1ad3 [vector] Center logo to match others 2026-04-17 15:43:28 -06:00
Behdad Esfahbod 7c54a401c0 [vector-draw] Add foreground/background color API
Add hb_vector_draw_set_{foreground,background}() and getters.

SVG: foreground wraps body in <g fill="rgb(...)">; background
emits a <rect> covering the viewBox before content.

PDF: foreground sets fill color via rg operator before glyph
content; background emits a filled rect at the start of the
content stream.

Default: foreground opaque black, background transparent.

Wire both into the hb-vector CLI util alongside the paint
equivalents.  Remove the old util-side emit_background_rect.

Regenerated vector test expected outputs.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 19:13:33 -06:00
Behdad Esfahbod d774a9a4e2 [vector/raster] Add set_background / get_background API
Add hb_vector_paint_set_background() / get_background() and
hb_raster_paint_set_background() / get_background().

For vector: if set to a non-transparent color, the SVG renderer
emits a <rect> covering the viewBox before glyph content, and
the PDF renderer prepends a filled rectangle to the content
stream.  Both support semi-transparent backgrounds (SVG via
fill-opacity, PDF via ExtGState /ca).

For raster: the root surface is pre-filled with the background
color before glyph compositing begins.

Default is transparent (no background emitted).

The hb-vector CLI util wires --background to the new API.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 18:22:07 -06:00
Behdad EsfahbodandClaude Opus 4.6 591748f1e1 [draw][paint] Make get_funcs instance-aware; add get_format
The six public draw / paint funcs getters across raster,
vector, and gpu used to be singletons:

  hb_raster_draw_get_funcs (void)
  hb_raster_paint_get_funcs (void)
  hb_vector_draw_get_funcs (void)
  hb_vector_paint_get_funcs (void)
  hb_gpu_draw_get_funcs (void)
  hb_gpu_paint_get_funcs (void)

That works fine for raster and gpu, where there's a single
backend per type, but breaks for the vector backend where
SVG and PDF have separate funcs sets — callers using the
public getter always got SVG funcs and silently produced
SVG markup inside PDF output streams when invoking the new
arbitrary-path clip API on a PDF context.

Make all six take a const-pointer to the relevant context
instance.  vector_paint dispatches on paint->format; the
other five just use the instance for symmetry today (room
for future format-style dispatch later).

Also expose hb_vector_draw_get_format / hb_vector_paint_
get_format public getters so callers (or third parties)
can ask a vector context for its format without poking at
internals.

Also: hb_vector_paint_push_clip_path_end now wraps the
emitted SVG clipPath's path in transform="scale(1,-1)" so
free-form arbitrary clips at base body level land in the
same coord system the per-glyph <use scale(_,-sy)>
wrappers establish.  Without this, free-form clip-path
arbitrary outlines emitted between paint_glyph calls came
out mirrored across the X axis.

Updates internal callers (hb_vector_paint_glyph,
hb_pdf_emit_glyph_path, hb_raster_paint_push_clip_path_
start, hb_gpu_paint_push_clip_path_start, the GPU pen
adapter), util sites (raster-output.hh, vector-output.hh,
gpu/demo-font.cc), API tests (test-raster.cc, test-gpu.cc),
and the docs section index.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:21:49 -06:00
Behdad EsfahbodandClaude Opus 4.6 98470a3e02 [draw] Rename hb_draw_rect to hb_draw_rectangle
API rename for the not-yet-released stroked/filled
rectangle helper added to hb-draw — full names
(hb_draw_line, hb_draw_circle, hb_draw_rectangle) read
better than mixed full/abbreviated.

Updates the public header, impl, the gpu doc reference,
the GPU API test, the GPU demo's extents overlay, the
extents-overlay paint helper, and the docs section
listing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad Esfahbod 599c99b589 [paint] Add arbitrary-path clip API
Add push_clip_path_start / push_clip_path_end to the
hb_paint_funcs_t vtable, for callers that want to clip paint
output to an arbitrary shape (not just a glyph or rectangle).

  hb_draw_funcs_t *df = hb_paint_push_clip_path_start (pf, pd, &dd);
  hb_draw_move_to (df, dd, NULL, ...);
  hb_draw_line_to (df, dd, NULL, ...);
  ...
  hb_draw_close_path (df, dd, NULL);
  hb_paint_push_clip_path_end (pf, pd);
  /* paint ops here are clipped to the emitted path */
  hb_paint_pop_clip (pf, pd);

The backend hands back a draw_funcs + draw_data pair (transfer
none) that accumulates the clip path; end() signals the
caller is done drawing clip geometry and the accumulated
path becomes an active clip.  pop_clip closes the scope,
symmetric with push_clip_glyph / push_clip_rectangle.

Only public API and the nil vtable stubs land here.  Backend
implementations (hb-vector, hb-raster, hb-gpu) follow in
separate commits.

Partial: https://github.com/harfbuzz/harfbuzz/issues/5930

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad Esfahbod 390ec06fa7 Merge pull request #5931 from harfbuzz/paint_or_fails
[vector/raster/gpu] Add *_glyph_or_fail() variants across all three
2026-04-16 16:13:05 -06:00
Behdad Esfahbod 64d2c7311b [paint] Promote reduce_anchors / normalize_color_line / sweep_tiles to public (#5932)
Every COLRv1 renderer ends up rewriting these three helpers;
they now live on hb-paint.h so Skia, FreeType-SVG, and other
downstream paint-API implementers can consume a single
canonical implementation.

  * hb_paint_reduce_linear_anchors() -- 3-anchor (P0, P1, P2)
    to 2-point axis projection.
  * hb_paint_normalize_color_line() -- sort + rescale stops
    to [0, 1]; returns (min, max) so callers can shift
    gradient geometry to match.
  * hb_paint_sweep_gradient_tiles() + matching
    hb_paint_sweep_gradient_tile_func_t callback typedef --
    iterates the full 0..2π sweep produced by a color-stop
    list, invoking the callback once per (start, end)
    angular segment.  Handles PAD / REPEAT / REFLECT.

Implementation moves from src/hb-paint.hh (private, static
inline) to src/hb-paint.cc (public, HB_EXTERN).  The sweep
tiler loses its C++ template/lambda flavor and grows a
user_data parameter alongside the function-pointer callback;
the three in-tree callers (cairo, vector-paint, vector-paint-pdf)
now use standalone trampoline functions + context structs
instead of captured lambdas.

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

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 14:56:15 -06:00
Behdad Esfahbod 98f3a42ee2 [vector/raster/gpu] Add *_glyph_or_fail() variants across all three
Consolidate the {vector,raster,gpu}_{draw,paint}_glyph APIs
to match the hb_font_{draw,paint}_glyph / _or_fail pattern:

  * Each existing *_glyph() public function now returns void.
    For the draw variants this is purely a return-value drop.
    For the paint variants the void entry additionally gains a
    synthesize fallback for non-color glyphs (calls
    hb_font_paint_glyph instead of _or_fail) so a mono glyph
    still produces output via a foreground-colored outline.

  * New *_glyph_or_fail() variants return hb_bool_t, reporting
    exactly what hb_font_{draw,paint}_glyph_or_fail() would.
    Callers that care about distinguishing color paint from
    synthesized outline now have a clean boolean signal.

Refactors the internal impls behind a shared static helper
parameterised by a `fallible` flag; the two public entries
delegate, passing true (for _or_fail) or false (for the void
alias).

For GPU specifically, paint_glyph_or_fail no longer folds the
encoder's unsupported flag into its return -- that state was
always better reported from hb_gpu_paint_encode() (which
returns NULL), and conflating the two prevented callers from
telling "font has no paint data" from "encoder hit a limit".

While in there, remove a dead branch at the end of
hb_vector_paint_glyph's SVG case (both inner blocks had
already returned; the tail was unreachable).

Updates docs/harfbuzz-sections.txt with the six new symbols
and the NEWS note with the Changed API callouts.  Updates
in-tree callers (hb-vector-svg-all, hb-raster-all, test-gpu,
util/vector-output.hh) to the _or_fail variants where they
previously read the return value.

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

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 00:36:37 -06:00
Behdad Esfahbod d8980e94e0 [draw] Add line/rect/circle drawing helpers (#5925)
* [gpu] Add hb_gpu_draw_line / _rect / _circle shape helpers

The GPU draw encoder already consumes arbitrary curves via the
hb_draw_funcs_t machinery -- that's how glyph outlines feed in.
Expose three convenience helpers so callers can emit common
shapes (tapered line, rectangle, circle) without having to
hand-roll the curve math:

    hb_gpu_draw_line   (draw, x0,y0,w0, x1,y1,w1);
    hb_gpu_draw_rect   (draw, x,y,w,h, stroke_width);
    hb_gpu_draw_circle (draw, cx,cy,r, stroke_width);

stroke_width = NaN means "filled".  A finite positive value
produces a stroked outline by emitting an outer contour CCW
and an inner contour CW so the fill rule carves a hole.

For shapes beyond these three helpers, callers can feed any
outline through hb_draw_move_to / _line_to / _quadratic_to /
_cubic_to / _close_path with the funcs from
hb_gpu_draw_get_funcs() and the hb_gpu_draw_t as data -- the
helpers are thin wrappers over that path.

Useful for game UI: health bars, progress rings, custom
line-art decorations, rendered through the same slug shader
as text.

Assisted-by: Claude <noreply@anthropic.com>

* [util/gpu] Add --show-extents flag

Exercises hb_gpu_draw_rect: when the flag is set, each glyph
blob encodes its ink-extent frame as an extra stroked
rectangle alongside the glyph outline, so the frame is cached
with the glyph and renders with no extra draw call.

The frame is padded outward by stroke_width / 2 so the stroke
sits entirely outside the glyph ink (otherwise the inner half
would knock out against the glyph shape, since both fill in
the same blob).

Cmdline-only for now -- a runtime 'e' toggle would require a
buffer re-shape hook that native hb-gpu doesn't yet expose.

Assisted-by: Claude <noreply@anthropic.com>

* [util/gpu] Cmdline toggles mirroring interactive keybindings

Add --dark / --no-vsync / --fullscreen / --no-stem-darken /
--debug so scripts and CI can start hb-gpu in any of the
states previously reachable only by pressing a key
interactively.  Applied via the same keystroke path by
synthesizing the corresponding key characters through
demo_view_type() at startup -- single source of truth for
each toggle.

Assisted-by: Claude <noreply@anthropic.com>

* [draw] Promote shape helpers from hb-gpu-draw to hb-draw

Three shape-emitting helpers (line, rect, circle) operate on
any hb_draw_funcs_t, not specifically the GPU backend.  Move
them out of the GPU-only API surface into the core hb-draw
API so any pen (raster, vector, gpu, user-supplied) gets
them.

API rename / move:

  hb_gpu_draw_line   -> hb_draw_line   (in src/hb-draw.h)
  hb_gpu_draw_rect   -> hb_draw_rect
  hb_gpu_draw_circle -> hb_draw_circle

Signatures gain a (dfuncs, draw_data, st) prefix to match the
existing hb_draw_move_to / line_to / cubic_to / close_path
shape -- the helpers are thin wrappers over those.

Callers in test/api/test-gpu.cc and util/gpu/demo-font.cc
updated to call hb_draw_* with hb_gpu_draw_get_funcs() and a
local hb_draw_state_t.

Updated harfbuzz-sections.txt with the new entries; removed
hb_gpu_draw_line / _rect / _circle from hb-gpu.h.

Assisted-by: Claude <noreply@anthropic.com>

* [draw] hb_draw_line: NaN second width defaults to first

Common case is a uniform-width line.  Letting @w1 default to
@w0 when NaN is passed makes the call shorter:

  hb_draw_line (..., x0, y0, 4, x1, y1, NAN);  /* uniform 4 */

Mirrors the NaN-as-sentinel convention used in hb_draw_rect /
hb_draw_circle for the stroke_width parameter.

Assisted-by: Claude <noreply@anthropic.com>

* [draw] hb_draw_line: add cap parameter (butt / square)

Add hb_draw_line_cap_t enum with HB_DRAW_LINE_CAP_BUTT (the
existing default behavior) and HB_DRAW_LINE_CAP_SQUARE, which
extends each endpoint along the line direction by half its
local stroke width.

Square caps let four hb_draw_line() calls form a closed
rectangle without gaps at the corners -- a meaningfully
cheaper alternative to hb_draw_rect() for thin outlined
rectangles, since each line's bbox is just stroke_width tall
instead of covering the full rectangle interior.

Round caps not implemented yet; can be added as a third enum
value when a use case shows up.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-15 21:49:45 -06:00
Behdad Esfahbod addaafd255 [vector] Rename svg_{set,get}_prefix to {set,get}_svg_prefix
Verb-then-thing matches the rest of the hb-vector setter/getter
naming (set_precision, set_palette, etc.).  Update the renamed
internal references and the NEWS / harfbuzz-sections.txt entries
to match.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 15:07:05 -06:00
Behdad EsfahbodandClaude Opus 4.6 ca75fd5ff9 [vector] Drop hb_vector_{draw,paint}_{set,get}_flat (#5927)
Flat mode disabled glyph reuse / caching to produce inline-
everything SVG output.  Its main use case was making
hb-vector SVGs safe to concatenate side-by-side in a single
document, but the recently-added svg_set_prefix API solves
that without giving up the cache.  No remaining callers in
tree (util/vector-output.hh's --flat option goes too).

Removes:
  - hb_vector_draw_set_flat / get_flat
  - hb_vector_paint_set_flat / get_flat
  - the `flat` field on both contexts
  - all `if (flat)` / `bool can_cache = !flat` branches
  - the --flat option in util/vector-output.hh
  - the four "flat*" expected files in test/vector/basic
  - the flat_draw / flat_paint params in the vector fuzzer
  - sections-list entries

meson test --no-rebuild green (241/241).

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 15:03:43 -06:00
Behdad EsfahbodandClaude Opus 4.6 ec63b7d921 [docs] Surface API-reference links in each integration section
The integration chapter explained how to use hb-glib /
hb-ft / hb-cairo / hb-uniscribe / hb-coretext / hb-icu but
never linked to the actual symbol pages.  Readers had to
guess the docbook page name to find the function reference.

Add a "API reference: <link>" line at the top of each of
the five C-binding integration sections (Python intentionally
omitted -- uharfbuzz lives outside this manual).

doc-check is green.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 14:40:41 -06:00
Behdad EsfahbodandClaude Opus 4.6 45d2856376 [docs] Link to harfbuzz-world.cc from the install manual
Add a "Single-file build with harfbuzz-world.cc" section
right after the configuration knob list.  Names the
amalgamation file, references the HB_TINY / HB_HAS_*
machinery the section above just covered, and points at
the harfbuzz-world.cc playground + source as a worked
example.

doc-check is green.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 13:46:40 -06:00
Behdad EsfahbodandClaude Opus 4.6 c3b0c4e282 [vector] Add hb_vector_{draw,paint}_svg_{set,get}_prefix
New public API for namespacing SVG output: callers that embed
multiple hb-vector-produced SVGs into the same document can
set a distinct id prefix per context, so hb-vector's short
internal IDs (p<N>, c<N>, clip-g<N>, gr<N>, cg<N>) don't
collide across snippets.

Example collision the new API prevents: page embeds two
hb-vector SVGs produced by different contexts.  Both use
id="clip-g10"; the browser's url(#clip-g10) resolves to
whichever element appears first, so paint layers in the
second SVG get clipped against the first SVG's glyph outline
-- visible as giant unclipped color rects bleeding across
the wrong glyph shape.

With the new API the second caller passes e.g. "b-" as its
prefix; the clash disappears.  Empty/NULL prefix preserves
the existing output byte-for-byte.

Affects every id / url(#...) / href="#..." emission in SVG
output:
  - hb-vector-draw: <path id="p..."> + <use href="#p...">
  - hb-vector-paint: <path>, <clipPath>, <linearGradient>,
    <radialGradient>, <g id="cg..."> color-glyph cache, and
    every corresponding url(#...) / href="#..." ref.
PDF output is unaffected (no ids).

Docs/harfbuzz-sections.txt updated; check-symbols passes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 11:48:54 -06:00
Behdad Esfahbod fd2a6968ab [draw] hb_draw_line: add cap parameter (butt / square)
Add hb_draw_line_cap_t enum with HB_DRAW_LINE_CAP_BUTT (the
existing default behavior) and HB_DRAW_LINE_CAP_SQUARE, which
extends each endpoint along the line direction by half its
local stroke width.

Square caps let four hb_draw_line() calls form a closed
rectangle without gaps at the corners -- a meaningfully
cheaper alternative to hb_draw_rect() for thin outlined
rectangles, since each line's bbox is just stroke_width tall
instead of covering the full rectangle interior.

Round caps not implemented yet; can be added as a third enum
value when a use case shows up.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-15 02:35:10 -06:00
Behdad Esfahbod e731c38975 [draw] Promote shape helpers from hb-gpu-draw to hb-draw
Three shape-emitting helpers (line, rect, circle) operate on
any hb_draw_funcs_t, not specifically the GPU backend.  Move
them out of the GPU-only API surface into the core hb-draw
API so any pen (raster, vector, gpu, user-supplied) gets
them.

API rename / move:

  hb_gpu_draw_line   -> hb_draw_line   (in src/hb-draw.h)
  hb_gpu_draw_rect   -> hb_draw_rect
  hb_gpu_draw_circle -> hb_draw_circle

Signatures gain a (dfuncs, draw_data, st) prefix to match the
existing hb_draw_move_to / line_to / cubic_to / close_path
shape -- the helpers are thin wrappers over those.

Callers in test/api/test-gpu.cc and util/gpu/demo-font.cc
updated to call hb_draw_* with hb_gpu_draw_get_funcs() and a
local hb_draw_state_t.

Updated harfbuzz-sections.txt with the new entries; removed
hb_gpu_draw_line / _rect / _circle from hb-gpu.h.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-15 02:27:43 -06:00
Behdad Esfahbod f6cd414c9f [gpu] Add hb_gpu_paint_set_scale / _get_scale
Mirror the draw API.  hb_gpu_paint_t already had x_scale / y_scale
fields and hb_gpu_paint_glyph() set them directly, but no public
setter / getter -- callers that want to use the paint funcs
without going through paint_glyph had no way to wire the scale.

Add the public setters / getters and route paint_glyph through
them, matching hb_gpu_draw_glyph's pattern.  Document on both
draw and paint that the convenience wrappers call _set_scale.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 19:08:03 -06:00