Commit Graph
16381 Commits
Author SHA1 Message Date
Behdad EsfahbodandClaude Opus 4.8 2b3562ac11 [subset] Privatize shared avar2 varIdx rows before offset compensation
avar2's VarIdxMap may map several fvar axes to the same IVS delta row
(Amstelvar does: GRAD+XOPQ, and YOPQ+YTLC+YTUC). The offset
compensation code wrote a restricted or pinned axis's bias and tent
deltas straight into its delta row, corrupting every other axis that
reads the same row -- a free axis sharing a row with a restricted one
could be off by up to full scale.

Give each offset-receiving axis whose row is shared a private copy of
the row (identical contents, preserving the rebased deltas) via the
new item_variations_t::duplicate_row(), and repoint its varIdx before
the offset loop. Sharers keep the clean row; the varstore optimization
pass re-merges identical rows afterwards.

Ports fonttools commit 0c0efb8ea from its avar2-instancing branch.

Verified with a fontTools spec-pipeline differential oracle: the
corruption (up to 8193 F2Dot14 units on a free axis sharing a row with
a restricted one) is gone. A regression test follows in a later
commit.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 16:35:11 -06:00
Behdad EsfahbodandClaude Opus 4.8 78075840dd [avar] Don't clamp avar2 deltas to ±1 when mapping coordinates
map_coords_16_16() clamped the avar2 delta itself to ±1.0 before
applying it; map_coords_2_14() clamped the mapped result to ±4.0
instead of ±1.0, and its unclamped float->int delta conversion could
overflow on wild fonts. Per the avar2 algorithm (and matching
fontTools' renormalizeLocation), the delta is applied unclamped and
only the RESULT is clamped to [-1, +1]. Since inputs and results live
in [-1, +1], deltas beyond ±2 are equivalent to ±2, so clamp to that
range only to keep the conversion safe.

This matters for offset-compensated avar2 partial instances (from
fonttools, or from hb-subset as of the following commits): the
compensation plus the original deltas legitimately sums beyond ±1.
For example, restricting wght to 100:250:500 on a font whose avar
maps -0.5 -> -0.35 needs, at the new wght maximum together with
wdth at maximum, a combined delta of -1.09 on the wght coordinate;
the old clamp turned the correct final coordinate of -0.09 into 0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 16:34:33 -06:00
Behdad EsfahbodandClaude Opus 4.6 c6b0cd5e07 [subset] Skip GPOS value format optimization for avar2
Don't compute effective value formats using layout_variation_idx_delta_map
when has_avar2 is true. The delta map contains wrong deltas (computed
from intermediate-space coords, not final coords) and could incorrectly
strip device table format flags, breaking GPOS variation references.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-01 12:42:56 -06:00
Behdad EsfahbodandClaude Opus 4.6 483bd446cb [subset] Skip remaining instancing paths for avar2
Add has_avar2 guards to all remaining tables that apply variation
deltas to base values using normalized_coords:
- post: skip MVAR delta application to underline metrics
- OS/2: skip MVAR delta application to typo/win/sub/super metrics
- head: skip updating xMin/xMax/yMin/yMax from instanced bounds
- maxp: skip instancing_update_fields
- glyf-helpers: skip head bounds update from instanced glyphs
- COLR: skip VarStore instancing and paint value delta folding
- BASE: route to non-instancing VarStore subset path

For avar2, base values must remain unchanged because the offset
compensation keeps all variation data in the original coordinate
space.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-01 12:42:56 -06:00
Behdad EsfahbodandClaude Opus 4.6 0428189b2c [subset] Skip glyf instancing and hmtx MVAR for avar2
For avar2 partial instancing, base glyph outlines and metrics must
not be modified. The offset compensation approach keeps gvar data in
old coordinate space, so glyf base values must remain unchanged.

- Skip glyf font creation for instancing (don't apply gvar deltas
  to base outlines)
- Skip MVAR delta application in hmtx/vmtx header update

This was the root cause of the rendering discrepancy: gvar deltas
were being folded into base outlines at intermediate coords, shifting
all glyph metrics.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-01 12:42:56 -06:00
Behdad EsfahbodandClaude Opus 4.6 455c5a11d4 [subset] Fix avar2 offset compensation bugs
Fix two bugs in _subset_avar2():

1. Deduplicate default-delta bias for shared varIdx entries.
   When multiple axes share the same (outer,inner) in VarIdxMap,
   the free-axis loop was adding the default_delta bias once per
   axis, causing double/triple-counting. Track processed varIdx
   values and skip duplicates.

2. Fix DeltaSetIndexMap serialization for NO_VARIATION_INDEX.
   When any axis has NO_VARIATION_INDEX (0xFFFFFFFF), use 4-byte
   width to avoid truncation of the sentinel value.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-01 12:42:56 -06:00
Behdad EsfahbodandClaude Opus 4.6 d171d444b1 [subset] Add avar as dependency for variation tables with avar2
When has_avar2 is true, ensure avar is subsetted before gvar, cvar,
HVAR, VVAR, MVAR, GDEF, and CFF2. This allows avar2 subsetting to
produce state (e.g., self-contained axes) that other tables may need.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-01 12:42:56 -06:00
Behdad EsfahbodandClaude Opus 4.6 a8874e6a31 [subset] Handle fvar axes and instances for avar2 partial instancing
For avar2 pinned axes: set HIDDEN flag and collapse range to
min=default=max=pinned_value instead of removing the axis.
For instance records: keep pinned axis coordinates (they're still
in fvar) instead of skipping them.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-01 12:42:56 -06:00
Behdad EsfahbodandClaude Opus 4.6 4fff04ee22 [subset] Skip variation instancing for avar2 partial instancing
When has_avar2 is true, route variation tables to their non-instancing
code paths that still handle glyph subsetting:
- HVAR/VVAR: use non-instancing VarStore serialization
- GDEF: use non-instancing VarStore subsetting
- MVAR: passthrough (no glyph subsetting needed)
- cvar: passthrough (no glyph subsetting needed)
- cvt: skip delta application
- CFF2: skip blend instancing, preserve glyph subsetting
- gvar: skip instantiate(), use non-instancing glyph subsetting

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-01 12:42:56 -06:00
Behdad EsfahbodandClaude Opus 4.6 c7a8feb80f [subset] Implement avar2 IVS rebasing and offset compensation
Core avar2 partial instancing algorithm:
- Modified avar::subset() to output version 2.0 with identity segment
  maps for pinned axes when has_avar2 is true
- Added _subset_avar2() helper implementing the offset compensation
  algorithm: evaluates default deltas, rebases IVS regions via
  instantiate_tuple_vars_no_region_build(), adds empty-region bias
  and tent deltas per axis, creates new VarData for NO_VARIATION_INDEX
  axes, serializes avarV2Tail with DeltaSetIndexMap and
  ItemVariationStore

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-01 12:42:56 -06:00
Behdad EsfahbodandClaude Opus 4.6 f01deb0030 [subset] Add item_variations_t methods for avar2 instancing
Add instantiate_tuple_vars_no_region_build(), add_vardata(),
get_item_count(), get_vardata_count(), has_nonzero_delta(), and
add_tuple() methods to item_variations_t. These allow manipulating
the IVS tuple representation between rebasing and finalization,
needed for avar2 offset compensation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-01 12:42:56 -06:00
Behdad EsfahbodandClaude Opus 4.6 85ba4a1315 [subset] Add avar2 plan members and v1-only normalization
Add has_avar2 flag and old_intermediates map to subset plan.
Add map_coords_v1_only() to avar that applies segment maps without
avar v2 processing. Modify normalize_axes_location() to detect avar2
partial instancing and compute intermediate-space coordinates using
v1-only mapping.

When avar2 partial instancing is detected, all axes (including pinned)
are kept in axes_index_map so they remain in fvar.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-01 12:42:56 -06:00
Behdad Esfahbod 4509695c78 [gvar] Avoid null checks in tuple scalar cache path (#6045)
Normalize a missing gvar scalar cache to the Null cache before the tuple loop,
so calculate_scalar can use the cache length directly in its fast path.

Keep the fallback from querying a zero-length cache, since that would otherwise
be interpreted as a cached zero scalar.
2026-06-29 16:37:16 -06:00
Behdad Esfahbod 27c96db228 Fix build, second try 2026-06-29 15:59:48 -06:00
Behdad Esfahbod ebaec91a8e Fix build 2026-06-29 15:50:21 -06:00
Behdad Esfahbod 049a1d5ecc [gvar] Fast-path cached shared tuple scalars
This ports the shared-tuple scalar fast path from FreeType commit
7c952c1b0d9eac1681dad8de09f5bb193ac1ed40, adapted to HB's logic.
2026-06-29 15:46:49 -06:00
Behdad Esfahbod 760470e91e [raster] Avoid clip mask origin overflow (#6044)
Clip mask extents can have extreme signed origins after malformed
or heavily transformed outlines. Subtracting the surface origin in
int overflowed for cases such as 0 - INT_MIN.

Keep the mask-to-surface coordinate conversion in int64_t until
after intersecting with the finite clip and surface bounds, then
convert to unsigned only for proven in-range pixels.

Add the minimized OSS-Fuzz seed to the raster fuzzer corpus.

Testing: meson test -C build
Fixes: https://oss-fuzz.com/testcase-detail/4621471331450880
Assisted-by: OpenAI Codex <codex@openai.com>
2026-06-29 15:26:24 -06:00
Behdad Esfahbod 46ca5be0bd [rust] Roll versions (#6042) 2026-06-29 09:44:05 -06:00
Behdad Esfahbod afe68c5c1c [rust] Always incoke cargo
It can track dependencies and detect rebuild need better than meson.
2026-06-26 21:09:27 +02:00
Garret Rieger 22d6df2a19 Fix missing addition of idDelta when collecting cmap4 unicodes and mappings. (#6038)
From the spec: The value c is the character code in question, and i is the segment index in which c appears. If the value obtained from the indexing operation is not 0 (which indicates missingGlyph), idDelta[i] is added to it to get the glyph index. The idDelta arithmetic is modulo 65536.
2026-06-24 03:00:52 -06:00
Behdad Esfahbod 5b665b336b [matcher] Leave inlining decision on next/prev to compiler
Forcing this inline speeds up most benchmarks by a few percents,
but at least for the Duployan benchmark, it slows it down by 40%.
This is on Apple silicon.

I had noticed that HarfRust was performing faster on this benchmark,
and after lots of investigation, this force-inline seemed to be the
culprit.
2026-06-21 23:30:06 +01:00
Behdad Esfahbod 336958bd15 [GDEF] Slight speedup in mark-set lookup
Avoids the nonnullptr overhead. 1% speedup in Duployan benchmark.
2026-06-21 10:12:37 +01:00
Behdad Esfahbod 9e6929319b [rust] Use harfrust table-backed font API (#6036)
* [rust] Use harfrust table-backed font API

* [rust] Roll HR forward
2026-06-20 12:18:56 -06:00
Qunxin Liu ac0979b6f4 [subset] fix bug in math table
Don't keep constructions for glyphs that are only added during math closure,
since we don't do recursive closure over math table.
2026-06-18 16:13:24 -06:00
Qunxin Liu f2dd8dcb81 [subset] do math closure before gsub closure 2026-06-18 16:13:24 -06:00
Behdad Esfahbod ce1228bf5a [blob] Fix a pathological int overflow issue (#6034) 2026-06-17 02:04:23 -06:00
j0j1j2 72dfc30899 [hangul] Apply 'calt' feature to non-Hangul characters in Hangul runs (#6030) 2026-06-16 13:55:17 +02:00
Qunxin Liu 9c7f4dffe5 [subset-repack] add additional sorting after extension promotion (#6033)
assign_spaces() requires correct topological ordering to find space
roots, so add an additional topo sorting after extension promotion and
table splitting to keep thing sorted
2026-06-16 01:48:35 -06:00
Behdad Esfahbod e113622a98 Merge pull request #6028 from harfbuzz/sanitizer-fixes
Sanitizer fixes
2026-06-11 18:42:05 +02:00
Behdad Esfahbod ba4f5824ba [meson] Set CMake import libraries for Windows DLLs (#6027)
The Meson-generated CMake package described Windows shared-library
targets with IMPORTED_LOCATION pointing at the import library. CMake
expects DLL imported targets to put the runtime DLL in
IMPORTED_LOCATION and the import library in IMPORTED_IMPLIB.

Generate bindir-aware paths for Windows CMake packages and set both
target properties for all HarfBuzz imported targets. Static and
non-Windows shared builds keep their existing single-location behavior.

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

Testing:
meson setup build --reconfigure
meson compile -C build
meson test -C build
MinGW cross configure/build/install in /private/tmp
CMake consumer configure/build against harfbuzz::harfbuzz and harfbuzz::subset

Assisted-by: OpenAI Codex
2026-06-11 13:48:12 +02:00
Behdad Esfahbod 8565202817 [AAT] Size Lookup null object storage correctly
The AAT Lookup null object intentionally starts with format 0xFFFF so
lookup dispatch treats it as unsupported. However, its specialized null
storage was declared as only two bytes, while Null(Lookup<T>) is returned
as a Lookup<T> reference.

Declare enough storage for the current Lookup<T> object size so binding
the null reference is well-defined, while preserving the invalid format
bytes.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-11 10:27:07 +02:00
Behdad Esfahbod fa417b9a77 [CFF] Check numeric conversion to int
Malformed CFF dictionaries can contain real operands outside the
representable range of int. Avoid converting those values directly in
number_t::to_int(), and make arg_stack_t::pop_int() set the interpreter
error when the checked conversion fails.

Also make in_int_range() test the stored double value before converting,
so serialization-side range checks do not depend on an unchecked
conversion.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-11 10:22:09 +02:00
Behdad Esfahbod 32d8dc6fb9 [COLR] Sanitize composite mode before paint callbacks
COLR PaintComposite stores its composite mode as an untrusted table
byte, while the paint callbacks take hb_paint_composite_mode_t. Avoid
casting unsupported table values directly to the public enum. Map
unrecognized values to CLEAR, as required by the COLR table comment,
before calling push_group_for() and pop_group().

Also drop the duplicated COLR-side composite mode enum values and use
the public paint enum names for the accepted values.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-11 10:14:23 +02:00
Behdad Esfahbod 259cd49044 [build] Drop empty translation units (#6025)
GCC LTO can emit weak filename-derived placeholder symbols for empty
translation units, and those symbols can leak from shared libraries on
ELF builds.  The stricter check-symbols test added for weak symbols then
catches names such as hb_raster.cc.<hash>.

Remove the empty hb-raster.cc and hb-subset-cff2-to-cff1.cc units from
the build and tracked amalgamations.  Move the raster section docs to
hb-raster-image.cc, which remains part of the raster library.

Testing:
meson test -C build

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6021
Assisted-by: OpenAI Codex
2026-06-08 10:19:32 -06:00
Khaled Hosny b582759c0d [ot-layout] Fix docs typo
These function take a font not face as input.
2026-06-08 11:25:18 +03:00
Khaled Hosny 56feae4035 14.2.1 2026-06-02 14:30:59 +03:00
Behdad Esfahbod 8beb229a4c [gen-tag-table] Generate bytes instead of str in rust output (#6017) 2026-06-02 03:11:23 -06:00
Fuqiao Xue 6dda1a083c Add HB_SCRIPT_KATAKANA_OR_HIRAGANA (#5995)
* Add HB_SCRIPT_KATAKANA_OR_HIRAGANA

Fix #1473.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Assisted-by: Google Antigravity

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

For development purposes.

* [rust] Use new HarfRust GlyphFlags getter

Faster.

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

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

Testing:
meson test -C build

Assisted-by: OpenAI Codex
2026-05-30 08:48:03 -06:00