MVAR::subset() copied the source valueRecordSize into the output
header but then walked the source array with a typed
VariationValueRecord pointer (8-byte stride) and embedded 8 bytes per
record. For a font whose MVAR uses value records longer than 8 bytes
(valueRecordSize > 8, which the spec and MVAR::sanitize() allow), every
record after the first was read from the wrong offset and the emitted
header described a record array that overlaps the table's own
ItemVariationStore, silently losing metric variations on partial
instancing.
Step through the source records with StructAtOffset at the table's own
valueRecordSize stride, the same way sanitize() and get_var() do, and
declare VariationValueRecord::static_size in the emitted header so it
always matches the 8-byte records that are written. Output for the
usual 8-byte fonts is byte-identical.
Adds a subset regression test (mvar_partial_instance_record_size) built
from NotoSans-VF.abc with its MVAR records re-padded to 12 bytes; its
expected instanced output is byte-identical to the 8-byte
mvar_partial_instance wght=300:600 file and it fails on the unpatched
tree.
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-EJUT4BZL.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
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
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
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
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
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
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
After instancing, GDEF maps all-zero delta rows to
HB_OT_LAYOUT_NO_VARIATIONS_INDEX. copy() still emitted a device with
the out-of-range varidx (0xFFFFFFFF), even though the delta is
already folded into the base value.
Drop the device in that case. gdef_partial_instance is marked
no_fonttools since fonttools keeps the dead device; the
empty_region_vardata and update_def_wght expected outputs are
regenerated.
Tested with: meson test -C build
Assisted-by: opencode
serialize_rangeoffset_glyid() treated every zero idDelta as "this
range needs a glyphIdArray", which is what to_ranges() emits for
non-run ranges. A real run with delta 0 (glyph id == codepoint) got
the same treatment and cost two bytes per codepoint.
Only zero deltas are ambiguous. Check those against the mapping and
keep the ones that are genuinely identity as delta ranges.
Adds a subset test with a small hand-built glyf font whose cmap maps
U+0001..U+0007 to gids 1..7.
Tested with: meson test -C build
Assisted-by: opencode
* [subset] Fix empty ClassDefFormat2 not intersecting class zero
An empty ClassDef (rangeCount == 0) assigns class zero to every glyph, but
ClassDefFormat2::intersects_class() and intersected_classes() reported no
intersection when glyphs is not empty.
Adds a subset test that fails before and passes after.
* [subset] Fix empty ClassDefFormat1 not intersecting class zero
Same bug as the previous commit, in the format 1 variant. When glyphCount is
zero and startGlyphID is zero, `startGlyph + classValue.len - 1` underflows
to 0xFFFFFFFF, so neither of the two comparisons can be true and class zero
is never reported. (With a nonzero startGlyphID it happens to work.)
harfbuzz always serializes an empty ClassDef as format 2, so this is only
reachable with fonts produced by other tools.
Extends the previous test with a hand-built format 1 variant of the font.
An avar version 2 table with a NULL varStore offset is legal and maps
like plain v1 — but partial-instancing it used to fail outright, because
the planner errored against the missing store. Rather than falling back
to the v1 instancing path (which rescales every variation store and is
not always bit-exact), keep such fonts on the avar2 path: mapping
entries that don't resolve to a real store row are normalized to
NO_VARIATIONS_INDEX, mirroring runtime get_delta semantics, and offset
compensation creates the needed delta rows on demand in an empty store.
The instance stays version 2 and bit-exact, and consumers that ignore
the v2 tail still see the renormalized v1 segment maps.
Adds a subset test with a null-VarStore variant of the RobotoDelta test
font; the instancing test fails outright without the fix.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* [instancer] Don't dedup VarStore rows when not optimizing
as_item_varstore dropped duplicate delta rows even with optimize=false,
where varidx_map is left empty and callers rely on original
VariationIndex values staying valid. HVAR/VVAR subsetting uses that
mode when the source table has an implicit (map-less) advance mapping:
any two glyphs sharing identical deltas shifted every following row, so
the synthesized identity map pointed at wrong rows and past the end of
the VarData — advances silently froze or took neighbors' deltas when
partially instancing such fonts (e.g. Source Han fonts).
Fixes https://github.com/harfbuzz/harfbuzz/issues/6068
* [subset] Drop identity advance maps for map-less HVAR/VVAR sources
When the source table uses implicit glyph-id indexing, the subsetter
synthesized an advance DeltaSetIndexMap whose content was the identity
over every output glyph — equivalent to the implicit indexing it
replaced, just bigger. Recognize that case in is_identity () and keep
the output map-less, like fontTools does. Sources that carry a real
map keep one, preserving their form; truncated maps don't qualify since
glyphs past their end share the last value.
retain-num-glyphs expected files regenerated: NotoSansJP-VF.subset.otf
is map-less, and its redundant identity map is now dropped (verified
against fontTools output).
* [test/subset] Test partial instancing of map-less HVAR
ImplicitHVAR.ttf carries an HVAR with implicit (map-less) advance
indexing and deliberately duplicated delta rows, the combination that
broke before the row-dedup fix: rows shifted or fell off the end of the
rebuilt VarData and advances silently froze. Expected outputs are
cross-checked against fontTools varLib.instancer + subset.
Add AdobeVFPrototype_vsindex.otf (already used by test/api): two
VarData subtables with distinct region sets and a charstring-level
vsindex, covering VarData pruning/renumbering, vsindex remapping and
the re-emitted charstring prefix.
Range limiting, pin-one-keep-one, a moved default, and axis dropping,
on AdobeVFPrototype. Expected outputs are hb-subset's own (fontTools
TTX comparison does not apply to CFF2 charstring encodings); they were
verified geometrically against both the original font and fontTools
varLib.instancer output at a grid of locations in the kept ranges.
Used in conjunction with retain gids, when set the num glyphs from the input font will be preserved. Empty glyphs will be inserted as necessary to maintain the num glyphs value. Put under experimental for now.
The test file has been stripped of most tables to avoid checking in a very large font (since it has a high number of codepoints), which causes OTS to fail on missing required tables.
Fixes#5281. Does the closure by default, but I've introduced a new flag and option to disable this behaviour since some users may want to get the minimal set if they know they don't need the mirrored variants.
cmap14 subsetting code was not considering variation selectors in the input unicode set when deciding which variant glyphs to keep. This updates subsetting to only keeps variant glyphs if their variation selector code point is in the input unicodes set.
For https://github.com/harfbuzz/harfbuzz/issues/4911
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.