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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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.
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>
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.
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.
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
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
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
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
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
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
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
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
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
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
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>
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_r3121421428https://github.com/harfbuzz/harfbuzz/issues/5955#issuecomment-4289771142https://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>
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>
* [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
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