Resolve condition-evaluation conflicts while preserving the layout
instancing fixes and main's double-precision and static VARC support.
Tests: full Meson suite (279 passed), and C++11 syntax checks with
HB_NO_VAR, HB_NO_SUBSET_LAYOUT, and HB_OPTIMIZE_SIZE.
Assisted-by: OpenAI Codex <codex@openai.com>
Adding a fractional pinned delta to a large condition default in float
loses its low bits. A scaled 32-bit bias also loses bits when stored in
float tuples, and float variation-store accumulation can erase small
residuals when large deltas cancel.
Use double accumulation for layout condition evaluation and instancing,
keeping ordinary positioning and region-scalar arithmetic unchanged.
Split large biases into float-exact parts, which integer row assembly
combines before serializing a single neutral-region delta.
Add large-default fractional fixtures for GSUB and GPOS, with both
legacy and additive feature variations. Test a positive 1/12288 residual
at cancellation, partial and repeated instancing, and direct evaluation
of 32-bit variation deltas outside float's exact integer range.
Tests: full Meson suite (279 passed), sanitized item-varstore tests,
C++11 reduced-feature checks, and sanitized allocation sweeps over the
new fixtures (2334 full-font attempts and 21 row-encoder attempts).
Assisted-by: OpenAI Codex <codex@openai.com>
GSUB conditions need GDEF's remapped indices and precise condition
values, just as GPOS does. With avar2, GDEF waits for avar, allowing
GSUB to run first unless its dependency is explicit.
Add GSUB to the GDEF dependency and generate identity-avar2 fixtures
for legacy and additive feature variations in both layout tables.
The regressions compare shaping after partial and repeated instancing.
Tests: full Meson suite (279 passed).
Assisted-by: OpenAI Codex <codex@openai.com>
Instancing can add base fields absent from the source value format.
Matching the original format after an early PairSet or class row is
therefore no longer an upper bound on the effective output format.
Disable the early exit when a variation-delta map is supplied. Add
regressions for both PairPos formats and both value records, with a
zero pinned delta in the first row and a nonzero delta in a later row.
Tests: full Meson suite (279 passed), including the new regressions.
Assisted-by: OpenAI Codex <codex@openai.com>
* [VARC] Apply constant deltas in static fonts
Static VARC fonts have no fvar coordinates, but sparse regions without
active axes still contribute constant deltas. Empty coordinate guards
were skipping those deltas in conditions, transforms, and axis values.
Supply an implicit zero coordinate for VARC variation-store evaluation
and remove its coordinate-presence guards. Keep inherited component
coordinates and the shared variation-store evaluators unchanged.
Add a generated static font and drawing/extents regression covering all
three consumers, with both constant and default-inactive regions.
Tests: meson test -C build (281 passed, 1 skipped); C++11 syntax checks
with default, HB_NO_VAR, and HB_OPTIMIZE_SIZE configurations.
Assisted-by: OpenAI Codex <codex@openai.com>
* [VARC] Allow empty coordinates in the multi-item instancer
The region evaluators already treat missing coordinates as zero.
MultiItemVarStoreInstancer is used only by VARC, so remove its
coordinate-presence checks instead of supplying a dummy coordinate
from the VARC caller.
Document why empty coordinates must allow constant VARC deltas, and
the ordinary instancer's existing empty-coordinate shortcut. Leave
ordinary instancer behavior unchanged.
Tests: meson test -C build (281 passed, 1 skipped); C++11 syntax checks
with default, HB_NO_VAR, and HB_OPTIMIZE_SIZE configurations.
Assisted-by: OpenAI Codex <codex@openai.com>
Packed VARC deltas can use the full signed 32-bit range. Converting
them to float before scaling and accumulation loses small residuals
when large contributions cancel, affecting conditions, transforms,
and component axis values.
Accumulate MultiItemVariationStore deltas in double and keep condition
and axis values at that precision until comparison or rounding. Leave
region scalars, drawing transforms, and ordinary variation stores
unchanged.
Add a generated regression font covering all three consumers.
Tests: meson test -C build (281 passed, 1 skipped); C++11 syntax checks
with default, HB_NO_VAR, and HB_OPTIMIZE_SIZE configurations.
Assisted-by: OpenAI Codex <codex@openai.com>
Partial instancing rounds the default and surviving deltas of format-2
layout conditions independently, moving their Boolean boundary and
changing GSUB or GPOS lookup selection.
Rescale variable conditions into private variation-store rows before
integer encoding, leaving shared positioning values unchanged. Prefer
exact integers; otherwise use the available signed 32-bit precision.
Carry defaults outside int16 in a neutral variation region.
Keep source values separate from output mappings so serialization retries
start with the original condition, and make private-row order independent
of source addresses. Propagate store-instancing failures to the serializer.
Add legacy and additive feature-variation fixtures covering nested
conditions, fractional coefficients, large defaults, shared positioning
rows, and a second instancing pass.
Tested: full Meson suite with and without experimental API (279 passed;
261 passed and 1 skipped respectively), C++11 reduced-feature syntax
checks, and C++11 sanitizer builds with failing allocation checks.
Assisted-by: OpenAI Codex <codex@openai.com>
Use a uint32 sparse-region count, region-relative Offset32 axis
references, and an Offset32 reference to the delta-set INDEX. Update
evaluation, sanitization, and subset serialization together.
Migrate all seven affected fixtures. Their logical VARC contents and
non-VARC table bytes are unchanged apart from head checksum adjustment.
Tests: full Meson suite (277 passed), C++11 amalgamation compilation,
and compilation with HB_NO_VAR and HB_NO_BORING_EXPANSION.
Spec: https://github.com/harfbuzz/boring-expansion-spec/pull/175
Offset-base erratum: https://github.com/harfbuzz/boring-expansion-spec/issues/177
Assisted-by: OpenAI Codex
OFF permits CFF2 CharStrings to omit a tail of glyphs provided by
VARC. Accept this count mismatch only when VARC is present, and
validate FDSelect against both the CharStrings and font glyph counts.
Reject malformed explicit FDSelect tables instead of using FD zero.
Add draw and count-mismatch regressions, plus FDSelect format 3 and 4
sentinel checks. The full Meson suite passes: 281 passed, 1 skipped.
C++11 syntax checks pass with extended and reduced features.
Assisted-by: OpenAI Codex <noreply@openai.com>
A satisfied condition set becomes universal when all its conditions are
dropped, even if no remaining condition requested retention. Mark that
record universal and retain it while other axes remain, preventing
later records and an obsolete default catch-all from changing behavior.
Serialize reduced unconditional records with a null ConditionSet.
Regress GSUB and GPOS together, with an earlier conditional record and
LookupVariationRecord ADD_DEFAULT_LOOKUPS interaction. Regenerate the
existing instance goldens for the unconditional-record representation.
Testing: full Meson suite, 281 passed and one expected skip.
Assisted-by: OpenAI Codex <noreply@openai.com>
Legacy FeatureVariationRecords forced non-axis conditions to false when
choosing the new default features. Their empty range maps also compared
equal, discarding distinct conditional records during partial instancing.
Evaluate value and boolean conditions against the original GDEF store
at the new default, classify their surviving ranges conservatively, and
avoid range-only deduplication for complex conditions. Reuse the lookup
condition serializer to fold pinned axes and remap variation indices.
Materialize a false condition rather than emitting a null (true) offset.
Remove the unused condition-subset TODO stubs.
Add GSUB/GPOS coverage with 75 full/partial-instancing comparisons of
glyph selection and advances, covering formats 2-5 and null children.
Testing: meson test -C build (281 passed, 1 skipped); C++11 reduced-
feature syntax checks with HB_NO_VAR, HB_NO_BEYOND_64K, HB_NO_CUBIC_GLYF.
Assisted-by: OpenAI Codex <noreply@openai.com>
Verify that VARC component coordinates can address axes retained in gvar
when a static font has no fvar table.
Tested with the full Meson test suite.
Assisted-by: Codex <codex@openai.com>
Make the coordinate comparison tag-based (self-contained pinned axes
are removed from the instance entirely; their baked contribution is
validated by the rendering checks) and the expected axis count
parametric.
New subtests: pinning opsz (NO_VARIATION_INDEX) off its default drops
the axis and bakes its constant final coordinate; pinning wdth combined
with a wght range restriction drops wdth while wght keeps offset
compensation (including wdth's constant push on wght's final
coordinate, re-added as a free-axis bias). The pin-at-default subtest
now expects wdth to be removed rather than kept hidden.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extend TestAvar2Instance.ttf with a HIDDEN parametric axis XTRA
(driven by wght through a new avar2 delta row, final coord spanning
[-0.2, +0.3]), a gvar table for 'A' (tuples on XTRA inside and outside
the reachable range, on wght, and on GRAD), and an HVAR table with
matching regions.
The new culling subtest restricts wght to 300:400:500 and checks, over
a grid of retained locations, that final normalized coordinates AND
rendering-level outputs (advance width, glyph extents) match the
original font, and that the instanced gvar and HVAR shrank. The
moved-default subtest also gains rendering checks.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add TestAvar2Instance.ttf, a 1.6KB fontTools-built avar2 font with five
axes (wght, wdth, GRAD, XOPQ, opsz), interior avar v1 breakpoints on
wght, XOPQ and opsz, a wght delta row driven by wdth, a single delta
row shared by GRAD and XOPQ (driven by wght), wdth and opsz mapped to
NO_VARIATION_INDEX, and opsz's default near its axis minimum (so a
far-moved default makes the retained avar v1 segment steep in the new
space, the quantization-limited regime for offset compensation).
test-subset-avar2.c checks that a partial instance produces the same
final normalized coordinates (hb_font_get_var_coords_normalized: fvar
+ avar v1 + avar v2) as the original font at the same user-space
location, within 2 F2Dot14 units (5 for the steepest case, chosen one
unit below what dropping the interior-breakpoint collection produces,
verified by mutation testing), over grids of locations including the
exact kink positions. The eleven subtests cover: same-default and
moved-default restriction (both directions), shared-varIdx rows
(restricted, pinned, and both restricted), pinning at and off the
default, a pinned axis driven by a free axis, NO_VARIATION_INDEX axes
(fresh VarData creation), interior avar v1 breakpoints, and steep
moved-far-from-min defaults.
The subtests abort without the three preceding fixes.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
paint_glyph() supports COLRv0 but this code is never reached because of
the early return if version is not 1. This early return seems to be from
before COLRv0 extents were supported.
When enabled the output subset conforms to the requirements for a base font to be patched by IFTB patches. IFTB is a proposed incremental font transfer patch. This new flag is set as experimental. Currently, setting this flag causes the output subset to also use long offsets for outline data in loca/glyf, gvar, CFF, and CFF2.
This change is a version of https://github.com/skef/harfbuzz/commit/3ae2fe2084d96f61d8ad1bbe42a6ef4e62ec830a rebased onto head w/ tests added.
Before we were emitting the entire VarStore rows if advMap
was Null. Instead, synthesize an advMap.
20% speed up in subset_glyphs/SourceHanSans-VF.otf/retaingids benchmark.
The url in the exif data incorrectly links to a proprietary license. However,
permission was granted for distribution under Apache-2 as part of another project,
so link to that project's license instead.
fixes#4062
Override the name string for the NameRecord identified by name_id,
platform_id, encoding_id and language_ids specified by the user.
If a record with specified name_id does not exist, this API will create
a new NameRecord with provided info and insert it to the name table.
This is needed to ensure virtual link ordering constraints are respected when repack is being called from fontTools. For subset usage, repack won't be called if the graph doesn't already overflow so this change doesn't cause any extra work.