Commit Graph
90 Commits
Author SHA1 Message Date
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
Behdad Esfahbod e970f7028c [harfruzz] Round towards negative infinity 2025-06-13 18:21:27 -06:00
Behdad Esfahbod 2617e89df1 [rust] Finish renaming HarfRuzz to HarfRust 2025-06-11 15:52:47 -06:00
Behdad Esfahbod c936b22937 [rust] Update to HarfRuzz->HarfRust rename 2025-06-10 08:22:47 -06:00
Behdad Esfahbod dcf50ca6fe [rust] Roll forward 2025-06-10 03:10:06 -06:00
Behdad Esfahbod e860b8d180 [harfruzz] Set point_size 2025-06-07 11:26:00 -06:00
Behdad Esfahbod e5becebf2c [harfRuzz] Roll forward 2025-06-06 21:02:07 -06:00
Behdad Esfahbod d5dd5ac819 [harfruzz] Clear mask before setting 2025-06-06 18:29:40 -06:00
Behdad Esfahbod 4ab5130e4a [harfruzz] More glyph flags 2025-06-06 18:16:31 -06:00
Behdad Esfahbod 74e99dbe63 [harfruzz] Apply review feedback 2025-06-06 18:15:20 -06:00
Behdad Esfahbod 80b73a1109 [harfruzz] Track main again 2025-06-06 18:13:05 -06:00