Commit Graph
100 Commits
Author SHA1 Message Date
Behdad Esfahbod 9e6929319b [rust] Use harfrust table-backed font API (#6036)
* [rust] Use harfrust table-backed font API

* [rust] Roll HR forward
2026-06-20 12:18:56 -06:00
Behdad Esfahbod 2575326527 [rust] Bulk-populate HarfRust input buffer (#6016)
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
2026-06-02 01:46:23 -06:00
Behdad Esfahbod a4eb9e25d3 [rust] Avoid parsing HarfRust language tags (#6015)
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
2026-06-01 10:35:24 -06:00
Behdad Esfahbod 97650e50e2 [rust] Use SmallVec for HarfRust features (#6014)
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
2026-06-01 09:53:23 -06:00
Behdad Esfahbod 8987443bd3 [rust] Bulk-copy HarfRust shape results (#6013)
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
2026-06-01 08:49:52 -06:00
Dominik RöttschesandBehdad Esfahbod 30bde663e7 Pass codepoints for context directly to HarfRust shaper (#6008)
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>
2026-06-01 02:32:01 -06:00
Behdad Esfahbod bc4cd305ca [rust] Use new harfrust GlyphFlags getter (#6011)
* [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
2026-06-01 02:23:26 -06:00
Behdad Esfahbod fd707f8151 [fontations] Map default variations
https://github.com/servo/servo/pull/38707#issuecomment-4587826343
2026-05-31 21:26:19 +02:00
Behdad Esfahbod 2353415a37 [rust] Reinstate commented-out git branch for harfrust
For development purposes.
2026-05-30 23:23:59 +02:00
Behdad EsfahbodandChad Brokaw 77abf89986 [harfrust] Honor hb font funcs during shaping (#6002)
Wire the HarfRust shaper through the active hb_font_t callback
surface so custom hb_font_funcs_t are respected during shaping.
Add a harfrust-specific test-shape invocation to cover that path.

Tested: meson test -C build test-shape-harfrust
Tested: HB_SHAPER_LIST=harfrust meson test -C build harfbuzz:shape_threads
Tested: HB_SHAPER_LIST=harfrust meson test -C build test-shape
Assisted-by: OpenAI Codex

---------

Co-authored-by: Chad Brokaw <cbrokaw@gmail.com>
2026-05-28 13:33:21 -04:00
Behdad Esfahbod 4b287d9f86 [rust] Remove accidental change to comments 2026-05-26 17:21:18 +02:00
Behdad Esfahbod 53c761783b [harfrust] Update shape glue for harfrust 0.8 (#6001)
Update the Rust bridge and Cargo dependency to harfrust 0.8.
Switch shaping calls to ShapeOptions, keep the cached shaper
path, and remove an unused face_data argument from the shaping
ABI.

Tested: meson compile -C build
Assisted-by: OpenAI Codex
2026-05-26 09:18:15 -06:00
Dominik Röttsches 0a7092643f [rust] Windows build fixes
Cast and add #[allow(clippy::unnecessary_cast)] as the C compiler
chooses different signedness for the hb_script_t and hb_tag_t enum
types depending on architecture. Add casts where needed and add
clippy suppressions to avoid warnings when compiled on systems
where the enum is unsigned by default.
2026-05-25 15:21:45 +03:00
Dominik Röttsches 4321818220 Cross-platform clippy-friendly casts in FFI
Bindgen generates a std::os::raw::c_char as return type for
functions like hb_blob_get_data. Depending on platform/arch, this
can be an i8 or u8. In the Rust side code, receiving
the data, these are interpreted as u8. Perform the pointer
casts in a way that compiles without clippy warnings about
unnecessary casts when the c_char type was already u8.
2026-05-18 17:02:39 +03:00
Dominik Röttsches 0cf18e7b64 Fix warnings in embedder build with newer rustc (#5983)
Wrap no_mangle in unsafe() to address compiler warnings
with newer rust compilers/editions.
2026-05-13 07:52:32 -06:00
Dominik Röttsches 3986312ea2 Make Rust global_allocator mapping optional (#5982)
In embedding projects, the global_allocator might already have been
overriden. There is no known way to keep the allocator library-local,
and allocator-bound containers are not a stable Rust feature yet.

Add an option to disable the allocator mapping to hb_malloc and friends,
so that an embedder can keep their own allocator.
2026-05-13 07:51:52 -06:00
parasol-aserandjeffhuang 1ea68a9f57 [fontations] Fix OOB write on glyph-name callback with size == 0 (#5946) (#5947)
* [fontations] Fix OOB write on glyph-name callback with size == 0

The Rust `_hb_fontations_glyph_name()` callback computed
`glyph_name.len().min(size as usize - 1)`. When a caller passed
`size == 0`, `size as usize - 1` underflowed a `usize` to
`usize::MAX`, the `min()` clamp collapsed to `glyph_name.len()`,
and the subsequent `copy_nonoverlapping` / trailing NUL wrote
`glyph_name.len() + 1` bytes into a zero-capacity caller buffer.
This is an out-of-bounds write reachable from the public API
whenever the build was configured with `-Dfontations=enabled`
and the application had called `hb_fontations_font_set_funcs()`.

Short-circuit the `size == 0` case before the subtraction.
Return `true` in that case to match the existing post and CFF1
backends (`hb-ot-post-table.hh`, `hb-ot-cff1-table.hh`), which
both early-out with `return true` on `!buf_len` — the glyph
does have a name; we simply had no buffer to write it into.

Regression tests added in `test/api/test-glyph-names.c` cover
the zero-size path on post and CFF1 backends, a sub-font, a
NULL buffer, and `size == 1` / small-buffer / exact-fit cases
so the truncation path does not silently regress.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/5946
Assisted-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* [font] Reject glyph-name lookups with size == 0 at the wrapper

`hb_font_t::get_glyph_name()` previously pre-wrote the trailing
NUL only when `size != 0` but still dispatched to the backend
callback with `size == 0`. Every current glyph-name backend has
to re-validate that argument: `post` and `cff1` short-circuit
with `return true`, the new Rust `fontations` callback now
short-circuits too (prior commit), and the CoreText callback in
`hb-coretext-font.cc` has a structurally similar `(CFIndex)size
- 1` pattern.

Normalize this at the wrapper layer: return `false` immediately
on `size == 0`, before any backend dispatch and before the
`*name = '\0'` write. This makes the zero-size case a single,
auditable no-op for every glyph-name provider (native or Rust,
current or future) and removes the CoreText underflow from the
reachable surface through the same chokepoint.

Observable change: callers that invoked
`hb_font_get_glyph_name(font, gid, buf, 0)` on post/cff1 backed
fonts used to get `true` back; they now get `false`. `size == 0`
queries carry no useful information for the caller, so this is
considered a safe hardening rather than a contract break.

Assisted-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* [font] Preserve glyph-name zero-size probe semantics

Keep `hb_font_get_glyph_name(..., NULL, 0)` as a valid
return-value-only probe instead of rejecting `size == 0` in the
wrapper.

Fix the remaining backend-specific zero-size paths in hb-ft and
hb-coretext-font so they answer the probe without dereferencing the
caller buffer, and update the API tests to assert the preserved
behavior.

Testing: CCACHE_DISABLE=1 meson test -C build test-glyph-names
Testing: CCACHE_DISABLE=1 meson test -C build test-ft
Assisted-by: OpenAI Codex <codex@openai.com>

---------

Co-authored-by: jeffhuang <jeff@docker.xydrsucermoubd24xgo33yhsgd.bx.internal.cloudapp.net>
2026-04-18 19:54:54 -06:00
Behdad Esfahbod 0cf2fa0929 Merge pull request #5891 from harfbuzz/vector-pdf
PDF output from hb-vector
2026-04-11 22:20:01 -06:00
Behdad Esfahbod fb594d4afe [rust] Roll HarfRust to 0.6.0 2026-04-09 13:10:59 -06:00
Behdad Esfahbod 1141e97ef4 [paint] Add hb_paint_push_group_for() API
Add a new push_group variant that receives the compositing mode
upfront. This lets backends like PDF emit blend-mode state before
painting the group content, avoiding the need to buffer and
retroactively wrap.

The default (nil) implementation calls hb_paint_push_group(), so
existing backends are unaffected.

Callers updated:
- COLR PaintComposite now calls push_group_for() for both groups
- Rust/fontations push_layer passes the mode through
- hb-raster SVG context accepts mode parameter (default SRC_OVER)

All 233 tests pass.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
Dominik Röttsches 6c5a137cb7 [rust] Make HarfRust' dependency on Draw/Paint optional. (#5900)
Add draw and paint features to font.rs. Enable both by default in
Cargo.toml. This allow compilation without draw and paint functionality
enabled on the C++ side.

Assisted-by: Gemini CLI
2026-04-07 12:38:19 -06:00
Behdad Esfahbod 20fc6583b9 Revert "[rust] Use design coords if available, to set on the Rust side"
This reverts commit cb121fe0368d37ee599c8d4e168a5d139520cbcf.
2026-03-19 12:12:27 -06:00
Behdad Esfahbod 30f8744405 [rust] Use design coords if available, to set on the Rust side
Going to commit since not useful. Just wanted to record the code.
2026-03-19 12:12:27 -06:00
Behdad Esfahbod b863a8f462 Revert "[rust] Use HarfBuzz-style glyph outline"
This reverts commit 6ba28949f5.
2026-02-05 15:32:46 -07:00
Behdad Esfahbod 6ba28949f5 [rust] Use HarfBuzz-style glyph outline
Slightly slower, but matches our point order better.
2026-02-05 15:24:53 -07:00
Behdad Esfahbod 0334f2e38d [rust] Add a couple of compiler flags (#5729)
Makes binary 100kb smaller!
2026-02-04 05:07:31 -07:00
Behdad Esfahbod b1c71874a4 [rust] Use panic="abort" in debugoptimized builds as well 2026-02-03 23:43:00 -07:00
Behdad Esfahbod 4ca351535b [rust] Roll to new HarfRust 2026-01-10 07:41:54 -07:00
Behdad Esfahbod 677f0b367d [rust] Update to HarfRust 0.4.* 2025-11-10 21:40:20 -07:00
Behdad Esfahbod 88844e2ed9 [rust] Tweak debugoptimized again
Now on par in perf with release, but nice stacktraces.
2025-09-24 13:28:28 -06:00
Behdad Esfahbod ba4f92f200 [rust] Change debugoptimized build to inherit dev instead of release
I was getting useless profiler stacks with the previous setup.
This one makes the debugoptimized build 30% slower than release
in one of my benchmarks, but at least we get useful stacktraces
by default.
2025-09-24 13:12:50 -06:00
Behdad Esfahbod 52eb959535 [rust] Don't use panic_immediate_abort (#5585)
It has changed. Use optimize_for_size which seems to have the
same size reduction effect.

Fixes https://github.com/harfbuzz/harfbuzz/issues/5584
2025-09-23 22:22:56 -06:00
Behdad Esfahbod 74c318610d [rust] Update to HarfRust 0.3.0 (#5548) 2025-09-12 13:31:29 -06:00
Behdad Esfahbod d94851e56d [rust] Use inherited codegen-units=1 in debugoptimized build
It makes significant (30% in Nastaliq benchmark) difference.
2025-09-03 11:52:51 -06:00
Behdad Esfahbod 01072c5c37 [harfrust] Require 0.2.0 2025-08-29 13:19:59 -06:00
Behdad Esfahbod 5fddacc158 [harfrust] Set buffer pre/post-context (#5492)
* [harfrust] Set buffer pre/post-context

Fixes the failing item-context tests. Yay.

* Bump MSRV
2025-08-21 12:54:49 -06:00
Behdad Esfahbod 00492ec7df [harfrust] Pin to 0.1.2 for relase 2025-08-20 13:48:11 -06:00
Behdad Esfahbod bbc2e0d0b5 [harfrust] Scale using int64 instead of float (#5461)
Like hb-font.hh does.
2025-08-14 16:12:59 -06:00
Behdad Esfahbod 354c6a17b8 [harfrust] Remove one function call (#5460)
lol. That's how desperate we are now.
2025-08-14 16:01:44 -06:00
Behdad Esfahbod 75044854a8 [harfrust] Update to latest API 2025-08-14 11:24:19 -06:00
Behdad Esfahbod 53cd214e83 [harfrust] Use buffer.ensure() (#5459) 2025-08-14 10:24:21 -06:00
Behdad Esfahbod 8ebdb9f75c [harfrust] Cache Shaper object (#5454) 2025-08-13 17:39:30 -06:00
Behdad Esfahbod 1e8a554eaa Hr buffer cache (#5452)
* [harfrust] Rename a variable

* [harfrust] Cache HR buffer on HB buffer
2025-08-11 19:27:32 -06:00
Behdad Esfahbod 1a2337d550 [rust] Require HarfRust 0.1.* 2025-08-11 12:53:03 -06:00
Behdad Esfahbod ef5c3d59fd [rust] Oops 2025-08-10 01:27:41 -06:00
Behdad Esfahbod 940604b2bc [gsubgpos] Micro improvement of (Chain)ContextFormat2 classdef cache 2025-08-10 01:25:13 -06:00
Behdad Esfahbod b3258808b9 [rust] Remove Cargo.lock
As per recommendations. I hope this is what they meant.
2025-07-23 20:06:19 -06:00
Behdad Esfahbod 8991fa7a89 [rust] Roll forward
Give clippy more time.
2025-07-20 18:12:39 -06:00
Behdad Esfahbod d47a319b82 [rust] Roll deps forward
Adjust tests. See:

https://github.com/harfbuzz/harfbuzz/issues/5388
2025-07-15 12:08:00 -06:00
Behdad Esfahbod 57f02dd237 [fontations] Cache glyph_from_names hashmap on the face
Fixes https://github.com/harfbuzz/harfbuzz/issues/5384
2025-07-11 23:40:51 -06:00