Commit Graph
3017 Commits
Author SHA1 Message Date
Behdad Esfahbod 9d044f792d [vector] Clear accumulated content after failed renders (#6363)
Early returns for missing extents, empty PDF paint output, or other
render failures retained content despite the automatic-clear contract.
Move clearing to scope guards in the common draw and paint render
entry points, covering every return for SVG and PDF.

Document the failure behavior. Extend the lifecycle regression to
compare subsequent output with fresh contexts for both formats,
including PDF resources and empty PDF paint renders. The regression
fails before the fix. The full Meson suite passes: 290 passed and one
existing test was skipped. The lifecycle test also passes as C99.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6358
Assisted-by: Codex
2026-10-10 18:33:11 -06:00
Behdad Esfahbod 94e9073251 [raster] Restore background and palette defaults on paint reset (#6361)
Paint reset omitted the background and palette, leaving settings from
the previous render despite its documented default-state guarantee.
Reset both fields and document that clear preserves these settings.

Add coverage for clear, reset, and rendering with a recycled image.
The regression fails before the fix. The full Meson suite passes:
290 tests passed and one existing test was skipped.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6356
Assisted-by: Codex
2026-10-10 18:32:30 -06:00
Behdad Esfahbod d89fa94461 [subset] Preserve distinct feature parameters and variations (#6350)
Matching lookup lists alone cannot establish that same-tag features are
duplicates. Different feature parameters carry distinct UI metadata, and
alternate features can have different behavior in each language system.

Compare complete supported parameter data before merging, and preserve
indices referenced by retained feature variations. Fully pinned fonts can
still merge features after resolving their alternates.

Add GSUB/GPOS regressions with differing cv01 character arrays, size
values, ss01 names, and ss02 alternatives, plus identical ss03 controls.
The full Meson suite passes, as do reduced-feature compilation checks.

Assisted-by: Codex
2026-10-10 17:07:29 -06:00
Behdad Esfahbod d45fa42c5a [vector] Restore reset defaults and clear PDF draw resources (#6355)
Vector reset omitted draw colors, paint background, SVG id prefixes,
and custom palette overrides. Restore these defaults while preserving
configuration across clear.

The PDF draw context also kept its opacity resource dictionary and
counter after clear, including automatic clearing after render.
Clear both with the accumulated output so later documents do not carry
resources from earlier renders.

Add regressions for SVG/PDF reset, configuration preservation, custom
palette overrides, and fresh-context PDF equivalence after explicit
clear, reset, and repeated rendering. All three regression groups fail
against the original implementation.

Tested with meson test -C build: 288 passed, 1 skipped, 0 failed.
The vector suite and the issue reproducer pass. The regression also
compiles and runs as C99 with -Wall -Wextra -Werror.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6342
Assisted-by: OpenAI Codex
2026-10-10 16:59:13 -06:00
Behdad Esfahbod 199cae8b28 [buffer] Document message callback lifetime across reset (#6354)
Buffer reset has retained message callbacks since their introduction,
although its documentation promised a freshly created buffer state.
Clarify that callbacks, their associated data, and attached user data
survive reset. Document explicit callback removal and destruction.

Add a regression test for callback-directed lookup skipping after
clear/reset, restoration of ligatures after removal, and exactly-once
destruction on replacement, removal, and final buffer destruction.

Tested with meson test -C build: 287 passed, 1 skipped, 0 failed.
The API test also compiles without buffer messages or OT shaping.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6341
Assisted-by: OpenAI Codex
2026-10-10 16:58:18 -06:00
Behdad Esfahbod fd0c6c9a69 [subset] Preserve parameters and names in alternate features (#6349)
Alternate feature serialization lacks the source feature tag, so it
cannot identify and retain cvXX, ssXX, or size parameters. Name-ID
closure also visits only the original base feature, losing labels
referenced by retained alternates or fully instantiated substitutions.

Carry source tags for retained features after deduplication. Collect
name IDs from the current base feature, retained variation records,
and original features used by catch-all records.

Add ordinary, full, partial, and range regressions for all three
parameter formats in GSUB and GPOS. Ten of twelve regression subtests
fail before the fix. The complete Meson suite passes: 284 tests.
The changed layout units also compile with HB_NO_VAR.

Assisted-by: Codex
2026-10-10 04:12:54 -06:00
Behdad Esfahbod 1bf17d7295 [subset] Allow instancing axes unrelated to VARC (#6265)
Replace the blanket VARC instancing rejection with validation of the
axes referenced by retained components, variation regions, and nested
conditions. Remap those indices when unrelated axes are removed, while
keeping passthrough VARC incompatible with instancing.

Preserve component-internal variation data during avar2 instancing by
avoiding culling based on font-level reachable ranges. Add drawing
comparisons and rejection tests with reproducible fixtures, including
hidden component axes and non-default unrelated-axis pins.

Serialize sparse-region axis references using the revised VARC format.
Regenerate the fixtures without changing their logical VARC contents or
other table bytes, apart from the head checksum adjustment.

Validation: meson test -C build (283 passed); subset suite (130 passed);
C++11 compile checks with HB_NO_VAR and HB_NO_VAR_COMPOSITES.

Assisted-by: Codex
2026-10-10 04:04:32 -06:00
Behdad Esfahbod a2ccf95182 [subset] Preserve IFTB offsets when downgrading CFF2 (#6348)
Pass the requested minimum CharStrings offset size to the CFF1 INDEX
serializer, matching the CFF2 path. The conversion previously emitted
short offsets even with HB_SUBSET_FLAGS_IFTB_REQUIREMENTS enabled.

Add a Cantarell downgrade regression, registered with the existing
IFTB tests only when experimental API support is enabled. The original
subsetter fails it with and without preprocessing.

Full Meson suites pass with experimental API enabled (282 tests) and
disabled (263 tests, one skipped).

Assisted-by: Codex
2026-10-10 01:46:09 -06:00
Behdad Esfahbod 3396dcb35b [subset] Keep original IUP contour points across serialization retries (#6345)
IUP adds rebased constant tuples to the plan's cached contour points.
When serialization needs a larger buffer, another gvar serialization
adds the same constants again. The final optimizer then chooses points
against a different outline than the one stored in glyf.

Copy the cached points before IUP instancing so every serialization
attempt starts from the original contour coordinates. Check allocation
failure through the usual vector error path.

Add a shifted-default Roboto Flex regression that fails on the original
subsetter. The entire configured Meson suite passes (278 tests, one
skipped).

Assisted-by: Codex
2026-10-10 01:13:14 -06:00
Behdad Esfahbod be6a74f303 [subset] Preserve line directions when specializing CFF charstrings (#6346)
hlineto and vlineto alternate directions for successive arguments.
Combining commands by their operator alone changes geometry: two
vertical segments become a vertical segment followed by a horizontal
one. Merging a mixed run also needs its argument-count parity.

Require odd parity before combining opposite starting directions and
even parity before combining identical h/v operators.

Test all 1,020 orientation sequences through eight segments at stack
limits 4 and 48, reconstructing every point after specialization. The
original specializer fails that test. Add a shifted Source Serif
instance and update its existing downgrade reference. The entire
configured Meson suite passes (277 tests, one skipped).

Assisted-by: Codex
2026-10-10 01:12:39 -06:00
Behdad Esfahbod 1e6ea99af7 [subset] Preserve deltas when a contour exceeds the IUP set limit (#6344)
The IUP optimizer returns success for contours larger than its 512-bit
sets can represent, leaving every optimized reference false. The
resulting partial instance loses the contour's variation data.

Keep all explicit references when skipping optimization at that limit.
This preserves the existing bounded search without changing geometry.

Add a 600-point contour regression. The original subsetter fails both
normal and preprocessed checks. The entire configured Meson suite
passes (278 tests, one skipped).

Assisted-by: Codex
2026-10-10 00:36:51 -06:00
Behdad Esfahbod 372119f1df [subset] Clamp fully instantiated COLRv1 alpha before narrowing (#6343)
Variation deltas can take solid and gradient stop alpha outside [0, 1].
Narrowing those values to F2DOT14 before clamping wraps alpha 2 to -2
and alpha -3 to 1, reversing the intended opacity.

Clamp full instances in float before storing alpha. Keep partial bases
unclamped because surviving axes can bring them back into range.

Add synthetic solid and gradient regressions for overflow, underflow,
and a partial base of 1.5 reduced to 0.5 by the retained axis. The old
subsetter fails four full-instance checks; the entire configured Meson
suite passes (278 tests, one skipped).

Assisted-by: Codex
2026-10-10 00:30:06 -06:00
Behdad Esfahbod d997502000 [meson] Guard tests for disabled optional libraries (#6335)
* [meson] Skip vector tests when vector is disabled

The vector budget test was built unconditionally even when vector was
explicitly disabled. Its empty dependency supplied neither include paths
nor libraries, breaking otherwise valid reduced-feature builds.

Skip the vector test directory when the library is disabled. Add a Linux
CI build and test pass with vector disabled to cover this configuration.

Reproduced the missing hb.h failure on Linux before the fix. The full
suite with vector, raster, and GPU disabled passed 229 tests with one
skip; all three vector tests passed with vector enabled.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6277
Assisted-by: OpenAI Codex <codex@openai.com>

* [ci] Remove extra vector-disabled build pass

Keep the fix focused on guarding the vector test directory without adding
another build and test pass to the Linux workflow.

CI-only change; the previously validated Meson guard is unchanged.

Assisted-by: OpenAI Codex <codex@openai.com>

* [meson] Guard dependency fuzzers when subset is disabled

With experimental APIs enabled, dependency fuzzers referenced
libharfbuzz_subset even when the subset library was disabled, causing
Meson setup to fail with an unknown-variable error.

Require subset support when building the dependency fuzzers and when
registering their tests.

Full tests with experimental APIs enabled: 92 passed with subset
disabled, and 247 passed with subset enabled. Both dependency fuzzers
and their 13 tests remain registered in the enabled configuration.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-07 12:55:53 -06:00
Behdad Esfahbod bf0828e9f4 [set] Restore sorted-array additions to inverted sets (#6333)
Adding a sorted array to an inverted set delegates to the underlying deletion path, but set_sorted_array() always added bits. Excluded members stayed excluded, and existing included members could become excluded.

Use the requested bit value, as set_array() already does. The regression covers duplicates, excluded and included members, and both existing and absent pages.

Assisted-by: OpenAI Codex
2026-10-07 12:19:48 -06:00
Behdad Esfahbod 0529c75459 [vector] Preserve contents on self-copy assignment (#6331)
Copy assignment resets the destination before reading the source. When
they are the same vector, this also clears the source. In particular,
hb_set_set(set, set) loses the set's stored pages.

Return immediately for self assignment. Cover trivial and nontrivial
vector elements and public set assignment in both inversion modes.

Validation: both regressions fail before the fix; meson test -C build
passes (261 passed, 1 skipped).

Assisted-by: OpenAI Codex
2026-10-07 12:16:05 -06:00
Behdad Esfahbod 3957e16e6c [set] Skip empty pages during reverse iteration (#6332)
Deleting the last member of a page leaves an empty page in the sparse set. `hb_bit_page_t::get_max()` returned zero for that page, so reverse iteration could report a value that was never in the set. For example, add and delete 512, then iterate backward from 1024: HarfBuzz reported 512 from an empty set.

Return INVALID for an empty page, matching get_min(), so previous() skips it. Cover reverse scalar/range iteration with retained empty pages, including inverted sets.

Assisted-by: OpenAI Codex
2026-10-07 12:09:14 -06:00
Behdad Esfahbod c22ae24405 [set] Reject unequal populations when comparing mixed inversion (#6329)
The mixed-inversion equality path compares zipped iterators, which stop
at the shorter set. An empty set therefore compares equal to a full
inverted set, as does any matching finite prefix.

Check populations before comparing members and add regression coverage
for empty sets and matching prefixes in both argument orders.

Validation: meson test -C build (261 passed, 1 skipped).

Assisted-by: OpenAI Codex
2026-10-07 12:06:58 -06:00
Behdad Esfahbod 4981dcc115 [set] Seek batch iteration correctly across missing pages (#6330)
When the cursor's page is absent, bfind selects the next stored page.
Using the cursor's offset in that different page can skip its members,
or skip the entire page when the cursor ends on a page boundary.

Apply the cursor offset only when the selected page matches its major
index. Cover batch and scalar iterator agreement across missing pages
for both ordinary and inverted sets.

Validation: the new regression fails before the fix; meson test -C build
passes (261 passed, 1 skipped).

Assisted-by: OpenAI Codex
2026-10-07 12:05:32 -06:00
Behdad Esfahbod a52249ff62 Merge pull request #6326 from harfbuzz/fix/cff2-fdselect-varc
[subset] Bound CFF2 FDSelect lookups by the CharStrings count
2026-10-06 19:34:36 -06:00
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
Yuxi Liu 12ee77ee00 [test] Add fonts with out-of-range GSUB/GPOS lookup types (#6319)
Two fuzzed fonts whose GSUB has lookups with types like 3586 (0x0E02)
and 7432 (0x1D08). HarfBuzz's sanitizer rejects the table, so the text
shapes to .notdef glyphs with no lookups applied. HarfRust truncated the
type to u8 and ran them as types 2 and 8 (MultipleSubst and
ReverseChainSingleSubst): a single "A" became 2048 glyphs
(harfbuzz/harfrust#484).

Tested with `meson test -C build` (harfbuzz suites: 252 ok, 8 skipped).

Assisted-by: Claude
2026-10-04 14:03:22 -06:00
Behdad Esfahbod 5d86ce2980 [rust] Keep disjoint interleaved fields on the batch path
Overlapping bounding ranges do not imply that strided input and output
slots overlap. For equal strides, check field separation modulo the
stride, including the gap across record boundaries. Share this check
between advances and vertical origins.

Cover interleaved glyph/position records and hb-ot-normalize's mapping
from codepoint to var1.u32 within the same glyph-info array.
Tests: full Meson suite (281 passed, 1 skipped), using opt-level=0 for
Clippy's nightly compiler workaround. An exhaustive standalone check
covered 3,136,320 stride/offset/count layouts. Seven-run medians for
interleaved Roboto improved 2.64x for horizontal advances, 22.77x for
vertical advances, and 1.77x for vertical origins.

Assisted-by: OpenAI Codex
2026-10-03 19:32:19 -06:00
Behdad Esfahbod cdf5edb49e [rust] Batch Fontations vertical origins
Register the vertical-origins batch callback. Compute X using HarfBuzz's
batched horizontal advances, then compute Y with v_origin_y_batched.
Retain HarfBuzz line and glyph-extents callbacks for fallback behavior.
Preserve scalar write order for aliased inputs, overlapping outputs, and
repeated X slots while batching normal interleaved position buffers.

Add default/varied glyf, CFF, and CFF2 coverage with strided, unaligned,
in-place, repeated, invalid-glyph, and zero-count queries.
Tests: full Meson suite (281 passed, 1 skipped); font-only Clippy; unchanged
144-case metric snapshots. Another 48 full-font batch cases (53,622 glyph
origins) matched the old scalar implementation. Clippy used opt-level=0
for the nightly compiler workaround.

Seven-run origin medians improved about 19% overall, about 36-38% for
unvaried glyf fonts; varied glyf and CFF/CFF2 remain dominated by extents.

Assisted-by: OpenAI Codex
2026-10-03 19:19:55 -06:00
Behdad Esfahbod 71fc895c78 [rust] Scope strided output references to each metrics batch
Replace safe pointer helpers that manufactured static mutable references
with explicit unsafe reads/writes and a callback-scoped output iterator.
Compute byte offsets in pointer width. Preserve direct batch writes for
aligned, disjoint buffers; use stack outputs for unaligned, repeated, or
overlapping slots without allocating or creating aliased references.

Add unaligned nominal/advance, padding, repeated output, and in-place
advance coverage. Tests: full Meson suite (281 passed, 1 skipped), font-only
Clippy, and unchanged 144-case metric snapshots. Clippy used opt-level=0
for the nightly compiler workaround.

Seven-run medians across 36 nominal/horizontal/vertical advance cases,
compared again with the saved old library on one CPU, showed no slowdown:
nominal about 6% faster, horizontal unchanged, vertical about 36% faster.

Assisted-by: OpenAI Codex
2026-10-03 19:11:51 -06:00
Behdad Esfahbod 59e454c899 [rust] Reuse Fontations instances when coordinates are unchanged
Font serial changes include scale changes, which need not discard the
read-fonts instance's variation and metrics caches. Compare normalized
coordinates using the builder's padding, truncation, and default-location
rules, and rebuild only when the effective coordinates change.

Test scale changes, zero coordinates, omitted axes, extra axes, and resets
against fresh Fontations instances. Preserve existing rounding behavior.
Tests: full Meson suite (281 passed, 1 skipped); 144 font/scale/location
snapshots matched the previous implementation. Clippy used opt-level=0
for the nightly compiler workaround.

Assisted-by: OpenAI Codex
2026-10-03 19:03:23 -06:00
Behdad Esfahbod f902205a0c [rust] Publish the glyph-name cache without replacement
Concurrent readers could replace and destroy a face's reverse-name map
while another reader was using it. Publish with replace=false, reclaim
losing maps, and retrieve the winner. Return failure if publication fails
without a winner instead of retrying indefinitely on allocation failure.

Add a concurrent initialization regression that fails before the fix.
Tests: full Meson suite (281 passed, 1 skipped). Clippy used opt-level=0
to avoid a nightly compiler timeout; library compilation remained opt=3.

Assisted-by: OpenAI Codex
2026-10-03 18:58:43 -06:00
Behdad Esfahbod 600f1cc8ae [rust] Use read-fonts model for Fontations font functions
Move character mapping, line and glyph metrics, vertical origins, and
glyph names to the new Font model. Use its batched advance APIs while
preserving horizontal rounding and HarfBuzz fallback callbacks.

Share the blob owner with the shaper and remove the metrics lifetime
transmute. Enable two existing vertical variation regressions for
Fontations and add strided batch advance coverage.

Tests: ninja -C build lib; meson test -C build (281 passed, 1 skipped).
Font-only and shape-only cargo checks also passed; the shape-only check
used CARGO_INCREMENTAL=0 after a nightly compiler crash.

Assisted-by: OpenAI Codex
2026-10-03 17:25:05 -06:00
Behdad Esfahbod 3c4d303c70 [subset] Bound default UVS ranges to 256 codepoints (#6317)
The dense DefaultUVS copy path merged adjacent source ranges without
respecting additionalCount's 8-bit limit.  Subsetting 257 consecutive
default UVS mappings could leave only one mapping after count truncation.

Start a new range before the additional count overflows.  Exercise cmap
formats 14 and 15 at 1, 255, 256, 257, 512, 513, and 768 mappings, checking
both the retained mapping count and the last variation glyph.

Built with C++11 and ran the complete Meson suite: 279 passed.

Assisted-by: OpenAI Codex
2026-10-02 21:33:22 -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
artemkulyk 95ba917215 [subset/CPAL] Share color record blocks between identical palettes (#6285)
Palette dedup only compared the original colorRecordIndices start.
After subsetting, palettes that differed just in colors that got
dropped keep equal color sequences at different starts, and each got
its own copy of the color records.

Compare the retained colors and reuse the first matching block.
Palettes may share color records; each still exposes the same colors.

Tested with: meson test -C build

Assisted-by: opencode
2026-10-02 16:59:21 -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 bd35da613d [test] Remove disabled advance checks from the obsolete proposal
Delete the remaining dead assertions for the old beyond-64K hmtx
extension, along with their stale adaptation comment. The current
specification uses separate capital-letter tables.

Leave the active legacy-table assertions and fixture unchanged.

Testing: full Meson suite: 281 passed, one skipped.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-02 11:22:24 -06:00
Behdad Esfahbod c034548995 [subset] Preserve the unrounded sign of constant layout conditions
Partial instancing used the rounded positioning delta to fold format-2
conditions. A positive fraction could round to zero and lose a lookup.
Evaluate the original GDEF store at the pinned/default coordinates when
the projected variation index becomes NO_VARIATION_INDEX instead.

Keep integer rounding for conditions with remaining variation and for
ordinary positioning values. The new helper is internal-only.

Extend the legacy condition grid and add an additive lookup regression
using existing fonts. The full Meson suite passes (281 tests, one skip),
including shape and subset suites. All 32 cross-library full/partial
GSUB/GPOS instancing diagnostics preserve the original shaping.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-02 11:09:38 -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 02c6a9f935 [glyf] Preserve cubic control pairing across contours
Starting every contour at its last point rotates all-off-curve cubic
controls by one point, changing the implied curves. Preserve their
original order instead. Reset the second leading control between
contours, and draw a two-control contour as a cubic, not a point.

Add regressions using current MAXP, GLYF, LOCA, HHEA, and HMTX tables
for all-off-curve contours, consecutive contours, and two controls.

Testing: meson test -C build (281 passed, 1 skipped).

Assisted-by: OpenAI Codex <noreply@openai.com>
2026-10-02 04:31:02 -06:00
Behdad Esfahbod 95f11782f1 [test] Remove obsolete loca glyph-count checks
The disabled checks reflect an abandoned beyond-64k proposal that
derived the glyph count from loca. Remove them while retaining the
active maxp compatibility and fallback tests.

Testing: meson test -C build (281 passed, 1 skipped).

Assisted-by: OpenAI Codex <noreply@openai.com>
2026-10-02 04:27:54 -06:00
Behdad Esfahbod f072bff4b0 [ot] Exercise GPOS lookup variations
Extend the lookup-variation fixture with a GDEF ItemVariationStore-backed
ConditionValue and a GPOS conditional positioning lookup. This covers
variation-index evaluation, GPOS shaping, and lookup collection while
reusing the existing partial-instancing checks.

Tested with the full Meson suite and OTS validation of the fixture.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-01 20:40:06 -06:00
Behdad EsfahbodandArthur031221 f20f4c20bc [raster] Fix background color and stride handling (#6310)
* [raster] Fix background color premultiplication and stride handling

ensure_initialized()'s background fill had two bugs:

1. The background pixel was built with HB_COLOR(blue, green, red,
   alpha), which packs channels through HB_TAG's bit layout
   (b<<24 | g<<16 | r<<8 | a). Every other pixel in this buffer is
   premultiplied BGRA32 (b | g<<8 | r<<16 | a<<24, see hb-raster.hh's
   SRC_OVER comment: "premultiplied src over premultiplied dst"), so
   the background was both unpremultiplied and in the wrong byte
   positions: a half-transparent red background (blue=0, green=0,
   red=255, alpha=128) filled the buffer with 0x0000ff80 instead of
   the correct premultiplied 0x80800000.

2. The fill then wrote that pixel into a contiguous run of
   width * height uint32_t slots starting at the buffer origin,
   assuming every row is packed at exactly width * 4 bytes. Once a
   caller sets a stride wider than that (row padding, alignment,
   embedding the glyph image inside a larger atlas), the fill drifts
   across row boundaries after the first row, leaving later rows
   partially uninitialized or wrongly colored.

Build bg with color_to_premul_pixel(), the same helper solid fills
already use, and fill row by row using the actual stride.

Added two regression tests in test/api/test-raster.cc:
test_background_premultiplied (default stride, half-alpha background,
checks the stored pixel is premultiplied) and test_background_stride
(stride much wider than width * 4, opaque background, checks every
row).

Assisted-by: Claude

* [raster] Handle unaligned background strides

A caller-supplied stride does not have to be word-aligned, so casting
each row to uint32_t * can perform misaligned stores.

Use hb_packed_t<uint32_t> for the row writes, and exercise an odd
stride in the regression test with byte-wise pixel checks.

Tests: meson test -C build

Assisted-by: Codex <noreply@openai.com>

---------

Co-authored-by: Arthur031221 <levi74108520963@gmail.com>
2026-10-01 20:11:49 -06:00
Behdad Esfahbod 3f39e24e75 [subset] Partially instantiate lookup conditions
Reduce LookupVariationRecord conditions to false, true, or a residual
condition when axes are pinned or restricted.  Fold compound AND, OR,
and NOT conditions, remap value-condition variation indices, and emit a
constant condition when a surviving lookup becomes unconditional.

Extend the test font with a second axis and all condition formats so the
subset tests cover structural, full, and partial instancing behavior.

Tested with the full Meson test suite, targeted Clang HB_NO_VAR and GCC
builds, and OTS validation of the fixture.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-01 19:43:47 -06:00
Behdad Esfahbod c8d6c273fb [subset] Instantiate LookupVariationRecord lookups
Resolve lookup variations at the pinned coordinates and store their final
lookup sets in the subset plan.  Use those sets when serializing the main
Feature tables before dropping FeatureVariations from a full instance.

This reuses the shaping resolver so version 1.0 feature substitutions,
ADD_DEFAULT_LOOKUPS, compound conditions, and GDEF variation data are
evaluated consistently.

Tested with the full Meson test suite and a targeted HB_NO_VAR build.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-01 19:31:11 -06:00
Behdad Esfahbod 3d6677f05c [subset] Preserve LookupVariationRecord tables
Subset FeatureVariations 1.1 lookup records while remapping feature and
lookup indices.  Preserve all condition formats and remap variation
indices used by value conditions.

Keep features with lookup variations distinct during feature
deduplication, since equal default lookup lists do not imply equal
variable behavior.

Tested with the full Meson test suite and a targeted HB_NO_VAR build.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-01 19:25:17 -06:00
Behdad Esfahbod 48d97c4ad1 [ot] Collect LookupVariationRecord dependencies
Include conditionally referenced lookups in layout collection, feature
closure, and GSUB dependency data.  Also retain variation indices used
by FeatureVariations conditions in GSUB and GPOS when remapping the
GDEF variation store.

Tested with the full Meson test suite and targeted HB_NO_VAR builds of
the touched runtime translation units.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-01 19:14:01 -06:00