A pinned float region product can be nonzero but subnormal. Multiplying
by a retained axis may then round it to zero, while positive rescaling
of the residual condition removes that threshold and selects a different
substitution after partial instancing.
Detect these source regions and reject affected variable conditions
instead of emitting a false activation. Keep full instancing and ordinary
fractional partial instancing working. Avoid scanning region axes when
their count cannot produce a subnormal product, and handle set OOM.
Add a valid 20-axis fixture and API regression. The partial request
incorrectly succeeds before the fix; controls check source/full output
and an ordinary partial request. The full Meson suite passes: 272 tests,
one skip, no failures.
Assisted-by: OpenAI Codex
Updates read-fonts to 0.46 and skrifa to 0.49, and drops skrifa's older
collections: outlines draw through a ScalerFont, and bitmaps, color glyphs,
palettes and ink extents come from the read-fonts font model. Skrifa is now
only needed for drawing.
Outlines are drawn unhinted at the units per em, which keeps fractional
points as before. Bitmaps are still chosen by the font's ppem. Other ink
extents come from the model, in COLR, VARC, glyf, CFF2, CFF order, so VARC
glyphs and COLRv1 clip boxes now measure as they do with the ot font
functions.
OFF 2026 section 5.3.3.11.2 permits larger ItemVariationStores and
specifies a saturated length field of 65535. Partial CFF2 instancing
currently rejects these stores while serializing them.
Saturate the field while retaining the 32-bit offset size check.
Add a font with 200 referenced regions over 60 axes and exercise
partial instancing and extents at three locations. The test fails
before the fix because the output loses its CFF2 table.
Validation: full Meson suite, 272 passed and one skipped.
Assisted-by: OpenAI Codex
The ordinary CFF2 Private DICT parser ignores hint blend operators but
leaves their raw operands on its stack. Multiple valid blend groups can
therefore overflow the stack during font loading, making glyph extents
and drawing fail. The subset parser already discards these operands.
Clear ignored operands after each hint blend in the ordinary parser too.
Add a synthetic font with two seven-result groups over 40 regions and
check its glyph extents at default and non-default locations. Each group
fits the stack, but their raw operands together exceed its capacity.
The regression fails before the fix and passes after. The complete
Meson suite passes: 272 tests passed, one skipped.
Assisted-by: Codex <noreply@openai.com>
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>
Instancing a CFF2 font with only empty outlines leaves the head bounds
accumulator at its inverted initialization sentinels. These are then
serialized as xMin=yMin=32767 and xMax=yMax=-32767.
Reset an empty accumulator to zero after collecting CFF2 extents. This
also provides a valid FontBBox if the instance is downgraded to CFF1.
Add a reproducible synthetic font and an API regression that fails before
the fix. The regression also checks preservation of the empty glyph's
advance and bearing. The complete Meson suite passes: 272 tests passed,
one skipped.
Assisted-by: Codex <noreply@openai.com>
In C++11 builds, copy-initialization of hb_atomic_t from zero can call
the non-constexpr move constructor and emit a runtime static guard.
HarfBuzz disables thread-safe statics, so concurrent first use races
on that guard before reaching the atomic cache operations.
Direct-initialize all three language caches through the constexpr
scalar constructor. Clang 18 then emits no initialization guards.
Reproduced the shape_threads TSan race on unmodified main using Clang
18 and C++11. With this fix, the full TSan suite passes: 289 passed,
three skipped. The existing shape_threads regression passes too.
Assisted-by: OpenAI Codex
The scalar cache stores floats, so computing uncached tuple scalars and
instancer deltas as doubles made results depend on whether the cache was
used. Restore single-precision calculations throughout the instancer and
update the affected CFF2 partial-instancing fixtures.
The current glyf partial-instancing comparison still matches fontTools,
so it does not need a new no_fonttools opt-out.
Fixes: https://github.com/harfbuzz/harfbuzz/issues/6423
Assisted-by: OpenAI Codex <codex@openai.com>
* [atomic] Use C++11 atomics throughout
Remove the compiler-intrinsic, user-provided, and HB_NO_MT atomic
implementations in favor of the existing std::atomic implementation.
This also allows hb_atomic_t to store floating-point values.
Use direct initialization and a non-constexpr move constructor so the
implementation builds with C++11 on GCC and Clang.
Checked GCC and Clang C++11, HB_NO_MT, HB_TINY, and 32/64-bit MinGW
compilation. The core library also builds without linking libstdc++.
Full test coverage will run in CI.
Assisted-by: OpenAI Codex
* [ot] Cache variation scalars as floats
The scalar cache rounds floats to scaled integers, losing precision for
small values. A variation result can therefore change between its first
calculation and a later cache hit.
Store floats directly in hb_atomic_t and use NaN for empty entries.
Remove the integer conversion and the zero fast path it required.
Add exact round-trip and clear tests for scratch and heap caches,
including a small scalar produced by three variation axes. The test
fails with integer storage and passes with float storage. The core
library builds without a C++ standard-library dependency.
Fixes: https://github.com/harfbuzz/harfbuzz/issues/6416
Assisted-by: OpenAI Codex
* [atomic] Preserve the HB_NO_MT implementation
Keep plain storage and operations when thread safety is disabled,
including HB_TINY, to avoid atomic reference-counting overhead.
Implement these operations directly without restoring the compiler
intrinsics or user-provided atomic hooks.
Checked GCC and Clang C++11 compilation and execution, including the
scalar-cache precision regression under HB_NO_MT, and the HB_TINY
atomic smoke test.
Assisted-by: OpenAI Codex
hb_shape_justify() copies the buffer text so it can reshape while
solving for the axis value, but only the solver path at the end
frees the copy. The three "nothing to solve" success returns
(default advance already in range, maximum expansion still short of
the target, maximum shrink still above it) and the three shaping
failure returns leak it, so ordinary line justification leaks one
text copy per call.
Free it with a scope guard right after the allocation, as the rest
of the tree does, and drop the explicit free at the end.
Reproduced with leaks --atExit on a plain experimental-API build:
four calls on Estedad-VF.ttf give four ROOT LEAKs at hb-shape.cc:319,
none with the fix. Add test-shape-justify.c covering all five paths
under the experimental-API test list so the asan-ubsan job runs it
under LeakSanitizer. The full ASan+UBSan Meson suite passes
(289 ok, 2 skipped).
Assisted-by: Claude
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>
* [cache] Reject out-of-range keys on reads
An empty entry can match an out-of-range key when the packed cache
entry leaves storage bits unused. In the 256-entry binary coverage
cache this reports glyph IDs 32512-32767 as NOT_COVERED, skipping
Context/ChainContext format 2 substitutions and positioning.
Apply the same key range check in get() as set(). Add regression
coverage for spare-bit and full-width entries across all three
storage sizes, with and without atomics.
The new cache test fails before the fix and passes afterward, also
with HB_TINY. All 28 GSUB/GPOS Context/ChainContext boundary cases
pass. meson test -C build: 272 passed, 1 skipped, 0 failed.
Fixes: https://github.com/harfbuzz/harfbuzz/issues/6418
Assisted-by: OpenAI Codex
* [cache] Combine cache miss checks into one branch
Fold the key range check into the existing miss condition using
bitwise operations. XOR the stored and queried tags so their
mismatch can be combined directly with key overflow and the empty
entry check.
Use a scalar empty-entry constant rather than casting through
item_t, which creates temporary atomic objects in GCC builds.
The binary, mapping, and cmap lookup probes now each have one
conditional branch with GCC 15 and Clang 21 at -O2 on x86-64,
compared with two or three in the initial fix.
Testing: meson test -C build: 272 passed, 1 skipped, 0 failed.
All 28 GSUB/GPOS Context/ChainContext boundary cases pass. The cache
regression also passes with Clang and with HB_TINY.
Assisted-by: OpenAI Codex
If retptr failed validation, _name_ptr stayed null and the macro went
on to bind a reference to *nullptr, which a function body would then
write through. Return early whenever the pointer is null.
The macro currently has no users; checked that a sample use compiles.
meson test passes on a -Dwasm=enabled build.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The check meant to catch a failed contours allocation tested
!n_contours instead of n_contours. An allocation failure went
unnoticed, leaving the guest with n_contours > 0 and a null contours
array; the check was otherwise unreachable on success since points
are always accompanied by contours.
Tested: meson test passes on a -Dwasm=enabled build; a wasm module
copying a glyph outline through the allocating path still succeeds.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hb_face_create() takes its own reference on the blob, so the one
returned by hb_blob_create() was never released.
Tested: meson test passes on a -Dwasm=enabled build; a wasm module
calling face_create on a valid blob shapes fine under valgrind.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
buffer_set_contents, face_create, and font_set_coords converted guest
array addresses to native pointers, using nullptr when validation
failed, but then handed the result to hb_memcpy(), hb_blob_create(),
and hb_font_set_var_coords_normalized() unconditionally. A font wasm
module passing an out-of-range address with a nonzero length made the
host copy from NULL. face_create also dereferenced the blob_t
parameter without checking it.
Fail the call when validation fails. buffer_set_contents now
validates before resizing the buffer.
Tested with the reporter's PoC fonts: each now traps in the guest with
"out of bounds memory access" instead of faulting in the host.
meson test passes on a -Dwasm=enabled build.
Reported-by: Ostrolab security team
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
font_glyph_to_string was registered with the WAMR signature "(ii$*)"
while the C function takes (font, glyph, char *s, uint32_t size).
WAMR thus treated the guest's size argument as a pointer and passed
the low 32 bits of its native address as size, defeating the length
bound in hb_font_glyph_to_string(). A font-supplied wasm module could
make the host write a glyph name past the end of the module's linear
memory.
Merely fixing the signature to "(ii*~)" is not enough: when WAMR is
built with hardware bounds checking (the x86-64 Linux default), its
native-call glue skips the size check for '*~' and relies on guard
pages, so an oversized range still faults inside host code.
Take the buffer as a plain guest offset instead and validate the whole
[s, s + size) range with HB_ARRAY_PARAM, which goes through
wasm_runtime_validate_app_addr(). The guest-side ABI is unchanged.
Tested with the reporter's PoC fonts: size now arrives as 144, and a
variant passing size=0x7FFFFFF0 traps with "out of bounds memory
access" before reaching hb_font_glyph_to_string(). meson test passes
on a -Dwasm=enabled build.
Reported-by: Ostrolab security team
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* [layout] Sanitize substitute feature params with their feature tag
FeatureTableSubstitutionRecord sanitized its substitute Feature with
no feature tag, so FeatureParams::sanitize() checked nothing for it.
The subsetter reads those params by the tag of the feature they
replace: Record::subset() when instancing applies the substitutes,
and FeatureTableSubstitutionRecord::subset(),
FeatureVariations::collect_name_ids() and
_features_have_equal_params() since #6349 and #6350. A size, ssXX
or cvXX substitute could thus be read past the end of the table.
Pass the FeatureList down from GSUBGPOS::sanitize() and sanitize
each substitute with the tag of its featureIndex, the tag every
reader uses.
Test: test_feature_substitution_params_sanitize in test-serialize.
Assisted-by: Claude
* [subset] Drop feature params when built without them
With HB_NO_LAYOUT_FEATURE_PARAMS, FeatureParams::sanitize() checks
nothing and collect_name_ids() keeps none of their names, yet
FeatureParams::subset() still copied the params by their tag.
Return false there too, so the subsetter drops them, like the other
FeatureParams readers do in that configuration.
Assisted-by: Claude
---------
Co-authored-by: Mar <mardgez13@gmail.com>
With HB_NO_LAYOUT_FEATURE_PARAMS, FeatureParams::sanitize() checks
nothing and collect_name_ids() keeps none of their names, yet
FeatureParams::subset() still copied the params by their tag.
Return false there too, so the subsetter drops them, like the other
FeatureParams readers do in that configuration.
Assisted-by: Claude
FeatureTableSubstitutionRecord sanitized its substitute Feature with
no feature tag, so FeatureParams::sanitize() checked nothing for it.
The subsetter reads those params by the tag of the feature they
replace: Record::subset() when instancing applies the substitutes,
and FeatureTableSubstitutionRecord::subset(),
FeatureVariations::collect_name_ids() and
_features_have_equal_params() since #6349 and #6350. A size, ssXX
or cvXX substitute could thus be read past the end of the table.
Pass the FeatureList down from GSUBGPOS::sanitize() and sanitize
each substitute with the tag of its featureIndex, the tag every
reader uses.
Test: test_feature_substitution_params_sanitize in test-serialize.
Assisted-by: Claude
* [glyf] Charge composite offsets to the work budget
Composite glyphs prepare component offsets before descending into
children. This work was not charged to the shared rendering budget,
including offsets for children later skipped by cycle detection.
Repeated preparation through COLR extents could time out the shaper.
Charge each offset before loading it and restore the scratch length
on failure. Add a cyclic-composite budget regression and the minimized
fuzzer testcase.
The full Meson suite passes (292 passed, one skipped). The reproducer
completes under ASan/UBSan in 17 seconds instead of timing out after
60 seconds. A failing-allocation variant passes 100 runs.
Fixes: https://oss-fuzz.com/testcase-detail/6193853460447232
Assisted-by: OpenAI Codex
* [glyf] Charge component preparation as traversal work
Component preparation parses records and updates scratch vectors, but
charging one unit per record still allows excessive work within the
shared budget. Use the existing 16-unit glyph traversal charge for
preparing a component, including children skipped by cycle detection.
Increase the cyclic-composite regression's budget so it also catches
the undercharged preparation path. The reproducer now takes about
1.1 seconds under ASan/UBSan and 0.03 seconds in the normal build.
Tested with the full Meson suite (292 passed, one skipped), 100
sanitizer reproducer runs, and 100 failing-allocation variant runs.
Assisted-by: OpenAI Codex
An allocation failure can leave out-of-range glyph IDs in the GSUB
set because subsequent range deletions are skipped. Building the flat
glyph map from that set can then request several gigabytes before the
set's error state is checked.
Reject an errored GSUB glyph set before sizing the flat map, and add
the minimized fuzzer testcase to the regression corpus.
Tested with the full Meson suite (292 passed, one skipped) and 100
reproducer runs under ASan/UBSan with failing allocations enabled.
Fixes: https://oss-fuzz.com/testcase-detail/5574495277219840
Assisted-by: OpenAI Codex
Unbounded variation deltas can overflow integer conversions while
instancing COLRv1 paints and clip boxes. Clamp coordinates, radii,
affine coefficients, and fixed-point values before narrowing them.
Keep affine base precision and existing alpha and clip rounding.
Add a generated font and regression checks for positive and negative
overflow in full and composed instances. Parenthesize the fixed-point
roundf argument so its template comma is safe for macro expansion.
Validation: meson compile -C build and meson test -C build pass
(292 tests passed, one skipped). The font regenerates identically.
Assisted-by: OpenAI Codex
Use the complement of ELT_MASK to align bitset and coverage cursors.
This preserves the masks while avoiding C4146 from negating the
unsigned ELT_BITS constant.
Validation: the build and full test suite pass in build-default
(290 tests). The usual build is blocked by unrelated local
HarfRust/Fontations compatibility errors. MSVC was unavailable.
Fixes: https://github.com/harfbuzz/harfbuzz/issues/6406
Assisted-by: OpenAI Codex
The manual named hb_ot_color_reference_png/svg(),
hb_font_paint_or_fail_glyph(), hb_ft_get_face() and
hb_coretext_face_get_ct_font(), none of which exist. Use
hb_ot_color_glyph_reference_png/svg(), hb_font_paint_glyph_or_fail(),
hb_ft_font_get_face() and hb_coretext_font_get_ct_font().
Assisted-by: Claude Code:claude-opus-5-5
hb_font_set_variation() seeds its new design coords from the font's
existing ones for every axis of the current face, trusting an assert
that their lengths match. hb_font_set_face() keeps the font's
variation coords, which stay sized for the old face, so switching to
a face with more axes and then calling hb_font_set_variation() reads
past the old array: a heap-buffer-overflow read with NDEBUG, an
assertion failure otherwise.
Only reuse the existing design coords when their length matches the
current face; otherwise start from the defaults, as when none are set.
Reproduced the overflow under ASan with NDEBUG and the assertion
failure in the default build. Added a regression test in test-font.c
that fails without the fix. The full ASan+UBSan Meson suite passes.
Assisted-by: Claude
Use has_nonzero_coords when creating a shaping plan, and treat explicit
all-zero coordinates as an empty location in ItemVarStoreInstancer.
A constant GDEF delta then cannot change a condition at the default
instance, matching OFF section 7.1 and the condition's default field.
Keep the Boolean result in the stored int16 default when partial
instancing moves an oversized condition value into a private bias row.
Only the excess belongs in that row, since default instances ignore it.
Add a regression for empty versus explicit default plan keys and shaping
across default, varied, and default locations. Existing subset precision
tests cover the private bias and repeated instancing.
Validation: all 290 Meson test groups pass with experimental APIs enabled.
Assisted-by: Codex
Changing the face now resets font funcs. Deprecate the setter in favor
of creating a new font with hb_font_create() and setting its properties.
Keep the exported symbol and move its declaration to hb-deprecated.h.
Document the deprecation in NEWS and the API section index. Guard the
face-setter tests with HB_DISABLE_DEPRECATED, and suppress expected
warnings from their deliberate use of the deprecated API.
The full ASan Meson suite passes (270 passed, 1 skipped). test-font also
builds and passes with HB_DISABLE_DEPRECATED. Its source passes Clang
-Werror checks both with and without deprecated APIs enabled.
Assisted-by: Claude
Assisted-by: Codex
Font funcs and their data may hold pointers into the font's face.
hb_font_set_face() released the old face but kept those funcs, causing
stale lookups or a use-after-free when the last face reference was gone.
Release the font funcs and their data while the old face is still alive,
then install the default funcs for the new face. Preserve the other font
properties and document the callback reset in the API docs and NEWS.
Add regressions for OpenType lookups and custom font-data destruction.
Reproduced stale glyph lookup and the heap-use-after-free under ASan
before the fix. The full ASan Meson suite passes (270 passed, 1 skipped),
and the two regressions also pass with HB_FONT_FUNCS=ft.
Assisted-by: Claude
Assisted-by: Codex
Use the same count-bounded coverage, class-map filtering, non-null
anchor test, and row-major index selection for MarkBase and MarkMark.
Pass a read-only 16/24-bit offset view after decoding the matrix rows.
Keep typed anchor serialization and the existing vector error behavior.
Saves 5120 bytes at -O3 and 3160 bytes at -Os with GCC 15.3 without
LTO, and 5912 bytes with Clang 21 LTO. The full Meson suites pass with
beyond-64k enabled and disabled; 288 synthetic subset cases match
baseline table bytes, plus 144 cases in the no64 build.
Sampled subset CPU-time geometric means change by +0.82% for ordinary
fonts and -0.55% for variable fonts. The largest ordinary-font change
is +3.42% for Noto Sans Devanagari.
Assisted-by: OpenAI Codex <codex@openai.com>
Expose the source glyphs, values, count, stride, and device-offset
base through a native view. Share effective-format analysis and
variation-index collection without changing typed glyph emission.
Move the value-copy context out of the source-width template too.
Retain the outer scan guard for variable-device instancing and the
existing record-serialization error behavior.
Saves 1576 bytes at -O3 and 128 bytes at -Os with GCC 15.3 without
LTO. The full Meson suite passes and 288 synthetic narrow/wide subset
cases match baseline table bytes. Sampled CPU-time geometric means
change by -1.08% with hint stripping and -0.23% for font instancing.
Assisted-by: OpenAI Codex <codex@openai.com>
Use read-only 16/24-bit offset views to share mark-anchor and
ligature-matrix traversal. Keep count-limited coverage iteration,
row-major index selection, original anchor bases, and null offsets.
The typed wrappers retain table sanitization and field decoding.
Saves 5752 bytes at -O3 and 3272 bytes at -Os in the subset library
with GCC 15.3 without LTO. The full Meson suite passes. Synthetic
16/24-bit subset checks match baseline table bytes in 192 cases,
including variation devices, null matrices, class pruning, and
retain-GID modes. Sampled variable-font subset CPU time changes by
+0.57% overall, with individual cases from +0.24% to +0.79%.
Assisted-by: OpenAI Codex <codex@openai.com>
Resolve the source base, value formats, and matrix dimensions before
analyzing and copying class-pair values. Keep those operations in a
common native view instead of duplicating them in the small and
beyond-64k table instantiations.
Preserve the variable-device scan guard and propagate allocation
failure when collecting retained second-class indices.
Saves 2864 bytes at -O3 and 1336 bytes at -Os in the subset library
with GCC 15.3 without LTO. The full Meson suite passes. Sampled subset
CPU-time geometric means change by -0.56% for ordinary fonts and
-1.55% for variable fonts.
Assisted-by: OpenAI Codex <codex@openai.com>
The coverage iterator needs glyph IDs and the mark-record count, but
zipping in the records gives it a type that depends on the source
width. Zip with a bounded index range instead, retaining the same
truncation when coverage and record counts differ.
Saves 7552 bytes at -O3 and 2112 bytes at -Os in the subset library
with GCC 15.3 without LTO. The full Meson suite passes; sampled subset
CPU-time changes range from -0.18% to +0.83%.
Assisted-by: OpenAI Codex <codex@openai.com>
* [ot] Share mark attachment positioning across table widths
MarkArray::apply instantiates the same positioning and attachment-chain
updates for each mark-array and anchor-matrix representation.
Resolve the format-specific anchors in the wrapper and pass them to a
common helper. Preserve the anchor checks, buffer flags, messages, and
attachment overflow behavior.
With GCC 15.3 on x86-64 without LTO, this removes 1576 bytes of core
code/read-only data at -O3 and 648 bytes at -Os. Validated with the full
Meson suite (292 passed, one skipped) and sampled shaping benchmarks.
Assisted-by: OpenAI Codex <codex@openai.com>
* [ot] Share cursive attachment positioning across table widths
CursivePosFormat1_2 duplicates the direction-dependent positioning and
attachment-chain updates for legacy and beyond-64k entry/exit records.
Keep record access and anchor validation in the format-specific wrapper,
then pass the resolved anchors to a common attachment helper. Preserve
all direction cases, chain reversal, overflow handling, and messages.
With GCC 15.3 on x86-64 without LTO, this removes another 2760 bytes of
core code/read-only data at -O3 and 864 bytes at -Os. Validated with the
full Meson suite (292 passed, one skipped) and sampled shaping benchmarks.
Assisted-by: OpenAI Codex <codex@openai.com>
* [subset] Share mark-class remapping across record widths
Mark classes remain 16-bit values in both mark-record representations;
only the record stride and array count differ. Decode those in the
wrapper and share the class collection and remapping work.
Give the common helper hidden inline linkage so its body is shared
across translation units as well as record formats. Class ordering,
existing mappings, and allocation behavior are preserved.
With GCC 15.3 on x86-64 without LTO, this removes 1152 bytes of subset
code/read-only data at -O3 and 1440 bytes at -Os. Validated with the full
Meson suite (292 passed, one skipped) and subset benchmarks.
Assisted-by: OpenAI Codex <codex@openai.com>
* [subset] Share SinglePos serializers across source formats
SinglePos output serializers only need the source value format and
ValueBase pointer, but carried the full source lookup type through
several template layers. The per-glyph mapper also had distinct lambda
types for legacy and beyond-64k source tables.
Pass the source format and base directly, and use a common mapper with
the same reference captures as the original lambda. Output formats,
device offsets, value copying, and allocation behavior are preserved.
With GCC 15.3 on x86-64 without LTO, this removes 18080 bytes of subset
code/read-only data at -O3 and 9472 bytes at -Os. Validated with the full
Meson suite (292 passed, one skipped) and subset benchmarks.
Assisted-by: OpenAI Codex <codex@openai.com>
* [subset] Share delta substitution subset serialization
SingleSubstFormat1_3 constructs equivalent remapping iterators in each
source-format specialization, giving the output and coverage serializers
distinct iterator types and duplicating their bodies.
Move the subset preparation into a common helper taking the decoded
coverage, delta, and glyph mask. Preserve the glyph intersection,
modular delta calculation, remapping, and serializer failure behavior.
With GCC 15.3 on x86-64 without LTO, this removes 11896 bytes of subset
code/read-only data at -O3 and 5776 bytes at -Os. Validated with the full
Meson suite (292 passed, one skipped) and subset benchmarks.
Assisted-by: OpenAI Codex <codex@openai.com>
* [ot] Share SinglePos optical-bound context setup
SinglePos position_single duplicates the temporary apply context and
value application for each source representation. Keep coverage and
value-index checks in the wrappers and share the context setup through
ValueFormat, passing the original value base explicitly.
With GCC 15.3 on x86-64 without LTO, this removes 2088 bytes of core
code/read-only data at -O3 and 616 bytes at -Os. Optical-bound benchmarks
show no consistent slowdown across the four source formats.
Validated with the full Meson suite (292 passed, one skipped) and
synthetic optical-bound checks for all directions, 16/24-bit glyph IDs,
missing glyphs, and device adjustments.
Assisted-by: OpenAI Codex <codex@openai.com>
* [subset] Share retained mark-anchor index collection
Mark-to-base and mark-to-mark variation collection construct the same
row-major anchor-index lists, but do so inside each table-width template.
Pass the decoded row and class counts to a common collector.
Preserve coverage filtering, class selection, index order, and the
existing vector allocation behavior. Anchor access remains in the
format-specific wrappers.
With GCC 15.3 on x86-64 without LTO, this removes 2896 bytes of subset
code/read-only data at -O3 and 2152 bytes at -Os. Validated with the full
Meson suite (292 passed, one skipped) and variable-font subset benchmarks.
Assisted-by: OpenAI Codex <codex@openai.com>
* [ot] Share delta substitution glyph traversal across widths
Closure, dependency extraction, and glyph collection for delta
substitutions only need a decoded coverage, delta, and glyph mask.
Share those traversals instead of instantiating them for each source
representation.
Keep the closure population and overlapping-range guards, dependency
bounds filtering, traversal order, and allocation behavior unchanged.
With GCC 15.3 on x86-64 without LTO, this removes 1112 bytes of core and
952 bytes of subset code/read-only data at -O3, and 608/712 bytes at -Os.
Validated with the full Meson suite (292 passed, one skipped), C++11
syntax checking, and subset benchmarks.
Assisted-by: OpenAI Codex <codex@openai.com>
* [subset] Share pair-position variation-index collection
Resolve the table-width-dependent PairPos fields before collecting
variation indices. Share the class sets and matrix traversal between
the small and beyond-64k formats while retaining the original value
base for device offsets.
Saves 3328 bytes at -O3 and 2312 bytes at -Os in the subset library
with GCC 15.3 without LTO. The full test suite passes, including the
HB_NO_BEYOND_64K build; variable-font subset timings remain close.
Assisted-by: OpenAI Codex <codex@openai.com>
Contextual lookup helpers are instantiated separately for 16-bit
glyphs, 24-bit glyphs, and coverage offsets, duplicating traversal
code when beyond-64k support is enabled.
Use an allocation-free glyph-data view carrying the pointer and
element width to share matching, contextual application, intersection,
collection, closure, and dependency helper bodies. Preserve the
existing forced-inlining policy for the matching helpers.
With GCC 15.3 on x86-64 without LTO, each stripped shared library
shrinks by 12 KiB at -O3. Shaping and subset timings stay close to
baseline overall, with a measured 2% slowdown on Duployan shaping.
Validated with the full Meson suite, API/shaping/subset tests with
HB_NO_BEYOND_64K, Clang reduced-feature syntax checks, and synthetic
24-bit contextual shaping, would-apply, and glyph-collection checks.
Assisted-by: OpenAI Codex <codex@openai.com>
Resolve the table-width-dependent PairPos fields before collecting
variation indices. Share the class sets and matrix traversal between
the small and beyond-64k formats while retaining the original value
base for device offsets.
Saves 3328 bytes at -O3 and 2312 bytes at -Os in the subset library
with GCC 15.3 without LTO. The full test suite passes, including the
HB_NO_BEYOND_64K build; variable-font subset timings remain close.
Assisted-by: OpenAI Codex <codex@openai.com>
Closure, dependency extraction, and glyph collection for delta
substitutions only need a decoded coverage, delta, and glyph mask.
Share those traversals instead of instantiating them for each source
representation.
Keep the closure population and overlapping-range guards, dependency
bounds filtering, traversal order, and allocation behavior unchanged.
With GCC 15.3 on x86-64 without LTO, this removes 1112 bytes of core and
952 bytes of subset code/read-only data at -O3, and 608/712 bytes at -Os.
Validated with the full Meson suite (292 passed, one skipped), C++11
syntax checking, and subset benchmarks.
Assisted-by: OpenAI Codex <codex@openai.com>
Mark-to-base and mark-to-mark variation collection construct the same
row-major anchor-index lists, but do so inside each table-width template.
Pass the decoded row and class counts to a common collector.
Preserve coverage filtering, class selection, index order, and the
existing vector allocation behavior. Anchor access remains in the
format-specific wrappers.
With GCC 15.3 on x86-64 without LTO, this removes 2896 bytes of subset
code/read-only data at -O3 and 2152 bytes at -Os. Validated with the full
Meson suite (292 passed, one skipped) and variable-font subset benchmarks.
Assisted-by: OpenAI Codex <codex@openai.com>
SinglePos position_single duplicates the temporary apply context and
value application for each source representation. Keep coverage and
value-index checks in the wrappers and share the context setup through
ValueFormat, passing the original value base explicitly.
With GCC 15.3 on x86-64 without LTO, this removes 2088 bytes of core
code/read-only data at -O3 and 616 bytes at -Os. Optical-bound benchmarks
show no consistent slowdown across the four source formats.
Validated with the full Meson suite (292 passed, one skipped) and
synthetic optical-bound checks for all directions, 16/24-bit glyph IDs,
missing glyphs, and device adjustments.
Assisted-by: OpenAI Codex <codex@openai.com>
SingleSubstFormat1_3 constructs equivalent remapping iterators in each
source-format specialization, giving the output and coverage serializers
distinct iterator types and duplicating their bodies.
Move the subset preparation into a common helper taking the decoded
coverage, delta, and glyph mask. Preserve the glyph intersection,
modular delta calculation, remapping, and serializer failure behavior.
With GCC 15.3 on x86-64 without LTO, this removes 11896 bytes of subset
code/read-only data at -O3 and 5776 bytes at -Os. Validated with the full
Meson suite (292 passed, one skipped) and subset benchmarks.
Assisted-by: OpenAI Codex <codex@openai.com>
SinglePos output serializers only need the source value format and
ValueBase pointer, but carried the full source lookup type through
several template layers. The per-glyph mapper also had distinct lambda
types for legacy and beyond-64k source tables.
Pass the source format and base directly, and use a common mapper with
the same reference captures as the original lambda. Output formats,
device offsets, value copying, and allocation behavior are preserved.
With GCC 15.3 on x86-64 without LTO, this removes 18080 bytes of subset
code/read-only data at -O3 and 9472 bytes at -Os. Validated with the full
Meson suite (292 passed, one skipped) and subset benchmarks.
Assisted-by: OpenAI Codex <codex@openai.com>
Mark classes remain 16-bit values in both mark-record representations;
only the record stride and array count differ. Decode those in the
wrapper and share the class collection and remapping work.
Give the common helper hidden inline linkage so its body is shared
across translation units as well as record formats. Class ordering,
existing mappings, and allocation behavior are preserved.
With GCC 15.3 on x86-64 without LTO, this removes 1152 bytes of subset
code/read-only data at -O3 and 1440 bytes at -Os. Validated with the full
Meson suite (292 passed, one skipped) and subset benchmarks.
Assisted-by: OpenAI Codex <codex@openai.com>
CursivePosFormat1_2 duplicates the direction-dependent positioning and
attachment-chain updates for legacy and beyond-64k entry/exit records.
Keep record access and anchor validation in the format-specific wrapper,
then pass the resolved anchors to a common attachment helper. Preserve
all direction cases, chain reversal, overflow handling, and messages.
With GCC 15.3 on x86-64 without LTO, this removes another 2760 bytes of
core code/read-only data at -O3 and 864 bytes at -Os. Validated with the
full Meson suite (292 passed, one skipped) and sampled shaping benchmarks.
Assisted-by: OpenAI Codex <codex@openai.com>