Commit Graph
20948 Commits
Author SHA1 Message Date
Behdad Esfahbod e046d2ba6d [vector] Add PDF color font rendering via paint API
Add hb-vector-pdf-paint.cc with a complete set of PDF paint
callbacks for the HarfBuzz paint API:

  push/pop_transform  →  q + cm / Q
  push/pop_clip_glyph →  q + path + W n / Q
  push/pop_clip_rect  →  q + re + W n / Q
  color               →  rg + re + f
  push/pop_group      →  q / Q
  gradients           →  solid fallback (first stop color)

The PDF paint backend reuses the draw funcs for glyph clip
path emission and shares the hb_vector_paint_t struct with
the SVG backend via hb-vector-paint.hh.

hb_vector_paint_glyph dispatches to SVG or PDF paint funcs
based on format.  hb_vector_paint_render delegates to the
PDF render function for PDF output.

Tested with COLRv0 (RocherColorGX) — color layers render
correctly with proper clipping.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
Behdad Esfahbod d530482115 [vector] Extract hb_vector_paint_t to shared header
Move the paint struct and color glyph cache key to
hb-vector-paint.hh so the upcoming PDF paint backend can
share the type.  Convert the SVG-specific transform helper
methods to free functions.

No functional change.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
Behdad Esfahbod ca9f1f49cf [vector] Fix PDF pen position — no Y negation needed
The pen coordinates from vector-output.hh are in font space
(Y-up), not SVG space.  The Y-flip in compute_extents only
affects the extents, not the pen positions passed to
hb_vector_draw_glyph.  Use pen_y directly.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
Behdad Esfahbod 0b91bb09fb [vector] Fix PDF coordinate system
Font and PDF coordinates are both Y-up, so no Y-flip is
needed in the path data.  The pen position from the SVG-space
layout is the only thing that needs negating.

Remove the Y negation from append_xy and the CTM from the
content stream.  Set the glyph transform to identity with
negated pen_y.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
Behdad Esfahbod 4faf03e9e9 [vector] Fix PDF fill inversion by negating Y in coordinates
The previous CTM-based Y-flip reversed path winding, causing
inverted fills.  Instead, negate Y directly in append_xy for
PDF format.  This preserves winding direction and produces
correct non-zero fill results.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
Behdad Esfahbod 3fc9ae5e49 [vector] Fix PDF coordinate system with Y-flip CTM
Prepend a 1 0 0 -1 0 (ey+eh) cm to the content stream so
that the SVG-space (Y-down) path coordinates render correctly
in PDF (Y-up).  Set the MediaBox to [ex 0 ex+ew eh].

Assisted-by: Claude <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
Behdad Esfahbod a43971d2a3 [vector] Add PDF output backend
Add HB_VECTOR_FORMAT_PDF to hb_vector_format_t.  The hb-vector
tool now produces self-contained PDF when invoked with -o out.pdf.

PDF path operators map directly from the draw callbacks:
move_to → m, line_to → l, cubic_to → c, close_path → h,
with quadratic-to-cubic promotion (PDF has no Q operator).

The render function builds a minimal PDF 1.4 with catalog,
page, and content stream objects plus a cross-reference table.

Implementation:
- Extract hb_vector_draw_t struct to hb-vector-draw.hh so
  future backends can share it.
- Draw callbacks branch on format for SVG vs PDF syntax.
- hb_vector_draw_glyph and hb_vector_draw_render dispatch by
  format.
- vector-output.hh selects format from file extension and
  skips paint (color glyphs) for PDF.

Coordinate system needs refinement — the page layout inherits
the SVG Y-flip transform, placing glyphs at the top with
extra whitespace.  Correct PDF coordinate handling is a
follow-up.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
jfkthame 5cbce05a7c Add a couple of missing overflow checks (#5901)
* Use hb_unsigned_mul_overflows in CFF2 process_blend.

* Check for overflow when computing hb_aat_layout_chain_accelerator_t size.
2026-04-07 15:36:21 -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 ee7c6dbde4 [CODE_OF_AI_CONDUCT] Require two reviews for large library changes (#5899) 2026-04-07 11:22:47 -06:00
Behdad Esfahbod a12f531ad1 [README.md] Format 2026-04-06 19:30:21 -06:00
Behdad Esfahbod 2b89ade7a1 [README.md] Auxiliary libraries 2026-04-06 18:13:17 -06:00
Behdad EsfahbodandOpenAI Codex 03c262d1eb [raster] Clamp reflected gradient LUT coordinates
Malformed reflected gradients can produce very large finite
gradient parameters. The raster backend normalized reflect
mode by casting floorf(t) to int, which can overflow and
drive LUT lookups past the fixed-size stack buffer.

Fold reflected coordinates with fmodf(), clamp LUT inputs
defensively, and add the minimized oss-fuzz raster
testcase to the corpus.

Fixes: https://oss-fuzz.com/testcase-detail/6597066439852032
Tested: meson test -C build
Co-Authored-By: OpenAI Codex <codex@openai.com>
2026-04-06 17:13:58 -06:00
Behdad Esfahbod 5ce0b12729 [CONFIG] Remove outdated note
Fixes https://github.com/harfbuzz/harfbuzz/issues/5890
2026-04-06 17:08:50 -06:00
dependabot[bot] cd095479dd Bump mymindstorm/setup-emsdk from 14 to 15
Bumps [mymindstorm/setup-emsdk](https://github.com/mymindstorm/setup-emsdk) from 14 to 15.
- [Release notes](https://github.com/mymindstorm/setup-emsdk/releases)
- [Commits](https://github.com/mymindstorm/setup-emsdk/compare/6ab9eb1bda2574c4ddb79809fc9247783eaf9021...667eb33f24e84e7f362c16d8d7fff0629a73e15e)

---
updated-dependencies:
- dependency-name: mymindstorm/setup-emsdk
  dependency-version: '15'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-06 14:00:47 +02:00
Behdad Esfahbod 3b7ee09f0e [gpu] Fix draw encode blob ownership leaks
hb_gpu_draw_encode() could allocate a fresh output buffer and then
return NULL before transferring ownership to a blob, leaking that
temporary buffer on late encode failures.

The recycled-blob growth path also tried hb_realloc() first and fell
back to hb_malloc() when that failed. Once the new buffer was committed
to the recycled blob, the old recycled buffer could be orphaned.

Free temporary buffers on the remaining late-failure exits and keep
the old recycled buffer alive until a replacement has been committed.
Tighten the GPU API recycle test to encode a larger second outline so
that reused-buffer growth stays covered.

Tested:
- meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-04-04 19:44:54 -06:00
Khaled Hosny cfb70b0b91 14.1.0 14.1.0 2026-04-04 20:31:18 +02:00
Behdad Esfahbod 1519b54405 Merge pull request #5894 from harfbuzz/fuzzer-fixes-apr3
Fuzzer fixes apr3
2026-04-03 18:20:33 -06:00
Behdad Esfahbod e8c5bb452d [raster] Widen edge row interpolation arithmetic
edge_sweep_row() computed the clipped endpoint x coordinates with
int32_t subtractions before casting to int64_t. If an edge started at
INT32_MIN and the scanline clipped endpoint was near zero, ey - yL
overflowed before the slope multiply and UBSan flagged the raster
fuzzer path.

Keep the endpoint interpolation and follow-on dx math in 64-bit until
clamping back to int32_t. This preserves the existing rasterizer logic
while avoiding signed overflow for extreme edge coordinates.

Tested:
- meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-04-03 18:07:28 -06:00
Behdad Esfahbod 8395b30b5b [raster] Move PNG scratch state out of libpng longjmp locals
libpng aborts via longjmp. Our PNG read/write helpers kept scratch
hb_vector_t objects as automatic locals after setjmp and then tried
to free them from the longjmp handler. Once longjmp fires, those
modified locals have indeterminate state, so the cleanup path can
miss live allocations and leak under the raster fuzzer.

Move the PNG scratch buffers and write accumulator into explicit
heap-backed state allocated before setjmp and cleaned up on every
exit path. This keeps both decode and encode cleanup deterministic
across libpng errors.

Tested:
- env LD_LIBRARY_PATH=/home/behdad/harfbuzz/build/src valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./build/test/fuzzing/hb-raster-fuzzer test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-subset-fuzzer-5684014636859392
- meson test -C build raster-fuzzer-chunk-0 raster-fuzzer-chunk-1 raster-fuzzer-chunk-2 raster-fuzzer-chunk-3 raster-fuzzer-chunk-4 raster-fuzzer-chunk-5 raster-fuzzer-chunk-6 raster-fuzzer-chunk-7 --wrap='valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1' --print-errorlogs
- meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-04-03 17:38:32 -06:00
Behdad Esfahbod ae23a9b5cb [raster] Fix transformed clip mask intersection bounds
Transformed clip rectangles kept their intersection math in unsigned
loop bounds after clamping only the lower edge to zero. When the
transformed upper edge stayed negative, the signed-to-unsigned cast
wrapped and raster clip reuse read past the previous alpha mask.

The same path also reused emitter-generated clip buffers without
clearing bytes outside the rows it rewrote, which let Valgrind see
uninitialized alpha values on later clip intersections.

Keep the clip intersection in signed ints until after the empty-range
check, and zero newly sized emitter clip buffers before partial writes.

Testing:
- env LD_LIBRARY_PATH=/home/behdad/harfbuzz/build/src valgrind --leak-check=full --error-exitcode=1 ./build/test/fuzzing/hb-raster-fuzzer test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-4872362293264384
- meson test -C build raster-fuzzer-chunk-0 --wrap='valgrind --leak-check=full --error-exitcode=1' --print-errorlogs
- meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-04-03 17:29:03 -06:00
Behdad EsfahbodandOpenAI Codex 19e4bf2597 [raster] Validate non-rect clip masks before reuse
The raster paint clip code indexed non-rect clip alpha rows directly,
assuming the clip metadata always matched a full stride*height backing
buffer. Fuzzing showed that reused clip objects can reach those reads
with stale scalar state, which turns the row access in
push_clip_rectangle() into a heap-buffer-overflow.

Reset cached clip geometry on acquire, add a validity check for
non-rect alpha masks, and refuse to build new clip intersections from
an invalid mask. The fallback is an empty clip, which keeps the paint
path safe without affecting well-formed clips.

Testing:
- meson test -C build --suite fuzzing --print-errorlogs
- meson test -C build

Co-authored-by: OpenAI Codex <codex@openai.com>
2026-04-03 17:17:49 -06:00
Behdad EsfahbodandOpenAI Codex 9f64e3fde2 [raster] Fail closed on SVG paint stack imbalance
The raster SVG renderer asserted that each element restored the paint
transform, clip, and surface stacks to their entry depths. Fuzzing
found malformed documents that violate that assumption and abort the
process in svg_render_element().

Replace the assertions with explicit stack restoration, discard any
extra group surfaces, and mark the render as failed if the renderer
cannot get back to the saved baseline. The top-level SVG entry point
now checks that failure bit and stops rendering cleanly instead of
crashing.

Testing:
- meson test -C build --suite fuzzing --print-errorlogs
- meson test -C build

Co-authored-by: OpenAI Codex <codex@openai.com>
2026-04-03 17:17:49 -06:00
Behdad EsfahbodandOpenAI Codex 98866c9fef [svg] Zero-initialize doc cache parser structs
MemorySanitizer reported use of uninitialized data while building the
SVG document cache used by vector painting. The parser keeps small
aggregate structs on the stack, and their padding could stay poisoned
as they were copied through the open-element stack.

Zero-initialize the parser stack and the temporary span / element
records before filling their fields. That keeps later copies and
container insertions from carrying undefined padding into the MSan
instrumented path.

Testing:
- meson test -C build --suite fuzzing --print-errorlogs
- meson test -C build

Co-authored-by: OpenAI Codex <codex@openai.com>
2026-04-03 16:49:48 -06:00
Behdad EsfahbodandOpenAI Codex bfafd9d648 [gpu] Check draw encode size arithmetic
The GPU fuzzer can build outline data large enough to stress the size
math inside hb_gpu_draw_encode(). Several totals and byte counts were
computed with unchecked unsigned arithmetic before the existing bounds
checks ran.

Use HarfBuzz's overflow helpers for band-index totals, encoded blob
lengths, byte sizes, and recycled-buffer growth. Also rewrite the
uint16-offset limit check so it does not rely on subtracting from an
already-overflowed total.

Testing:
- meson test -C build --suite fuzzing --print-errorlogs
- meson test -C build

Fixes: https://oss-fuzz.com/testcase-detail/6336503637934080
Co-authored-by: OpenAI Codex <codex@openai.com>
2026-04-03 16:44:50 -06:00
Behdad EsfahbodandOpenAI Codex c111ff82ff [gpu] Fail cleanly on OOM in draw encode
Failing-malloc fuzzing exposed two holes in the GPU draw path.
Accumulation ignored push failures, and encode reused scratch vectors
that could remain poisoned after a previous allocation failure.

Poison the draw object on accumulator OOM, bail out of the remaining
path-building callbacks, and have hb_gpu_draw_encode() return NULL once
the object has failed. Also check the encode scratch resizes and reset
poisoned vectors before reuse. Resetting the draw now fully resets the
curve vector as well, so callers can recover after an OOM by calling
hb_gpu_draw_reset().

Testing:
- meson test -C build --suite fuzzing --print-errorlogs
- meson test -C build

Co-authored-by: OpenAI Codex <codex@openai.com>
2026-04-03 16:29:27 -06:00
Behdad EsfahbodandOpenAI Codex 92b9b1ed82 [docs] Clarify OOM policy for experimental libraries
Document that raster, vector, and gpu still must not crash,
access out of bounds, or corrupt memory under failing-malloc,
but best-effort early failure is acceptable and complex rollback
logic is not required after OOM.

Co-authored-by: OpenAI Codex <codex@openai.com>
2026-04-03 16:24:31 -06:00
Behdad EsfahbodandOpenAI Codex 63c7d00e75 [docs] Require single-issue commits in AGENTS.md
Add an explicit commit-guidance rule to keep each commit focused on a
single issue or concern, instead of combining unrelated fixes,
renames, refactors, or behavior changes.

Co-authored-by: OpenAI Codex <codex@openai.com>
2026-04-03 16:04:14 -06:00
Behdad EsfahbodandOpenAI Codex a4aff49856 [gpu] Fix contour breaks and bounds quantization in encode (#5892)
Encode used adjacent endpoint equality to infer contour breaks, which
fails when two contours touch at the same point. Track contour starts
explicitly during accumulation instead, and use that flag when packing
shared endpoints.

Encode also rounded blob bounds to the nearest quarter unit. That can
shrink the encoded extents and clip coverage at glyph edges. Quantize
mins downward and maxes upward so the blob header always encloses the
actual geometry.

Add focused API tests for both regressions.

Testing:
- meson test -C build

Co-authored-by: OpenAI Codex <codex@openai.com>
2026-04-03 12:09:02 -06:00
Behdad Esfahbod 0234df4db6 [gpu] Fix WebGPU error page not showing when adapter unavailable
Check navigator.gpu synchronously in main() before calling
the WebGPU C API.  Previously the error was reported in an
async callback that raced with onRuntimeInitialized, which
hid the loading div before the error message could appear.

Also re-show the loading div and set window._webgpuError in
the adapter callback as a fallback.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-02 01:26:54 -06:00
Behdad Esfahbod 63cff45ae8 [ci] Disable docs build in Linux CI
Docs are built in the dedicated docs CI workflow.  Remove
gtk-doc-tools and disable docs in the Linux build.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-02 01:22:44 -06:00
Behdad Esfahbod 72bd5d3ae7 [ci] Move doc_tests from Linux CI to docs CI
The doc tests belong with the docs build, not the general
Linux build.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-02 01:22:03 -06:00
Behdad Esfahbod 84f15592dc [gpu] Hoist fwidth out of _hb_gpu_render_single
Compute pixelsPerEm once in hb_gpu_render and pass it down,
so MSAA samples share one fwidth call instead of each
computing their own.  Required for WGSL (fwidth must be
called from uniform control flow) and a minor win for all
backends.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-02 01:20:10 -06:00
Behdad Esfahbod 33baa306b2 [gpu] Fix docs for hb_gpu_draw_set_scale
Use XSince: REPLACEME and add to harfbuzz-sections.txt.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-02 01:19:42 -06:00
Behdad Esfahbod 60629a665d [gpu] Port scale/ppem/MSAA to MSL, WGSL, and HLSL shaders
Port the font-scale header, hb_gpu_ppem(), and adaptive MSAA
from hb_gpu_render() to all shader languages.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-02 01:11:07 -06:00
Behdad Esfahbod b4958570cf [gpu] Trim hb_gpu_render() doc comment
Assisted-by: Claude <noreply@anthropic.com>
2026-04-02 01:01:08 -06:00
Behdad Esfahbod e7c5b839eb [gpu] Store font scale in blob header; auto-MSAA in hb_gpu_render
Add hb_gpu_draw_set_scale() API and store x/y scale in the
glyph blob header (buf[1].b/a).  hb_gpu_draw_glyph() sets it
automatically from the font.

hb_gpu_render() now reads the scale, computes ppem via fwidth,
and automatically blends 4 corner samples at ±1/3 pixel when
ppem < 16 to reduce moiré at small sizes.  Define
HB_GPU_NO_MSAA to disable.

Add hb_gpu_ppem() public shader helper so clients can get
ppem without touching internal functions (e.g. for
hb_gpu_darken).

Remove hb_gpu_render_aaa(), u_upem uniform, and set_upem
plumbing from the demo — no longer needed.

GLSL only for now.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-02 00:59:39 -06:00
Behdad Esfahbod a255d9745b [gpu] Rework MSAA into hb_gpu_render_aaa with caller-provided ppem
Replace the two-program MSAA toggle with hb_gpu_render_aaa()
that takes ppem from the caller and auto-selects single-sample
(ppem >= 16) or 4-corner MSAA (ppem < 16).  This keeps
hb_gpu_render() lean for the fast path while letting the
adaptive function handle small sizes.

The previous approach had the ppem calculation inside the
library shader using 1/fwidth(texcoord), which was wrong by
a factor of upem — MSAA fired at all sizes.  Now the demo
passes correct ppem via a u_upem uniform.

Remove the 'm' key toggle, two-program compilation, and
set_msaa plumbing — no longer needed.

GLSL only for now.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-02 00:40:49 -06:00
Behdad Esfahbod fcfed99ce0 [gpu] Reduce MSAA from 3x3 grid to 4 corner samples
Use 4 samples at ±1/3 pixel corners instead of the full 3x3
grid.  Diagonal placement provides good moiré reduction at
half the cost.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-02 00:21:12 -06:00
Behdad Esfahbod 39d3b83b47 [gpu] Add GLFW_KEY_M to web GL stub for MSAA toggle
Assisted-by: Claude <noreply@anthropic.com>
2026-04-02 00:19:04 -06:00
Behdad Esfahbod 4f9048cd27 Revert "Revert small-size MSAA experiment"
This reverts commit 3c291a5015.
2026-04-02 00:18:05 -06:00
Behdad Esfahbod 5eb52c7407 [gpu] Fix display() signature in D3D11, Metal, and WebGPU renderers
Drop HB_UNUSED from the generation parameter — it's not
available in MinGW or Emscripten build contexts.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-01 23:52:54 -06:00
Behdad Esfahbod 61db984844 [gpu] Pass buffer generation to renderer display
The previous commit added the generation parameter to the
display interface but missed passing it from demo_view_display.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-01 23:29:15 -06:00
Behdad Esfahbod c86cb51bf6 [gpu] Fix garbled rendering after font change in web demo
The GL renderer cached the vertex buffer upload by comparing
the data pointer and count.  After clearing and refilling the
buffer with a new font's glyphs, std::vector reused the same
allocation, so the pointer and count matched — the upload was
skipped and the GPU drew with stale vertex data containing old
atlas offsets.

Fix by adding a generation counter to demo_buffer_t that
increments on clear().  The renderer compares generation and
count to decide whether to re-upload.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-01 23:25:48 -06:00
Behdad Esfahbod 3c291a5015 Revert small-size MSAA experiment
Reverts dc19a8002 and 7ac851ab6.  The improvement was not
worth the complexity or performance cost.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-01 23:09:36 -06:00
Behdad Esfahbod dc19a8002a [gpu] Add optional MSAA mode for small-size antialiasing
Add hb_gpu_render_msaa() that evaluates 9 samples (3x3 grid
at ±1/3 pixel) to reduce moiré at small sizes.  GLSL only.

The demo compiles two shader programs and toggles between them
with the 'm' key, so the MSAA program's register pressure
does not affect the fast single-sample path.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-01 23:08:30 -06:00
Behdad Esfahbod 7ac851ab6f [gpu] Add small-size MSAA to reduce moiré aliasing
At ppem < 16, blend in 4 extra samples at ±1/3 pixel offsets
to reduce moiré patterns and aliasing at small sizes.  The
blend factor transitions smoothly from full MSAA at ppem 8
to single-sample at ppem 16.

GLSL only for now; MSL, WGSL, and HLSL still use single-sample.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-01 22:50:46 -06:00
Behdad Esfahbod 5151ae0b34 [config] Fix HB_TINY build after HB_NO_CFF closure move
The HB_NO_DRAW closure must run before the HB_NO_CFF closure
so that HB_NO_DRAW → HB_NO_CFF → HB_NO_OT_FONT_CFF propagates
correctly in a single pass.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-01 15:03:53 -06:00
Behdad Esfahbod bd645e5573 [config] Move HB_NO_CFF from HB_LEAN to HB_NO_DRAW closure
CFF parsing requires the draw infrastructure, so it belongs
in the HB_NO_DRAW closure rather than being unconditionally
disabled by HB_LEAN.  This allows HB_LEAN and HB_TINY builds
that re-enable draw (via config-override.h) to also get CFF
support without explicitly undefining HB_NO_CFF.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-01 14:58:49 -06:00
Khaled Hosny a243dcb5c4 [ci] Fix docs deploy
We now have a subdir (hb-gpu-demo) so  needs .
2026-04-01 15:05:28 +02:00