Commit Graph
20996 Commits
Author SHA1 Message Date
Behdad Esfahbod 3dfd706145 [internal] More hb_unique_ptr_t conversions
Two more cleanup sites now that the alias works for all HB types:

hb-buffer-verify.cc:
  - buffer_verify_unsafe_to_break: fragment, reconstruction -> unique_ptr.
    Remove two hb_buffer_destroy pairs on success/fail paths.
  - buffer_verify_unsafe_to_concat: fragments[2] array + reconstruction
    -> unique_ptr.  Drop the goto-out cleanup cascade; the guards
    handle destruction on every return path.

hb-graphite2.cc:
  - _hb_graphite2_shaper_face_data_create: silf_blob -> unique_ptr.
    Collapse the two hb_blob_destroy sites (early-return and
    fall-through) to one.

All 240 tests pass.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 00:43:06 -06:00
Behdad Esfahbod 2e50079cbf [internal] Convert HB_SCOPE_GUARD HB-destroy sites to hb_unique_ptr_t
Now that hb_unique_ptr_t<T> is available for subsystem types via
the dual-trigger vtable registration, replace three hand-written
scope guards around hb_*_destroy calls with the typed wrapper:

  hb-raster-draw.cc hb_raster_draw_render:
    image_guard -> hb_unique_ptr_t<hb_raster_image_t> image.
    Final success path returns image.release ().

  hb-uniscribe.cc _hb_rename_font:
    HB_SCOPE_GUARD (hb_blob_destroy (blob)) -> hb_unique_ptr_t<hb_blob_t>.
    Rename the input parameter to blob_in so the owning handle can
    hold the (sanitized) blob under the plain name.

  hb-wasm-shape.cc face-data init:
    blob_guard for wasm_blob -> hb_unique_ptr_t<hb_blob_t>.
    data->wasm_blob = wasm_blob.release () on success.

Non-HB-type cleanups (wasm_module_t, wasm_exec_env_t, inflateEnd,
raw hb_malloc buffers) stay as scope guards.

All 240 tests pass.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 00:40:07 -06:00
Behdad Esfahbod 80bed0cc9f [cplusplus] Enable hb_unique_ptr_t for subsystem types
The vtable specializations for hb_{raster,vector,gpu,subset}_*_t in
hb-cplusplus.hh were gated behind #ifdef HB_<SUBSYSTEM>_H, which
only fires when a subsystem public header was included BEFORE
hb-cplusplus.hh.  Internal code includes hb-cplusplus.hh via hb.hh
long before any subsystem header, so those specializations never
activated — hb_unique_ptr_t<hb_raster_image_t> failed to compile.

Fix: keep the HB_DEFINE_VTABLE macro available (stop #undef'ing it at
the bottom of hb-cplusplus.hh) and add a paired tail block to each
subsystem public header that fires when HB_CPLUSPLUS_HH is already
defined.  Either include order now works.

Also fix the pre-existing const-correctness drift: the subsystem
_get_user_data functions took non-const T* while the vtable_t
template (matching the core types) expects const T*.  Add const to:

  hb_raster_image_get_user_data
  hb_raster_draw_get_user_data
  hb_raster_paint_get_user_data
  hb_vector_draw_get_user_data
  hb_vector_paint_get_user_data
  hb_gpu_draw_get_user_data

Signature-only change; all existing call sites keep compiling
because non-const arguments pass through const-pointer parameters
fine.  Source-compatible for consumers too.

All 240 tests pass.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 00:38:40 -06:00
Behdad Esfahbod 4650398a07 [gpu] encode() returns extents + auto-clears; drop get_extents() (#5910)
Bring hb_gpu_draw_encode into line with the rest of the render APIs:
auto-clear on success, and return the computed glyph extents to the
caller via a new out-parameter (nullable).

  HB_EXTERN hb_blob_t *
  hb_gpu_draw_encode (hb_gpu_draw_t      *draw,
                      hb_glyph_extents_t *extents);

Consumers typically need both the encoded blob and the glyph's
extents to size the quad they'll draw into in the vertex shader;
returning them together removes a redundant trip through the draw
state and lets encode() auto-clear like hb_vector_*_render() and
hb_raster_*_render() do.

Drop hb_gpu_draw_get_extents() from the public API — its only
role was reading extents out of the draw state post-encode, which
the new encode() signature makes redundant.  The computation
stays (moved to a static _hb_gpu_draw_get_extents helper) so
encode() can call it before auto-clear wipes the state.

ABI break for anyone who had already wired up against the 14.0.0
hb_gpu_draw_encode signature or hb_gpu_draw_get_extents, but the
library is new/experimental and the two in-tree consumers
(test/api/test-gpu.cc, util/gpu/demo-font.cc, util/hb-gpu-encode-all.cc,
test/fuzzing/hb-gpu-fuzzer.cc) are updated here.

All 240 tests pass.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 00:15:54 -06:00
Behdad Esfahbod 2891b2e6ad Merge pull request #5909 from harfbuzz/clears
Add _clear() methods to new libraries.
2026-04-12 22:02:42 -06:00
Behdad Esfahbod 040dce087f [docs] Drop implementation-detail notes from _clear/_reset docstrings
The "internal scratch buffers / encode buffer / image cache are
preserved for reuse" notes in hb_raster_draw_{clear,reset} and
hb_gpu_draw_{clear,reset} leak an implementation detail into the
public API docs.  Users shouldn't care; drop the lines.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 21:40:12 -06:00
Behdad Esfahbod 8ad69b4175 [docs] List the new _clear() entry points in harfbuzz-sections.txt
Follow-up to the _clear() API additions — add the five new public
symbols to the generated-docs section index so gtk-doc picks them up.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 21:27:51 -06:00
Behdad Esfahbod 3fa9ba2473 [api] Add _clear() companions to _reset() across render contexts
Introduce a public _clear() entry point on each render-context type
that discards accumulated output state while preserving user
configuration.  _reset() is redefined as _clear() plus resetting user
configuration to defaults — same observable effect as before, but
now there is one code path for the output-state teardown.

New public API:
  hb_vector_draw_clear()
  hb_vector_paint_clear()
  hb_raster_draw_clear()
  hb_raster_paint_clear()
  hb_gpu_draw_clear()

Contract:
  _clear(): preserves transform, scale factors, precision, flat,
            foreground, palette, custom palette colors.
  _reset(): equivalent to _clear() + resetting all user config.

The render/encode entry points now auto-clear on every exit path, so
the context is ready for the next glyph out of the box:

  hb_vector_draw_render (SVG + PDF) — ends with _clear().
  hb_vector_paint_render (SVG + PDF) — ends with _clear().
  hb_raster_draw_render — wraps body in HB_SCOPE_GUARD (_clear()).
  hb_raster_paint_render — wraps body in HB_SCOPE_GUARD (_clear()).

hb_gpu_draw_encode is intentionally NOT auto-clearing: its
hb_gpu_draw_get_extents() reads computed extents from the draw after
encode, so callers need that state preserved until they explicitly
clear.

Side fix: hb_vector_paint_clear() (and therefore _reset() and the
render paths) now correctly free the PDF backend's heap-allocated
hb_pdf_resources_t that had been leaking through clear_render_state.
hb_vector_paint_destroy() also free it now.  Expose
hb_vector_paint_pdf_free_resources() as HB_INTERNAL from
hb-vector-paint-pdf.cc for that.

All 240 tests still pass.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 21:27:00 -06:00
Behdad Esfahbod 80aea20b58 Merge pull request #5908 from harfbuzz/raii
Use some RAII error handling
2026-04-12 21:16:56 -06:00
Behdad Esfahbod 4e2627ada0 [internal] Add move constructor to hb_scope_guard_t
Pre-C++17 doesn't guarantee copy elision on factory function
returns, so hb_make_scope_guard() requires an accessible copy
or move constructor even if the temporary is elided in practice.
Deleting the copy constructor implicitly deletes the move
constructor, which broke CI on compilers not defaulting to
C++17-or-later guaranteed elision.

Add an explicit move constructor (transfers ownership, dismisses
the source's active flag) and keep move-assignment deleted.

Fixes build reported at hb-unicode.cc:406 via HB_UNICODE_FUNC_IMPLEMENT.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 20:22:00 -06:00
Behdad Esfahbod c550539bad [internal] RAII sweep (third batch): raster_paint_render + wasm acquire_plan
Two more cleanup paths converted to scope-guard form:

hb-raster-paint.cc hb_raster_paint_render:
  Factor the duplicated success/fail cleanup (transform_stack.clear,
  release_all_clips, surface_stack release+clear, clip_rdr reset,
  has_extents/fixed_extents reset) into a single HB_SCOPE_GUARD at
  the top of the function.  Collapses two cleanup blocks into one.

hb-wasm-shape.cc acquire_shape_plan:
  Replace four goto-fail sites and the shared "fail:" cleanup (free
  plan, deinstantiate module, destroy exec_env) with three scope
  guards released on success.

All 240 tests pass.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 20:11:44 -06:00
Behdad Esfahbod 5b4b363e20 [internal] RAII sweep (second batch): 12 more cleanup sites
Convert additional cleanup patterns across the codebase to use
HB_SCOPE_GUARD / hb_make_scope_guard.  All changes are mechanical
replacements of goto-based cleanup with scope guards; no behavior
changes.

Destroy-on-fail funcs-setter pattern (identical body in four files):
  - hb-draw.cc _hb_draw_funcs_set_middle
  - hb-font.cc _hb_font_funcs_set_middle
  - hb-paint.cc _hb_paint_funcs_set_middle
  - hb-unicode.cc HB_UNICODE_FUNC_IMPLEMENT macro
  Replace two goto-fail sites per function with one scope guard that
  runs destroy(user_data), released on the success path.

Resource cleanup with multi-exit paths:
  - hb-gdi.cc _hb_gdi_reference_table: GDI DC + hb_malloc buffer
    via paired scope guards; collapse three fail labels to returns.
  - hb-wasm-shape.cc face-data init: wasm_blob + wasm_module via
    scope guards.
  - hb-uniscribe.cc _hb_rename_font: hb_blob + hb_calloc'd sfnt
    buffer via scope guards.
  - hb-ft.cc _hb_ft_reference_table: hb_malloc'd FT buffer via
    scope guard.
  - hb-ot-font.cc hb_ot_draw_glyph_or_fail: release_gvar_cache via
    scope guard; remove the goto done cascade in the backend walk.
  - hb-raster-draw.cc hb_raster_draw_render: per-exit state reset
    via scope guard; image cleanup via scope guard released on
    success.
  - hb-coretext.cc CTFontCopyAvailableTables walker + variations
    extractor: CFRelease pairs via scope guards.

Pure control-flow cleanup (no RAII, just goto→return):
  - hb-raster-paint.cc: four "goto done" sites in gradient paint
    funcs where done: body was only (void) stops_ — remove label,
    use return directly.

All 240 tests still pass.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 20:09:44 -06:00
Behdad Esfahbod 869b55e690 [internal] Use HB_SCOPE_GUARD for non-HB cleanup paths
Convert three sites where manual cleanup-per-return-path (or
goto-fail cascades) can be replaced by a single scope-guard
registration.  Fewer lines, one place to read the cleanup rule,
and no cleanup-duplication drift over time.

hb-zlib.cc hb_blob_decompress_gzip:
  - Replace goto fail / fail_free cascade with two scope guards
    (one for inflateEnd, one for hb_free(output)).
  - Release the output guard on the success path before the blob
    takes ownership.

hb-vector-paint-pdf.cc hb_pdf_build_indexed_smask:
  - Three hb_malloc'd buffers (raw, unfiltered, prev_unfiltered)
    with six early-return cleanup sites each flattened to one
    guard per allocation.

hb-cairo-utils.cc _hb_cairo_add_sweep_gradient_patches:
  - Replace the "fall through to done: and conditionally free
    heap-allocated angles/colors" pattern with two scope guards
    that check-and-free; drop the goto done; eliminate the done:
    label entirely.

26 lines removed, no behavior change; 240 tests pass.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 19:59:19 -06:00
Behdad Esfahbod 1dcf59ea52 [internal] Add hb_scope_guard_t + HB_SCOPE_GUARD() macro
Generic RAII cleanup helper for the long tail of non-HB-type
resources — raw malloc'd buffers, paired init/end calls like
inflateInit/inflateEnd, FT_Done_* handles, third-party opaque
state, etc.  For HB-typed resources prefer hb_unique_ptr_t<T>,
which already uses the type's hb_*_destroy() via vtable.

Usage:
  void *buf = hb_malloc (len);
  if (!buf) return false;
  HB_SCOPE_GUARD (hb_free (buf));
  ... multiple fallible operations ...
  return true;  // buf freed automatically on any return path

The guard also supports explicit release() for cases where
ownership is transferred out on success.

Uses __LINE__ for unique naming (standard; consistent with other
line-indexed macros in this codebase).  One guard per line is the
convention; putting two on the same line would collide.

Follow-up commits sweep existing manual-cleanup sites to use
hb_unique_ptr_t / HB_SCOPE_GUARD where they fit.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 19:53:57 -06:00
Behdad Esfahbod c3b32f59fc [internal] Add hb_unique_ptr_t alias for hb::unique_ptr
hb-cplusplus.hh already defines hb::unique_ptr<T> — a type-aware
RAII wrapper that destroys an HB object on scope exit via the
type's hb_*_destroy() function.  Expose it to internal library
code under the hb_*_t naming convention so cleanup paths can use
it without qualification and without pulling the whole hb::
namespace in.

  Usage: hb_unique_ptr_t<hb_blob_t> blob (hb_blob_create_or_fail (...));
         // destroyed automatically on scope exit
         return blob.release ();  // transfer ownership out

No functional change — this commit just adds the alias.  Follow-up
commits will introduce hb_scope_guard_t for non-HB-type cleanup
and sweep existing manual cleanup paths to use both.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 19:51:38 -06:00
Behdad Esfahbod 186238e016 [cplusplus] Add hb-gpu type 2026-04-12 19:29:56 -06:00
Khaled Hosny 460d28f9ca [vector] Fix doc-check 2026-04-13 02:56:09 +02:00
Khaled Hosny 45465a506e [ci] Run doc tests in docs workflow 2026-04-13 02:56:09 +02:00
Behdad Esfahbod a1939317e2 Merge pull request #5905 from harfbuzz/svg-remove
[raster][vector] Remove SVG-font glyph source rendering
2026-04-12 01:26:39 -06:00
Behdad Esfahbod 32596c0f7d [vector] Rename SVG-specific helpers: hb_svg_ -> hb_vector_svg_
Rename the remaining hb_svg_* internal helpers (those that really
do emit SVG syntax or carry SVG-specific semantics) to the
hb_vector_svg_* prefix, matching the filenames of the hb-vector
SVG output backend.

Renames:
  hb_svg_append_instance_transform  -> hb_vector_svg_*
  hb_svg_extend_mode_str            -> hb_vector_svg_*
  hb_svg_emit_color_stops           -> hb_vector_svg_*
  hb_svg_composite_mode_str         -> hb_vector_svg_*
  hb_svg_paint_append_global_transform_{prefix,suffix}
                                    -> hb_vector_svg_paint_*
  hb_svg_path_*                     -> hb_vector_svg_path_*
  hb_svg_add_sweep_patch            -> hb_vector_svg_add_sweep_patch
  hb_svg_point_t / hb_svg_rgba_t    -> hb_vector_svg_*
  hb_svg_{add,sub,scale,dot,lerp,clamp01,normalize,
          lerp_rgba,rgba_from_hb_color,hb_color_from_rgba,
          buffer_contains}          -> hb_vector_svg_*
    (math + color helpers scoped to the SVG-sweep-patch emitter)

All internal symbols — no public API affected.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 23:16:47 -06:00
Behdad Esfahbod de8a7fc6cf [vector] Rename neutral helpers: drop hb_svg_ prefix
Several internal helpers in the hb-vector library carry an
hb_svg_ prefix for historical reasons but are not SVG-specific —
they do generic math, transform points, compute extents, manage
blob recycling metadata, compare color stops, etc.  Now that the
SVG-font input code is gone and these helpers are used equally
from the SVG and PDF output backends, rename them to match their
true scope.

Renames:
  hb_sweep_gradient_tiles        -> hb_vector_sweep_gradient_tiles
  hb_svg_transform_point         -> hb_vector_transform_point
  hb_svg_set_glyph_extents_common-> hb_vector_set_glyph_extents_common
  hb_svg_scale_precision         -> hb_vector_scale_precision
  hb_svg_decimal_point_*         -> hb_vector_decimal_point_*
  hb_svg_color_glyph_cache_key   -> hb_vector_color_glyph_cache_key
  hb_svg_color_glyph_cache_key_t -> hb_vector_color_glyph_cache_key_t
  hb_svg_get_color_stops         -> hb_vector_get_color_stops
  hb_svg_color_stop_cmp          -> hb_vector_color_stop_cmp
  hb_svg_blob_meta_*             -> hb_vector_blob_meta_*

All internal symbols — no public API affected.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 23:15:40 -06:00
Behdad Esfahbod 5e6ae10f62 [raster][vector] Remove SVG-font glyph source rendering
Remove support for rendering glyphs whose source is the OpenType
SVG table, in both hb-raster and hb-vector.  SVG is a large format
and our in-tree parser/renderer was half-finished; the complexity
was not justified by the partial coverage.

This is source-side only: hb-vector's SVG *output* backend (used
to serialize outline / COLR glyphs to SVG) is unaffected.  Fonts
that have an SVG table will still load; glyphs served only by that
table will not render from these libraries.

hb-raster:
  - Delete the hb-raster-svg-* file cluster (11 .cc/.hh files plus
    hb-raster-svg.hh: parse, base, bbox, clip, color, defs,
    defs-scan, fill, gradient, parse, render, use, context).
  - Drop svg_glyph/svg_font/svg_palette state from
    hb_raster_paint_t and the HB_PAINT_IMAGE_FORMAT_SVG branch in
    the image callback.
  - Drop hb_raster_paint_push_clip_path + hb_raster_svg_path_func_t
    (only used from the SVG renderer).
  - Drop zlib dependency (gzip decompression was only used for the
    SVG table reader; libpng brings its own zlib linkage for PNGs).

hb-vector:
  - Delete hb-vector-svg-subset.{cc,hh} (extracted font-SVG glyph
    for embedding in SVG output).
  - Remove the HB_TAG('s','v','g',' ') branch from the image paint
    callback; PNG embedding remains.
  - Drop svg_image tracking state from hb_vector_paint_t
    (current_color_glyph_has_svg_image, current_svg_image_glyph,
    current_face, svg_image_counter, subset_body_scratch).
  - Simplify the color-glyph cache to store just def_id instead of
    packed (def_id, image_like).
  - Drop hb_svg_append_image_instance_translate.

Build wiring: src/meson.build, CMakeLists.txt, harfbuzz-world.cc
updated to match.  Test suite: remove SVG-specific cases from
test/api/test-raster.cc and the handwriting-{svg,picosvg} vector
tests + expected fixtures.

~5700 LOC deleted, ~10 LOC added.  Full test suite (240 tests)
passes.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 22:46:35 -06:00
Qunxin Liu 380ae0122f [subset-repack] dont duplicate node that might be shared (#5889)
repacker will duplicate it if actually needed
2026-04-11 22:23:40 -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 90741274fc [vector] Extract hb_vector_paint_render_svg helper
Move the SVG case out of the hb_vector_paint_render switch into its
own static helper, matching the hb_vector_paint_render_pdf and
hb_vector_draw_render_{svg,pdf} pattern.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 22:06:35 -06:00
Behdad Esfahbod 7b6f26e844 [vector] Address review feedback
- Default hb_vector_{draw,paint}_t::format to HB_VECTOR_FORMAT_INVALID
  instead of HB_VECTOR_FORMAT_SVG.
- Update renamed hb_vector_{draw,paint}_set_{flat,precision} API docs
  from "Since: 13.0.0" to "XSince: REPLACEME".
- Extract hb_vector_draw_render_svg() helper to match the
  hb_vector_draw_render_pdf() pattern; move the misplaced
  hb_vector_draw_render doc comment to the actual function and update
  it to say "output blob" since the renderer is no longer SVG-only.
- Revert 14.0.0 NEWS entry edits; the API rename will be announced in
  the next release entry.
- Update docs/harfbuzz-sections.txt to reflect the API renames.
- hb-vector tool: expose -O/--output-format with supported formats
  "svg/pdf", validate format, update description string, and switch
  PDF detection to g_ascii_strcasecmp for case-insensitive matching.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 22:02:38 -06:00
Kyr1o5anddefault f099a260d9 Fix: Add safety limits to hb-repacker to prevent algorithmic complexity attacks (#5904)
* Fix: Algorithmic Complexity DoS in HarfBuzz Repacker

Introduce total iteration limits in overflow resolution loop and physical growth limits (vertices and spaces) to prevent Hang/OOM during subsetting of malicious fonts.

* Repacker: Move safety limits to hb-limits.hh as requested by Behdad

---------

Co-authored-by: default <default@zimbra.0day.lab>
2026-04-10 18:06:24 -06:00
Behdad Esfahbod 81a9830f30 [gpu] Make Escape exit fullscreen before quitting
When in fullscreen mode, pressing Escape now exits fullscreen
instead of closing the application. Pressing Escape again (or Q
at any time) still quits.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 18:05:00 -06:00
Behdad Esfahbod 3f6c0e48ad [vector] Switch format selection from if/else to switch
Replace all if/else chains on hb_vector_format_t with switch
statements, making the format dispatch explicit and extensible.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 12:34:21 -06:00
Behdad Esfahbod ca8f48de2d [vector] Rename source files and internal API for consistency
Rename files to follow hb-vector-{draw,paint}[-{svg,pdf}] convention:

  hb-vector-svg-draw.cc  -> hb-vector-draw.cc
  hb-vector-svg-paint.cc -> hb-vector-paint.cc
  hb-vector-pdf-paint.cc -> hb-vector-paint-pdf.cc

Rename internal API to match:

  hb_vector_pdf_paint_funcs_get -> hb_vector_paint_pdf_funcs_get
  hb_vector_pdf_paint_render    -> hb_vector_paint_render_pdf

Remove stale declarations for hb_vector_svg_paint_funcs_get and
hb_vector_svg_paint_render which were declared but never defined.

Update meson.build, CMakeLists.txt, and harfbuzz-world.cc.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 12:28:36 -06:00
Behdad Esfahbod 30ee1bb2c6 [vector] Rename hb_vector_svg_*set_{flat,precision} API
Drop "svg" from the names since flat/precision settings apply
equally to PDF output.  The new names follow the hb_vector_draw_*
/ hb_vector_paint_* convention:

  hb_vector_svg_set_flat         -> hb_vector_draw_set_flat
  hb_vector_svg_set_precision    -> hb_vector_draw_set_precision
  hb_vector_svg_paint_set_flat   -> hb_vector_paint_set_flat
  hb_vector_svg_paint_set_precision -> hb_vector_paint_set_precision

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 12:16:55 -06:00
Behdad Esfahbod fdf3325b78 Merge pull request #5903 from harfbuzz/fuzzer-fixes-apr9
Fuzzer fixes apr9
2026-04-09 23:40:46 -06:00
Behdad Esfahbod 6c2afd1e0e [geometry] Clamp glyph extents conversion
hb_extents_t::to_glyph_extents() rounded bounds to hb_position_t
before subtracting them. Extreme extents from fuzzed VARC and
raster paths could therefore overflow signed int arithmetic while
forming glyph widths or heights.

Compute the rounded endpoints in double, clamp the exported values
to hb_position_t, and reject non-finite results. Also avoid the
same overflow in the reverse hb_glyph_extents_t constructor, add
an internal regression for the shared helper, and include the
minimized raster testcase.

Fixes: https://oss-fuzz.com/testcase-detail/4826864710647808
Not-tested: Skipped by request.
Assisted-by: OpenAI Codex
2026-04-09 23:21:05 -06:00
Behdad Esfahbod b5287cb3fb [gpu] Clamp exported draw extents
hb_gpu_draw_get_extents() cast rounded bounds to hb_position_t
before subtracting them. A fuzzed glyph outline with an extreme
negative bound could therefore overflow signed int arithmetic while
forming width or height.

Compute the rounded bounds in double, reject non-finite values, and
clamp the exported extents to hb_position_t before returning them.
Add an API regression that covers the OSS-Fuzz testcase through the
public GPU draw API.

Fixes: https://oss-fuzz.com/testcase-detail/5918954634936320
Tested: meson test -C build --print-errorlogs
Assisted-by: OpenAI Codex
2026-04-09 23:15:34 -06:00
💀 f4600f3c87 test: add hb-ft load-flag preservation regression 2026-04-09 14:57:29 -06:00
💀 ff36ee1da5 ft: preserve load flags in hb_ft_font_set_funcs 2026-04-09 14:57:29 -06:00
Behdad Esfahbod fb594d4afe [rust] Roll HarfRust to 0.6.0 2026-04-09 13:10:59 -06:00
Behdad Esfahbod 0967927b88 [vector] Extract shared sweep gradient tiling logic
Move the sweep gradient color stop tiling (pad/repeat/reflect
across 0-2π) into a shared template hb_sweep_gradient_tiles()
in hb-vector-svg-utils.hh.  Both SVG and PDF backends now call
it with their own patch emitter callback.

Also adds hb_color_lerp() to the shared header (fixing an R/B
channel swap bug in the PDF version's interpolation).

Net reduction of ~170 lines of duplicated tiling code.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
Behdad Esfahbod d80e1da9cd [vector] Implement PDF PNG image embedding with transparency
Add PNG image support to the PDF paint backend. Parses PNG chunks
to extract IHDR metadata and IDAT compressed data, then embeds
directly as PDF XObject Image with /FlateDecode and /Predictor 15
(PNG predictor), avoiding any re-encoding of pixel data.

Supports:
- Grayscale, RGB, Gray+Alpha, RGBA (8-bit)
- Indexed color (palette PNG) via /Indexed colorspace with PLTE
- Transparency for indexed PNG via SMask: decompresses IDAT,
  un-filters PNG rows, maps palette indices to tRNS alpha values,
  and emits a separate DeviceGray soft mask image

Tested with NotoColorEmoji.ttf (CBDT, indexed PNG with partial
alpha) and sbix.ttf (SBIX, RGBA PNG).

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
Behdad Esfahbod 184b5bb7c3 [vector] Implement PDF blend modes via push_group_for
Use the new push_group_for API to emit PDF ExtGState with /BM
(blend mode) when the compositing mode has a PDF 1.4 equivalent.

Maps 15 blend modes: Multiply, Screen, Overlay, Darken, Lighten,
ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion,
Hue, Saturation, Color, Luminosity.

Porter-Duff modes (Clear, Src, Dst, etc.) have no direct PDF /BM
equivalent and fall back to the default (Normal/SrcOver).

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 20:12: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
Behdad Esfahbod 39f622285e [vector] Fix PDF sweep gradient to tile across full circle
The previous implementation only covered start_angle to end_angle
with a fixed number of equal sectors, which broke repeat/reflect
extend modes and produced too few patches for oscillating gradients.

Rewrite to use the same tiling logic as the SVG sweep gradient:
map color stops to angles, handle pad/repeat/reflect extend modes,
and tile across the full 0-2π range. Each color stop interval
becomes one Coons patch (further split at 90° max for arc quality).

Tested with sweep_270_440_reflect_narrow glyph from
test_glyphs-glyf_colr_1_variable.ttf.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
Behdad Esfahbod c67c323d0b [vector] Rename hb_svg_append_* to hb_buf_append_*
The buffer helper functions (append_str, append_len, append_c,
append_num, append_unsigned, append_hex_byte, append_base64,
recover_recycled, blob_from) are format-agnostic and used by
both SVG and PDF backends.  Rename from hb_svg_* to hb_buf_*
to reflect this.

SVG-specific helpers (append_color, append_instance_transform,
transform_point, scale_precision, etc.) keep their hb_svg_*
names.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
Behdad Esfahbod 4087416a68 [vector] Add hb-vector-pdf-paint.cc to harfbuzz-world.cc
Assisted-by: Claude <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
Behdad Esfahbod 6abf48a9e5 [vector] Implement PDF sweep gradient via Type 6 Coons patches
Replace the pie-slice sector fallback with proper Type 6
Coons patch mesh shading.  Each sector of the sweep is a
patch with:
  - Outer arc approximated by cubic Bézier (kappa method)
  - Inner arc at small radius to avoid degenerate geometry
  - Radial straight edges connecting inner and outer
  - Corner colors from the color line at sector boundaries

Sectors are limited to 90° for accurate Bézier arc
approximation, with a minimum of 4 patches per sweep.

The mesh data is encoded as a binary stream with 16-bit
coordinates, 8-bit color components, and 8-bit flags per
the PDF Type 6 specification.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
Behdad Esfahbod 4086e62808 [vector] Implement PDF sweep gradient via sector decomposition
Decompose sweep gradients into 360 colored pie-slice sectors.
Each sector evaluates the color line at its midpoint and emits
a filled triangular path from the center to two points on a
large-radius arc.

Includes a color line evaluator that handles pad, repeat, and
reflect extend modes with linear interpolation between stops.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
Behdad Esfahbod 30be6b8b53 [vector] Add alpha, linear, and radial gradients to PDF paint
Rewrite hb-vector-pdf-paint.cc with a proper PDF object
system that supports dynamic resource generation:

Alpha:
  Solid colors with alpha < 1 now emit ExtGState objects
  with /ca (fill opacity) and reference them via /GSn gs
  in the content stream.

Gradients:
  Linear gradients → PDF Type 2 (axial) shading with
  Type 2/3 interpolation functions for color stops.
  Radial gradients → PDF Type 3 (radial) shading.
  Sweep gradients → solid fallback (no PDF equivalent).

Architecture:
  A hb_pdf_resources_t collector tracks extra PDF objects
  (ExtGState, Shading, Function) during painting.  At render
  time, these are emitted as numbered objects and referenced
  from the Page's Resources dictionary.

Mark internal symbols HB_INTERNAL to fix check-symbols test.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
Behdad Esfahbod e197c13f8b [vector] Fix PDF paint glyph Y-flip
Remove the -xy/-yy negation from the PDF paint glyph
positioning transform.  Font and PDF coordinates are both
Y-up, so no flip is needed.  Same fix as was applied to
the draw path earlier.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
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