Commit Graph
187 Commits
Author SHA1 Message Date
Behdad Esfahbod 9af58580c6 [subset] Merge main into the condition precision branch
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>
2026-10-05 18:51:15 -06:00
Behdad Esfahbod 366065c366 [subset] Preserve large condition biases and delta residuals
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>
2026-10-05 18:11:53 -06:00
Behdad Esfahbod 726f2266e6 [subset] Wait for GDEF before instancing GSUB conditions
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>
2026-10-05 18:04:51 -06:00
Behdad Esfahbod 8a9b58c30f [subset] Scan later PairPos rows when instancing device values
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>
2026-10-05 18:04:26 -06:00
Behdad Esfahbod 152313c8cc [VARC] Apply constant deltas in static fonts (#6315)
* [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>
2026-10-02 18:01:26 -06:00
Behdad Esfahbod c042c00839 [VARC] Preserve precision when accumulating 32-bit deltas (#6314)
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>
2026-10-02 17:17:10 -06:00
Behdad Esfahbod 49d6ba3fa4 [subset] Preserve precision in variable layout conditions
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>
2026-10-02 14:14:29 -06:00
Behdad Esfahbod 1c06f05453 Merge pull request #5655 from harfbuzz/beyond-64k
[beyond-64k] Update to final ISO Open Font Format 5th edition standard
2026-10-02 13:07:46 -06:00
Behdad Esfahbod bd079077d2 [VARC] Update the variation-store binary format (#6312)
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
2026-10-02 12:58:52 -06:00
Behdad Esfahbod e5ce527941 [cff2] Support VARC glyphs beyond the CharStrings INDEX
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>
2026-10-02 06:43:14 -06:00
Behdad Esfahbod 955770eaa8 [subset] Preserve universal first-match records after axis pinning
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>
2026-10-02 06:20:51 -06:00
Behdad Esfahbod 81b68595b1 [subset] Instance FeatureVariationRecord condition formats 2-5
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>
2026-10-02 04:49:46 -06:00
Behdad Esfahbod 92f0aa24f9 [test] Cover static VARC axes without fvar (#6260)
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>
2026-09-14 15:30:54 -06:00
Behdad Esfahbod 74fc05cd14 [subset] Address VARC review findings 2026-09-07 12:10:33 -06:00
Behdad Esfahbod 23a0aa4746 Merge branch 'main' into avar2-instancing 2026-07-30 12:20:25 -06: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
Khaled Hosny f3dea1e602 [subset] Add HB_SUBSET_FLAGS_CFF_IDENTITY_CHARSET
When set and subsetting a CID-keyed CFF font, the output charset is
written as identity: CID = new GID.
2026-07-27 22:12:16 +03:00
Behdad EsfahbodandClaude Opus 4.8 dfa9711dc9 [test] Add avar2 self-contained axis tests
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>
2026-07-03 18:57:00 -06:00
Behdad EsfahbodandClaude Opus 4.8 7c87fea07e [test] Add avar2 variation-culling tests
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>
2026-07-03 18:57:00 -06:00
Behdad EsfahbodandClaude Opus 4.8 37b92ed336 [test] Add avar2 partial-instancing differential tests
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>
2026-07-03 16:35:49 -06:00
Behdad Esfahbod 6a0bcf4318 [VARC] Fix test fonts glyphDataFormat (#6046) 2026-07-02 14:01:19 -06: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
Qunxin Liu 77d073044e [subset] fix HVAR encoding width (#5523) 2025-09-02 15:40:51 -06:00
Khaled Hosny 2d8e5255f3 [test/ot-math] Add a test for the Cambria Math workaround 2025-04-06 02:48:49 +02:00
Khaled Hosny ed558e5da4 [test] Add name table to test/api/fonts/glyphs.ttf
Some version of Wine fails to load the font otherwise.
2025-03-23 01:28:41 +02:00
Matthias Clasen 41e14f7029 [test-paint] Use latest test fonts
Update the color test fonts from https://github.com/googlefonts/color-fonts/
repository and update the test results.
2025-03-07 10:48:46 -07:00
Khaled Hosny 4d1f6e049c [COLR] Enable COLRv0 support in get_extents()
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.
2024-10-07 13:24:14 -06:00
Behdad Esfahbod 0037ee281f Merge pull request #4578 from harfbuzz/varc-table
`VARC` table
2024-05-24 08:10:15 -07:00
David Corbett 0db136b1b0 [subset-cff] Shorten output of encode_num_tp 2024-05-12 09:04:02 -07:00
Behdad Esfahbod 6129c72619 [varc] Use Condition instead of ConditionSet
With more Condition formats.

https://github.com/harfbuzz/boring-expansion-spec/commit/df7dcc4618b9dc003740d25c53afe30a8fc03fe2
https://github.com/harfbuzz/boring-expansion-spec/issues/147
2024-04-22 14:52:58 -06:00
Behdad Esfahbod d07d70aef1 [varc] Add test 2024-04-16 17:10:46 -06:00
Christer Sandberg 1ab8822b41 Fixed some errors in STAT table implementation 2024-02-10 07:08:18 -07:00
Garret Rieger 9701b0024e [subset] Always place CFF1/2 char strings at the end of the packed table.
Makes the behaviour from HB_SUBSET_FLAGS_IFTB_REQUIREMENTS the default.
2023-11-06 16:49:09 -07:00
Garret Rieger c6884377ec [subset] Add HB_SUBSET_FLAGS_IFTB_REQUIREMENTS flag.
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.
2023-11-06 16:49:09 -07:00
Behdad Esfahbod c8f6ae1df7 [subset/hvar/retaingids] Synthesize a DeltaSetIndexMap if needed
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.
2023-07-08 20:23:20 -06:00
Behdad Esfahbod 132391ad62 [layout] Add test for font_extents 2023-05-19 16:10:21 -06:00
Behdad Esfahbod 4a735b30c4 [cff2-subset] Update test 2023-02-19 20:39:01 -07:00
Andres Salomon c622c6b883 [font] update the license url for TestGVAREight.ttf
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
2023-01-25 09:27:49 -07:00
Matthias Clasen dd64266ea4 Add a test for glyph extents
This verifies a recent fix for COLRv1 returning
0,0,-1,1 for extents of non-painting glyphs.
2023-01-24 18:08:22 -07:00
Matthias Clasen cca0ed9bcd test-paint: Add variable font tests
These needs freetype master to work.
2023-01-12 21:09:50 -05:00
Garret Rieger 0f01a83622 [subset] add basic test for CFF2 subsetting.
FontTools does not yet support CFF2 subsetting so we can't add a comparison test. Instead add a golden file test.
2023-01-09 21:15:11 -07:00
Matthias Clasen 2a51567925 [paint] Add a test for recursion 2022-12-26 17:00:20 -07:00
Matthias Clasen a7a93b85e6 Drop accidentally added ttx files 2022-12-24 12:08:32 -07:00
Matthias Clasen d00e97f16c Add test-paint to the autotools build 2022-12-24 09:16:29 -05:00
Matthias Clasen 47dbebff39 [paint] Add COLRv0 tests 2022-12-23 13:37:59 -07:00
Matthias Clasen 30a6fd04d0 [colr] Add some tests 2022-12-23 13:37:59 -07:00
Qunxin Liu 8eadb83640 [subset] Update hb_subset_input_override_name_table API
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.
2022-12-02 18:05:53 -07:00
Qunxin Liu 6314aa7da4 [subset] add an experimental API that can override name strings for specified name_id 2022-11-08 14:10:25 -07:00
Garret Rieger af74ab452f [repack] always run the sort in repack.
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.
2022-06-16 15:17:58 -06:00
Garret Rieger 4e11da054d [repacker] update repacker test golden file.
Changed due to removal of Kahn sorting.
2022-05-20 09:41:18 -06:00