226 Commits
Author SHA1 Message Date
Behdad Esfahbod c67232c237 Merge pull request #6647 from harfbuzz/test/indic-zero-context
[test] Cover Indic zero-context feature detection
2026-11-11 12:34:33 -06:00
Behdad EsfahbodandClaude Opus 4.8 fd57025171 [syllabic] Record HB_MAX_SYLLABLE_LENGTH cuts so every pass sees the same pieces (#6558)
Since 12b686dad, _hb_next_syllable() cuts syllables longer than
HB_MAX_SYLLABLE_LENGTH at whatever glyph index the walk reaches, and
nothing records that cut.  The Indic shaper's initial and final
reordering (with GSUB features shortening the buffer in between) then
walk different pieces, the deferred pre-base-matra cluster merge never
happens, and hb_shape() returns non-monotone clusters at the default
MONOTONE_GRAPHEMES level for an over-long Indic syllable.

Add hb_syllabic_record_cut(), next to the other shared syllabic
helpers, and call it on each piece from the foreach_syllable() loops
that already exist where syllables are set up in all four syllabic
shapers (Indic, Khmer, Myanmar, USE), and once more in Indic initial
reordering since dotted-circle insertion can push a piece back over
the limit.  Its inline fast path is a single length compare, so it
costs nothing unless a piece reaches the limit.  Only a piece of
HB_MAX_SYLLABLE_LENGTH glyphs that is followed by more of the same
syllable takes the slow path: it cuts the rest of the syllable into
the pieces foreach_syllable() would make, gives every piece but the
last one of two serials that differ from the preceding syllable and
from the last piece (which keeps the ragel serial), so substituted
glyphs inherit it and all later walks see identical pieces, and
merges the whole oversized syllable into one cluster
(merge_clusters at monotone cluster levels, unsafe-to-break
otherwise) so the cut cannot become a line-break opportunity
mid-syllable.  Serials of all other syllables are untouched, so
numbering and wraparound are exactly what the ragel machines
produce.  The cut in _hb_next_syllable() stays as the backstop.

Behaviour change: syllables longer than HB_MAX_SYLLABLE_LENGTH become
a single cluster, where previously each piece got its own clusters.

A regression test with a 68-codepoint Devanagari input is added to
indic-syllable.tests; it fails (non-monotone clusters) on the
unpatched tree.

Tested: meson test (all pass).  hb-shape on hi-words / a 175KB
Devanagari paragraph shows no measurable slowdown.

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-W15T9EXZ.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-10 19:15:38 -06:00
Behdad EsfahbodandClaude Opus 4.8 cd570b6f54 [aat] Match morx language-tag features against ltag without interning the font's tags
Chain::compile_flags() resolved every type-39 (language tag) feature
record by interning the font's ltag string with
hb_language_from_string(), whose process-wide language list is a
linear, never-freed linked list meant for the handful of languages an
application passes in.  A font controls both the number of records and
the number of distinct tags, so shape-plan creation became quadratic
(about a minute for a 125 KB font) and the tags stayed in the list for
the life of the process.

Add ltag::matches_language(i, specific), which compares the tag bytes
directly against the buffer language, applying the same
canonicalization hb_language_from_string() does (at most 63 bytes,
lowercase, '_' to '-', stop at the first other non-alphanumeric) and
the same prefix rule as hb_language_matches(); each record now costs
at most the length of the buffer's language and nothing is added to
the global list.  get_language() is kept for the name table, which
genuinely needs an hb_language_t.  Behaviour is unchanged for every
real tag; only a degenerate tag with no valid leading byte, which used
to become the empty/invalid language, now matches nothing.

Adds a regression font to the in-house aat-morx tests whose type-39
features gate substitutions by tags 'sr' and 'Zh_Hant', exercising
case folding, '_' canonicalization, subtag prefix matching and
non-matches.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-KYZIZMO6.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-02 10:52:07 -06:00
Behdad EsfahbodandClaude Opus 4.8 77be62a733 [aat] Collect LookupFormat2 glyphs in one pass over the segments
The per-subtable glyph sets built by the morx/kerx chain accelerator
assume LookupFormat2 segments are sorted and disjoint, but the
sanitizer does not check that, so a malformed table can repeat a
segment spanning the whole glyph range tens of thousands of times,
and every subtable pointing at it pays a full bit-set pass per
segment -- 300 subtables sharing one 65000-segment lookup stalled
shaping two letters for over 20 seconds.

Make LookupFormat2::collect_glyphs{,_filtered} track the end of the
last range added and, at the first segment that is out of order, fold
every remaining matching segment into a single add_range.  For
well-formed fonts the result is identical; for malformed ones it is a
superset, which is safe because the set is only an intersects()
pre-filter.  collect_glyphs() now shares the filtered implementation
with an always-true filter.  Formats 4/6/8/10 cannot amplify this way
and are untouched.

Adds a morx font with unsorted format-2 segments to the in-house
aat-morx shape tests, checking the subtable still applies.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-A0RYWLIT.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-02 10:52:07 -06:00
Behdad EsfahbodandClaude Opus 4.8 5afb887342 [aat] Index morx chain accelerator entries by subtable position
hb_accelerate_subtables_context_t::dispatch() filled accelerator
entries with a counter that advanced only for the subtable types
ChainSubtable::dispatch() knows, while Chain::apply() reads entries by
subtable position.  A subtable of a reserved type (3, or 6 and up),
which the sanitizer accepts and apply() steps over, shifts every later
entry down by one, so each later subtable is gated by the wrong glyph
set and the last one gets a zeroed entry and is never applied.  Output
then depends on where the unknown subtable sits in the chain.

Add Chain::accelerate(), the same walk Chain::dispatch() does but
setting the context's index to the subtable position before each
dispatch, and stop the context's dispatch() from advancing the index
itself; create() calls accelerate() instead of dispatch().  Unknown-
type subtables keep a zeroed entry, which is what the calloc in
create() already relies on, and apply() does nothing for them anyway.
mort shares Chain/ChainSubtable so it is fixed too; the kerx
accelerator already fills one entry per subtable and is untouched.

Adds a regression font with subtables [reserved, 1->2, 3->1] to the
in-house aat-morx shape tests.

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-OIN1GIHX.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-02 10:51:40 -06:00
Behdad EsfahbodandClaude Opus 4.8 ec4a38c4ab [aat] Fix negative-state arithmetic in StateTable so 'kern'/'mort'
tables with a non-first initial state are accepted

AAT::StateTable numbers the rows before the initial 'kern'/'mort'
row negatively (the Apple stateArray quirk the code documents), but
the negative branch of sanitize() passed the negative int min_state
to hb_unsigned_mul_overflows() and used it in unsigned index
arithmetic, so the overflow check always fired and such tables were
always rejected and silently dropped.  get_entry() indexed the state
array the same unsigned way and would read far past it had sanitize()
let those tables through, so the two functions have to be fixed
together.

sanitize() now works with the magnitude of min_state
(num_neg_states = -min_state) for the overflow check, the
check_range() and the sweep pointer, and get_entry() computes its row
index in signed int so negative states address the rows before the
initial one.  Negative states only arise for ObsoleteTypes, where
nClasses and offsets are 16-bit so the products fit; for ExtendedTypes
states are never negative and sanitize() already bounds
(max_state+1)*nClasses by the blob size, so the (int) casts cannot
change any sanitized index.

Fonts whose 'kern' format 1 / 'mort' state tables use a non-first
initial state now sanitize and apply instead of being dropped.  Adds
a regression test (kern-format1.tests plus its font) to
test/shape/data/in-house.

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-FM7UTB3Y.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-02 10:51:40 -06:00
Behdad Esfahbod e8a7f183fe [paint] Preserve void extents through transformations (#6548)
Honk paints an empty outline as one of its COLR layers. Transforming its
void bounding box orders the sentinel corners into a real rectangle at
(-1,-1)-(0,0), even with the identity transform. That rectangle expands
the accent's ink bounds toward the origin and shifts fallback marks by
hundreds of units.

Keep void extents void when applying a transform. Add shaping regressions
for normal and double scale and vertical layout using a default-instance
Honk subset, with its OFL embedded in the name table.

Current read-fonts already computes the correct COLR bounds. Removing
only the empty layer also makes unpatched HarfBuzz match HarfRust,
confirming the cause of harfrust#553.

Update the existing vertical-origin overflow fixture to use an explicit
COLR clip box. Assert that its height still clamps to INT_MIN so the
original negation-overflow regression stays covered after void bounds
stop producing artificial ink.

Testing: meson test -C build (276 passed).

Fixes: https://github.com/harfbuzz/harfrust/issues/553
Assisted-by: OpenAI Codex
2026-11-01 19:26:02 -07:00
Behdad Esfahbod 0e6a9c81f0 [indic] Fix Unicode 18 shaping and Rust table generation (#6544)
* [indic] Include Unicode 18 Devanagari and Bengali additions

The block filter discarded U+11B0A even though the Unicode 18 data
classifies it as a consonant. Following marks therefore formed broken
syllables and received unwanted dotted circles. The same omission
excluded Bengali Supplement's U+11DF0 and U+11DF1.

Include both blocks and regenerate the Indic table. These three code
points are the only effective classification changes. Add nine shaping
cases using the existing Adobe Blank font, including a valid-syllable
control and an isolated anusvara that needs a dotted circle.

Eight new cases fail before the fix. All 275 Meson tests pass after it,
including the full shaping suite.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6452
Assisted-by: OpenAI Codex

* [gen] Preserve current Rust vowel-constraint buffer access

The shared generator still emitted direct field access through
buffer.cur(), which now returns Option in HarfRust. Regenerating the
file also lost its checked access to output glyph information.

Emit the cur_glyph helper and guarded output lookup already used by
the checked-in Rust implementation. The regenerated Rust functions
match HarfRust after its import adaptations, and the C++ output is
byte-for-byte unchanged.

All 275 Meson tests pass. HarfRust's default and all-feature workspace
tests pass with the regenerated functions.

Assisted-by: OpenAI Codex

* [test] Keep Unicode 18 Indic cases in a dedicated shaping file

Group the new cases in indic-unicode18.tests so HarfRust can import
these generated tests without replacing existing Indic regressions.
Register the file in the in-house shaping suite.

All 275 Meson tests pass.

Assisted-by: OpenAI Codex

* [gen] Emit HarfRust names directly from the shared generators

Generate the Rust module paths, type names, and table symbol prefixes
used by HarfRust at their source. This removes the need for text
rewrites in HarfRust's Unicode-table makefile.

All eight Rust outputs are byte-for-byte identical to the previous
postprocessed outputs. All seven C/C++ generator outputs are
byte-for-byte unchanged, and all 275 Meson tests pass.

Assisted-by: OpenAI Codex
2026-11-01 19:14:23 -07:00
Behdad Esfahbod 90417543fd [aat] Match CoreText kerx format 1 history (#6540)
* [test] Probe CoreText kerx stack behavior

Add native CoreText probes for list reuse, excess values, zero values,
duplicate pushes, repeated actions, resets, and long lists. Run them on
macOS 15 and macOS latest to establish the compatibility behavior before
changing the kerx driver.

The local baseline Meson suite passes all 275 tests. Native execution
is intentionally checked by the new macOS probe jobs.

Related: https://github.com/harfbuzz/harfbuzz/pull/6538#issuecomment-6561986849
Assisted-by: OpenAI Codex

* [test] Probe retained kerx history past eight pushes

Add an end-of-text action after twenty repeated push/action entries to
distinguish retained history from an eight-entry rolling window.

The local Meson suite passes all 275 tests.

Assisted-by: OpenAI Codex

* [test] Probe kerx history wraparound and reset reuse

Add native cases around the eight-slot boundary, actions before the
first push, a first push after ignored glyphs, and history reuse after
reset. These distinguish partial-history initialization and cursor
wraparound for the CoreText compatibility implementation.

Testing: all 275 Meson tests pass with the implementation in progress.

Assisted-by: OpenAI Codex

* [test] Verify kerx reset anchors and Arabic examples in CoreText

Measure a reset followed by another action without a push, and include
both versions of the reported Arabic font. Use mapped glyphs for ignored
prefixes so font fallback cannot affect the native position comparison.

Testing: all 275 Meson tests pass with the implementation in progress.

Assisted-by: OpenAI Codex

* [test] Probe long kerx lists after resetting history

Distinguish how reset initializes unused history slots by applying a
long list after a reset with and without a push, and after every push.

Testing: all 275 Meson tests pass with the implementation in progress.

Assisted-by: OpenAI Codex

* [aat] Match CoreText kerx format 1 history

The written kerx rules describe destructive stack pops and a reset flag.
Native CoreText retains an eight-slot circular history, initializes its
unused slots to the first glyph, and ignores reset. Each action list
walks the history independently and wraps after eight values.

Use that behavior for extended kerx while retaining legacy kern rules.
Bound the longer action-list walks by the buffer operation budget and
keep fixed-size history storage. Document the spec discrepancy and add
regressions for reuse, wraparound, initial slots, reset, and both Arabic
examples, plus terminated and unterminated over-budget lists.

Testing: all 275 Meson tests pass. HB and HR match glyph identities,
character indices, positions, and final extents for all 35 native cases
on macOS 15.8.2 and 26.6.2. Both Arabic examples match their GPOS reference.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6536
Assisted-by: OpenAI Codex

* [ci] Remove exploratory CoreText kerx probe jobs

The native measurements established the compatibility behavior, which
is now covered by the normal shaping regressions in HB and HR. Keep the
manual probe, recorded results, and discrepancy documentation without
adding two native macOS jobs to every pull request.

CI and documentation only; no code or test inputs changed.

Assisted-by: OpenAI Codex

* [test] Run kerx CoreText comparisons with shaping tests

Move the native helper and reference data from .ci into test/shape.
Run the native comparison as a normal CoreText-enabled macOS Meson
shaping test, using the existing macOS CI job. Keep the discrepancy
explanation beside the regression cases and drop the standalone Markdown.

Testing: all 275 Linux Meson tests pass. The comparison runner passes
all 35 recorded cases and rejects an injected position mismatch. The
native helper is unchanged from the macOS 15.8.2 and 26.6.2 measurements.

Assisted-by: OpenAI Codex

* [test] Keep kerx regressions in the shaping suite

Remove the API C budget test, native CoreText C helper, comparison
runner, reference JSON files, and extra Meson test target. Retain the
library fix and normal shaping regressions, with a short explanation of
the native behavior in the shaping test file.

Testing: all 275 Meson tests pass.

Assisted-by: OpenAI Codex
2026-11-01 13:35:37 -07:00
Behdad Esfahbod a92e0996dc [aat] Read kerx format 1 value indices and terminators (#6538)
kerx format 1 entries contain value-array indices and terminate lists
with a separate 0xFFFF word. The shared kern/kerx driver instead treated
the indices as byte offsets and used the legacy kern low-bit terminator.

Keep the legacy kern behavior, but read kerx indices directly and stop
before popping a glyph for 0xFFFF. Validate kerx values as they are read
so a short list can terminate while glyphs remain on the stack. Mark
the dependencies of adjustments to earlier stacked glyphs unsafe to break.

Add regressions for positive and negative odd values, nonzero indices,
short lists, retained stack entries, and glyph flags. All 275 Meson
tests pass, including the shaping suite and both font callback backends.

Related: https://github.com/harfbuzz/harfbuzz/issues/6536
Assisted-by: OpenAI Codex
2026-11-01 11:52:56 -07:00
Khaled Hosny 436f067b20 Merge pull request #6537 from harfbuzz/issue-6535
[aat] Apply kerx format 4 cross-direction mark offsets immediately
2026-11-01 09:28:05 -07:00
Behdad EsfahbodandClaude Opus 4.8 703509a9d9 [GPOS] Bound cross-offset resolution by the glyph count (#6492)
Cursive lookups with different flags can create an attachment cycle.
The const cross-offset walker then follows it forever when attaching
a mark. An acyclic chain over len glyphs has at most len - 1 links;
stop at that bound while retaining every valid forward and backward
chain and the existing offset accumulation behavior.

Add an in-house shaping regression instead of a bespoke unit test:
a tiny payload font whose two cursive lookups (one RightToLeft, one
IgnoreMarks) close an A -> B -> C -> A cycle, with a MarkBasePos that
attaches a mark onto C. Shaping ABCD looped forever before the fix and
now terminates. The original hang is reproduced on the unpatched tree;
the patched build shapes it identically under the ot and ft font-funcs.
The full Meson suite passes (274 tests), including shaping.

Reported by Anthropic's OSS Scanner as ANT-2026-PRD7EFA6.

Assisted-by: OpenAI Codex

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 14:48:18 -06:00
Behdad Esfahbod 88e5077a80 [aat] Read kerx format 2 class values as byte offsets (#6494)
Format 2 class values are byte offsets, but ExtendedTypes::offsetToIndex
leaves them unchanged. Use byteOffsetToIndex to convert their sum to an
FWORD index. ObsoleteTypes retains the existing kern format 2 behavior.

Add a synthetic font and shaping regressions covering negative and
positive kerning, the final array entry, zero classes, missing lookup
entries, and disabled kerning.

The shaping regression fails without the fix. The full Meson test suite
passes, and Helvetica Light's LY, AY, Hi, and HH kerning matches CoreText.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6461
Assisted-by: OpenAI Codex
2026-10-30 12:49:31 -06:00
Behdad Esfahbod d0b38a793b [arabic-fallback] Count components only for matched ligatures (#6474)
A missing component skipped a fallback ligature but left its partial
component list counted. Later ligatures then used the wrong letters.
Write tentative components at the current offset and advance the
count only after every component has matched.

Add a generated GSUB-less font and two shaping regressions, covering
both the wrong ligature and the valid ligature it displaced, with ot
and ft font functions. All four cases fail before the fix. The full
Meson suite passes (293 tests, 6227 in-house shaping subtests).

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-EMRGZ57Y.

Assisted-by: OpenAI Codex
2026-10-29 19:31:29 -06:00
nussaibah shaikh 6c8fe9f278 [aat] Don't divide by zero interpolating duplicate trak tracks (#6425)
* Don't divide by zero interpolating duplicate trak tracks

TrackData::get_tracking() brackets the requested track value (always
0 when shaping) between entries i and j and interpolates with
(track - t0) / (t1 - t0).  The bracketing scan doesn't assume the
entries are sorted or distinct, so two entries that both have track
value 0.0 end with i = 1, j = 0.  That skips the exact-match return
and computes 0/0.  The NaN reaches hb_font_t::em_multf(), where the
cast to hb_position_t is undefined (UBSan float-cast-overflow at
hb-font.hh:1167); in practice the advance becomes INT_MIN on x86 and
the tracking is dropped on arm64.

Sanitize accepts such a table, so any font with STAT plus this trak
reaches it from hb_shape(); the CoreText font funcs call the same
getter.

Handle t0 == t1 the way TrackTableEntry::interpolate_at() already
handles equal sizes, by averaging the two values.

Added a 108-byte font to the aat-trak shape tests.  It fails without
the fix and passes with it.  meson test passes on an ASan+UBSan
debug build.

Assisted-by: Claude

* [aat] Pin duplicate-trak test to ot font funcs

The 108-byte test font only carries STAT and trak, with no head,
hhea or hmtx.  The ot font funcs give each glyph a 500 advance, but
FreeType reports 1000 and DirectWrite refuses to load the font, so
the ft and directwrite runs of the test disagreed with the expected
output.  The test only needs to exercise the trak interpolation,
so pin it to --font-funcs=ot like other minimal-font tests.

Tested with meson test -C build; the shape suites pass with
FreeType enabled.

Assisted-by: Claude
2026-10-27 14:44:18 -06:00
Khaled Hosny 31e8921887 [arabic-pua] Remove mappings for code points with no legacy encoding (#6454)
Fixes https://github.com/harfbuzz/harfbuzz/issues/6451
2026-10-27 12:15:17 -06:00
Khaled Hosny 646b0d8de9 [kbts] Hook up font variations 2026-10-22 17:05:31 +03:00
Khaled Hosny b6baf2123c [kbts] Update to version 2.28g 2026-10-22 17:05:31 +03:00
Behdad Esfahbod 5a1c0c4660 [aat] Keep deleted glyphs in the buffer glyph set (#6433)
Ligature substitutions replace consumed components with DELETED_GLYPH.
The deletion helper did not add that sentinel to the cached buffer glyph
set, so a later state machine triggered by the deleted-glyph class could
be skipped when the buffer started with at least four glyphs.

Record DELETED_GLYPH in the active set, as the other replacement helpers
do. Add a synthetic morx font that ligates glyphs 1,2 into 3, then uses a
deleted-glyph transition to enable substitution 4 -> 5. Cover both the
three-glyph scan and the four-glyph cached-set paths.

Found while reviewing harfbuzz/harfrust#542.

Validation: all 292 Meson test groups pass, including the shaping suite.

Assisted-by: OpenAI Codex <noreply@openai.com>
2026-10-21 19:42:13 -06:00
Behdad EsfahbodandOpenAI Codex 22e7463b59 [GPOS] Keep anchor variation adjustments fractional (#6421)
AnchorFormat3 returned each scaled variation delta as an integer before
subtracting the mark and base anchors. Rounding the two deltas separately
can shift the final attachment by an output unit even with an exact
quarter scalar.

Add float-preserving device queries for anchor resolution. Keep hinting
adjustments and ValueRecord queries on the existing integer path, and
retain the final anchor-difference rounding.

Add ten cases with exact scalars, signed deltas, negative and independent
axis scales. Six fail against the original implementation. The full
meson test suite passes (272 passed, one skipped), as does a reduced
HB_NO_VAR/HB_NO_HINTING compile.

Fixes: #6420

Co-authored-by: OpenAI Codex <noreply@openai.com>
2026-10-19 21:59:14 -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 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 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 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 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 2c05df744c [ot] Support LookupVariationRecord shaping
Parse and sanitize the FeatureVariations 1.1 lookup-oriented records.
Resolve their effective lookup sets while constructing the shape-plan
key so cache entries remain exact without retaining raw coordinates.

Handle ADD_DEFAULT_LOOKUPS, multiple matching conditions, and the
interaction with version 1.0 feature substitutions.  Keep the existing
public FeatureVariations query API behavior unchanged.

Tested with the full Meson test suite.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-01 19:08:11 -06:00
Chris Van Emmerik b58d201455 [test] Add test for format 3 context in Indic blwf detection (#6308)
Noto Sans Bengali builds its ra-phala with a format 3 context lookup in
blwf. The Indic shaper asks would_apply() whether that lookup applies;
HarfRust's ContextFormat3 would_apply was off by one and never matched,
so the ra was taken as the base consonant (harfbuzz/harfrust#482).

Font is a 6 KB subset of Noto Sans Bengali (OFL).
2026-10-01 16:11:36 -06:00
Behdad Esfahbod db981a8baf [gsubgpos] Preserve concat hazards at end of input (#6238)
The RuleSet fast paths filtered out rules requiring another glyph when
the skipping iterator reached the end of the buffer. Unlike the normal
rule walk, that early return did not record the resulting
unsafe-to-concat range.

Keep the end-of-input optimization, but track filtered rules and mark
their concat hazard before returning. Cover both contextual and chained
contextual rule sets with a five-rule font that forces the fast paths.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-09-05 14:44:39 -06:00
Behdad Esfahbod 92e67ef19f [ot] Preserve pair-positioning and ligature concat hazards
A zero-valued PairPos record can select a different, non-zero record
if the second glyph changes, so keep the pair unsafe to concat even
when no positioning was applied.

Likewise, make the ligature second-glyph digest rejection report the
same hazard as the full ligature walk.

Tests: meson test -C build

Port of https://github.com/harfbuzz/harfrust/pull/465

Assisted-by: OpenAI Codex <codex@openai.com>
2026-09-04 19:55:47 -06:00
Dylan PulverandDylan Pulver 2688e6c579 [unicode] Treat U+180F FVS4 as Default_Ignorable (#6229)
U+180F MONGOLIAN FREE VARIATION SELECTOR FOUR was added in Unicode
14.0 and has Default_Ignorable_Code_Point=Yes, but
is_default_ignorable() only covered U+180B..180E, so FVS4 was never
hidden and leaked a .notdef into the output.

8c65442069 ("[Unicode 14] Handle U+180F FVS4") added the U+180F case
to _hb_glyph_info_set_unicode_props() and to the Arabic shaper, but
that branch sits inside "if (unicode->is_default_ignorable (u))", so
it has been unreachable since it was written.  Extending the range to
U+180B..180F makes it live.

U+180B..180F are all Default_Ignorable_Code_Point per
DerivedCoreProperties.txt, so the range stays contiguous.

Before, with a font with no Mongolian coverage:

  $ hb-shape Roboto-Regular.abc.ttf -u U+0061,U+180F
  [1=0+1114|0=0@-908,0+0]

Every other default ignorable (U+180B..180E, U+FE00, U+200B) on that
font shapes to [1=0+1114].  After the change U+180F matches them.

Added two cases to mongolian-variation-selector.tests, which already
covered FVS1, FVS2, FVS3 and MVS but not FVS4: U+180F, and U+1810
MONGOLIAN DIGIT ZERO to pin the top of the range so it cannot be
widened by accident.

Tested with "meson test -C build": 254/254 OK, 0 failures.  Restoring
the old U+180B..180E fails in-house 6174/6176, and widening it to
U+180B..1810 fails the same way.

Assisted-by: claude-opus-5

Co-authored-by: Dylan Pulver <dylanpulver@users.noreply.github.com>
2026-09-03 16:26:30 -06:00
Behdad Esfahbod ebdb43f4d9 [test] Add mort and morx text-rendering tests (#6206) 2026-08-24 14:54:55 -06:00
ff217d3039 [graphite2] Fix cluster values when the buffer was reversed (#6156)
When the requested direction differs from the script's horizontal
direction, the Graphite2 shaper reverses the buffer before segmenting.
Input cluster values then decrease along the buffer, so assigning each
Graphite group the cluster of its base character can leave earlier
characters outside the resulting cluster map.

Preserve the source span of every Graphite glyph while constructing the
output. At monotone cluster levels, seed each glyph from the minimum
endpoint of that span and use merge_clusters() over each Graphite output
range. Keep the historical base-character behavior at non-monotone
levels.

HarfBuzz cluster values are opaque client labels and can be repeated or
gapped. Merging them can therefore coalesce multiple Graphite layout
groups. Preserve the Graphite group index separately for positioning so
every group's advance is emitted even when its HarfBuzz cluster was
merged. Validate Graphite slot source bounds before indexing the input.

Add shape regressions using a subset of Awami Nastaliq and an API test
with repeated input clusters. The latter used to merge the output
clusters correctly but drop an entire layout-group advance, reducing
the total from 3200 to 1269.

Tested with:
meson test -C build test-graphite2
meson test -C build --suite shape
meson test -C build



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

Co-authored-by: Michael Brown <michael.brown@rubicotech.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-22 12:48:13 -06:00
Garret Rieger 49bf947b0a In text-rendering-tests/update.py escape test names sourced from https://github.com/OpenType/fonttest before putting them into meson.build. 2026-08-11 12:27:52 -06:00
Behdad Esfahbod c14ad7c6cb [aat] Fix insertion at end of text (#6142)
Insertion state machines may emit glyphs during the end-of-text transition, when the buffer has no current input glyph. Emit the glyph first in that case and apply AAT metadata to the new output glyph instead of buffer->cur().

Add a regression font whose end-of-text action inserts the AAT deleted-glyph sentinel.

Assisted-by: OpenAI Codex <noreply@openai.com>
2026-08-09 12:37:15 -06:00
Khaled Hosny 6b6f0d9770 [GPOS] Apply mark-attachment cross-direction offsets immediately
Fixes https://github.com/harfbuzz/harfbuzz/issues/4596

See the issue for more details.

Instead of deferring mark positioning to the end of GPOS application, we
now apply cross-direction offsets (y-direction in horizontal text)
immediately and keep applying main-direction (x-direction in horizontal
text) as before.

This is still not 100% compatible with DirectWrite or Core Text (they
apply both directions immediately), but enough to fix the reported
issue.

Based on Behdad’s patch below, but fixes the Noto Nastaliq regression by
resolving the base offset through the whole cursive attachment chain
since cursive offsets are relative the previous glyph and get finalized
only at end of GPOS:
https://github.com/harfbuzz/harfbuzz/issues/4596#issuecomment-2276300688

The remaining failure is not a regression, the new expectation now match
DirectWrite and Core Text.

The tests include a subsetted bug font, as well as two constructed fonts
where curs lookup come before mark ones, once with kern before mark and
with kern after mark, to show that lookup order affects y but not
x-direction.
2026-07-30 23:27:22 +03:00
Khaled Hosny 6cc6d89e05 [GPOS] Count decomposed pieces as one ligature component
Non-first pieces of a MultipleSubst now add no extra component, so a
decomposed glyph absorbed into a ligature counts as the single component
it started as, and its marks attach where MarkBasePos would.

Part of https://github.com/harfbuzz/harfbuzz/issues/4969
2026-07-25 13:35:41 +03:00
Khaled Hosny a49431bcf9 [GPOS] Attach mark to first component of MultipleSubst in MarkLigPos
Do what MarkBasePos already does, so the backward search skips the
leftover pieces of a decomposition instead of giving up on them.

Fixes https://github.com/harfbuzz/harfbuzz/issues/4969
2026-07-25 13:35:28 +03:00
j0j1j2 72dfc30899 [hangul] Apply 'calt' feature to non-Hangul characters in Hangul runs (#6030) 2026-06-16 13:55:17 +02:00
Khaled Hosny 8d24ed6cd6 [arabic-pua] Fix mapping for isolated lam alef maksura ligature (#5985)
Correct the ArabicPUATraditional.txt entry for 0xF295 which should be
isolated not final form. Also enable 0xFC43 ligature so the ligature is
actually used.

Fixes https://github.com/harfbuzz/harfbuzz/issues/5984
2026-05-17 15:24:40 -06:00
David Corbett 27f1be922e [indic] Categorize U+1CF5 and U+1CF6 as CS (#5949) 2026-04-18 19:54:27 -06:00
Behdad EsfahbodandClaude Sonnet 4.6 63fb2eec90 Monotone characters fixups (#5752)
* [buffer] Fix a typo and doc string

* [buffer] Add merge_grapheme_clusters / merge_out_grapheme_clusters

Cluster merges serve two distinct purposes that require different level
gates:

- Grapheme grouping: combining marks merged into their base cluster.
  Correct gate: IS_GRAPHEMES (levels 0 and 3).
  New functions: merge_grapheme_clusters / merge_out_grapheme_clusters.

- Monotonicity maintenance: clusters merged to prevent non-monotone
  output after ligature formation, reordering, etc.
  Correct gate: IS_MONOTONE (levels 0 and 1).
  Existing functions: merge_clusters / merge_out_clusters.

Previously both paths shared merge_clusters_impl's single IS_MONOTONE
gate, so GRAPHEMES (level 3) was incorrectly blocked from merging
grapheme clusters.  This also caused a regression in the Thai and
Hangul shapers for MONOTONE_CHARACTERS (level 1): when their explicit
== MONOTONE_GRAPHEMES call-site guards were removed in #5069, the
impls' IS_MONOTONE gate no longer protected them.

Gates are now in the inline wrappers in hb-buffer.hh; the _impl
functions are gate-free.  hb_form_clusters, CoreText grapheme
detection, and the Thai/Hangul shapers are updated to call the
grapheme-semantic variants.  Fixes #5750.

Fixes https://github.com/harfbuzz/harfbuzz/issues/5751
Fixes https://github.com/harfbuzz/harfbuzz/issues/5750

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* [thai] Adjust grapheme merging logic

* [hangul] Tweak grapheme merging

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-20 11:25:24 -07:00
Behdad Esfahbod e5c227b49b [test] Restructure record-test.sh's a bit
Haven't reviewed, AI code.
2026-02-12 15:26:19 -07:00
Khaled Hosny 46bc4e95f9 [kbts] Update to version 2.0 2025-11-28 12:56:36 +02:00
Behdad Esfahbod 33f8ee8efc [test] Add HarfBust tests 2025-11-10 02:55:44 -07:00
Behdad Esfahbod b11c14227f Match backtrack/lookahead per syllable (#5635)
* [match-backtrack] Fix syllable-setting logic

If accidentally backtrack_len() was equal idx, we were setting
syllable, even though we want to match backtrack, which shouldn't
match syllable.

I'm surprised how this was not exposed before.

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

* Always match backtrack per syllable

* Always match lookahead per syllable as well

* Add Indic test for per-syllable backtrack/lookahead matching
2025-11-04 13:49:52 -07:00
Khaled Hosny 6105bad187 Fix applying synthetic slight to glyph origins (#5629)
* Fix applying synthetic slight to glyph origins

The hb_font_t::get_glyph_[h/v]_origins() methods were applying all the
transformations to the first glyph in the buffer. This shows up for
vertical text only because h_origin callback is usually unset.

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

* Don’t apply slant to glyph origin

Per discussion in https://github.com/harfbuzz/harfbuzz/issues/5628#issuecomment-3459345504

* Disable only font functions that fail
2025-10-29 13:59:51 -06:00
Harry Dalton 780b986659 [shape] Test fallback to kern table under different shapers
More specifically, this asserts that the `kern` table is avoided for
certain shapers, and that we avoid double-spacing in the presence of
`dist` for the same.
2025-10-17 16:26:21 -06:00
Khaled Hosny 189358e3d0 [test] Add test for harfrust#278 (#5610)
Add test case for https://github.com/harfbuzz/harfrust/pull/278
2025-10-14 20:06:26 -06:00
David Corbett e189b34ec9 [Unicode 17] Update the emoji table & cluster test 2025-09-10 11:19:14 -04:00
Behdad Esfahbod 2c22a65f0c [test] Add test for would_apply with multiple subtables
From HarfRust issue:
https://github.com/harfbuzz/harfrust/issues/118
2025-08-08 15:14:16 -06:00