Port of fontTools' instantiateCFF2 (fonttools/fonttools#3506) design, with
a simplification: the instancing solver acts on regions independently of
per-blend delta values, so instead of lifting every blend's deltas into
the store and reading them back, instance each VarData once with identity
delta rows. The surviving tuples then form a fixed linear map from old
per-region deltas to new per-region deltas; the fold-into-default part is
the old store's region scalars at the new default location.
Dormant so far: computed for partial-instancing requests but not yet
consumed; blends are still (wrongly) fully flattened.
The pinned private-dict serializer rebuilt its blend-encoder param for
every opstr, so an ivs recorded from a vsindexdict opstr was gone by the
time later opstrs' blends were flattened; dicts with a non-zero vsindex
were blended against VarData 0's scalars. Hoist the param into the
serializer (one instance per private dict) so it survives the whole
dict.
The subset-side private-dict opset never handled OpCode_vsindexdict, so
accelerator_subset_t's privateDicts[fd].ivs always stayed 0 and charstring
interpretation during subsetting started from the wrong variation-store
index for any FD whose Private dict declares a non-zero vsindex. Mirror
what cff2_private_dict_opset_t does; the op bytes are still recorded so
the verbatim-copy path is unchanged.
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>
The D3D11 demo atlas backend advanced its cursor and copied glyph data into the
shadow buffer without checking the fixed atlas capacity. Long sessions could
therefore write past the end of the shadow buffer once the atlas filled.
Match the other demo atlas backends by failing before advancing the cursor when
the requested glyph data does not fit.
Testing: meson test -C build
Assisted-by: OpenAI Codex <codex@openai.com>
Mirror Mesons gpu_demo feature in the CMake build with an
AUTO/ON/OFF option. AUTO keeps the demo optional while reporting
missing dependencies, ON makes missing dependencies fatal, and OFF
skips probing and building the demo.
Tested with meson test -C build.
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
Some projects may need higher C++ standard than C++11. In order not to
force the requirement for the whole project, the C++ standard can be set
at the configure time with -DCMAKE_CXX_STANDARD=20 for example. The
project default takes precedence only when there's no assignment
provided in the command line by setting the default cache value.
There's no need to additionally check for the compiler support when
CMAKE_CXX_STANDARD_REQUIRED is already set.
Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
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
* [util] Fix Unicode command line arguments on Windows
GLib g_option_context_parse() converts argv strings from the system ACP via g_locale_to_utf8(), but Windows cmd deliver arguments encoded in the system codepage (ex: CP1252), which cannot represent most Unicode codepoints. This caused non ascii character to be corrupted
For example, for this command, it rendered garbage instead of the emoji:
```
hb-view.exe "C:\Windows\Fonts\seguiemj.ttf" "😋" --output-file=output.png
```
Fix this in all util binaries (hb-ft-raster, hb-info, hb-raster, hb-shape, hb-subset, hb-vector, hb-view) by:
1. Calling g_win32_get_command_line() to obtain correctly UTF-8-encoded arguments from GetCommandLineW().
2. Parsing with g_option_context_parse_strv() which skips the g_locale_to_utf8() conversion for G_OPTION_ARG_STRING entries.
3. Adding G_OPTION_FLAG_FILENAME to the G_OPTION_REMAINING callback entry in main-font-text.hh, so the callback path also skips the locale conversion in strv_mode (see https://gitlab.gnome.org/GNOME/glib/-/blob/8ef2f3ad402daf9fb94615ddef63ceef978fd76f/glib/goption.c#L1305).
* [util] Fix Windows UTF-8 argv parsing
On Windows, GLib's option parser treats argv as encoded in the
system codepage and converts strings with g_locale_to_utf8(). The
utilities need to parse the UTF-8 command line obtained from
GetCommandLineW() instead, otherwise non-ASCII arguments can be
corrupted before reaching the tool logic.
Add a small argv_t wrapper for utility entry points to replace argv
with g_win32_get_command_line() on Windows, and use the strv parser
there so GLib skips the top-level argv conversion. Mark remaining
callback arguments as filenames so GLib also skips callback argument
conversion for positional text and font arguments.
Testing:
meson test -C build
Assisted-by: OpenAI Codex
* [mingw] Update instructions
---------
Co-authored-by: moi15moi <moi15moismokerlolilol@gmail.com>
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