Commit Graph
21026 Commits
Author SHA1 Message Date
dependabot[bot] 2ae3d08919 Bump actions/upload-artifact from 7.0.0 to 7.0.1
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 7.0.0 to 7.0.1.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/bbbca2ddaa5d8feaa63e36b76fdaad77386f024f...043fb46d1a93c77aae656e7c1c64a875d1fc6a0a)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: 7.0.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-13 22:46:19 +02:00
dependabot[bot] 0f2f2f49d6 Bump mymindstorm/setup-emsdk from 15 to 16
Bumps [mymindstorm/setup-emsdk](https://github.com/mymindstorm/setup-emsdk) from 15 to 16.
- [Release notes](https://github.com/mymindstorm/setup-emsdk/releases)
- [Commits](https://github.com/mymindstorm/setup-emsdk/compare/667eb33f24e84e7f362c16d8d7fff0629a73e15e...4528d102f7230f0e7b276855c01ea1159be0e984)

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

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-13 22:46:05 +02:00
Behdad Esfahbod f587af3ec3 [gpu] Extract shared shader helpers into hb_gpu_shader_source() (#5921)
The draw-renderer fragment shaders defined utilities
(HB_GPU_UNITS_PER_EM, the hb_gpu_atlas uniform, hb_gpu_fetch) that
any future GPU renderer will also need.  The draw-renderer vertex
shader likewise contained only the generic hb_gpu_dilate helper.
If a paint renderer were added today and a caller linked both
fragment sources together, hb_gpu_fetch would be defined twice.

Move these shared helpers into a new family of sources and expose
them via a new public entry point:

  hb_gpu_shader_source (stage, lang);

The existing hb_gpu_draw_shader_source() now returns only the
draw-specific fragment code; it returns an empty string for the
vertex stage because all current vertex logic is shared.  Callers
concatenate the shared source first, then the draw-specific
source, then their own main():

  [#version, hb_gpu_shader_source (...), hb_gpu_draw_shader_source
  (...), main]

Additions:
 - src/hb-gpu-fragment.{glsl,msl,wgsl,hlsl} — shared fragment
 - src/hb-gpu-vertex.{glsl,msl,wgsl,hlsl}   — shared vertex,
   renamed from hb-gpu-draw-vertex.*
 - src/hb-gpu-shaders.cc — hb_gpu_shader_source() dispatcher

Removals:
 - src/hb-gpu-draw-vertex.{glsl,msl,wgsl,hlsl} — moved to common

Shared sources are Behdad-only copyright; the Eric Lengyel / Slug
attribution stays on the draw-specific fragment sources where the
Slug algorithm actually lives.

Updates: test/api/test-gpu.cc, the Metal/D3D11/WebGPU/GL demo
shaders, the hb-gpu SECTION documentation, meson.build,
CMakeLists.txt, gen-gpu-shader-artifacts.py decl_map,
harfbuzz-world.cc, and docs/harfbuzz-sections.txt.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 12:10:23 -06:00
jfkthame 603ab95602 Return size_t rather than unsigned int from get_size() (#5915)
* [subset] Return size_t rather than unsigned from get_size() methods

It's possible some get_size() computations during serialization
may overflow 32-bit arithmetic.

(The result of get_size() is used as size_t when allocating via
hb_serialize_context_t::extend(), but if the return value was
declared as unsigned int, the value may have wrapped resulting
in under-allocation.)

* [subset] Use size_t when accumulating subset_data_size

* [graph] Use size_t (rather than signed int64_t) for vertex_len variables

* Use size_t for sanitize_closure_t::stride to avoid narrowing
2026-04-13 11:01:19 -06:00
Behdad Esfahbod e2d68946bf Merge pull request #5916 from harfbuzz/survey-cleanup
More new-lib cleanup
2026-04-13 04:08:42 -06:00
Behdad Esfahbod 90678d6876 [docs] Register new raster and vector getters in sections.txt
Add the eight new getters introduced in the recent API-cleanup
commits to their section indexes:

  hb_raster_paint_get_foreground
  hb_raster_paint_set_palette
  hb_raster_paint_get_palette
  hb_vector_draw_get_flat
  hb_vector_draw_get_precision
  hb_vector_paint_get_foreground
  hb_vector_paint_get_palette
  hb_vector_paint_get_flat
  hb_vector_paint_get_precision

Without these entries gtk-doc's doc-check flags the new symbols
as undocumented.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 03:49:56 -06:00
Behdad Esfahbod aded5fccad [raster] Make hb_raster_image_serialize_to_png_or_fail const
The function only reads the image; the internal
hb_raster_image_t::serialize_to_png_or_fail() method is already
declared const.  Take a const pointer at the public API boundary.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 03:39:36 -06:00
Behdad Esfahbod d0c9edd7fe [vector] Add getter companions for set_flat, set_precision,
set_foreground, set_palette

Every storable setter on hb_vector_draw_t and hb_vector_paint_t
now has a matching getter, matching the symmetry already present
for transform/scale_factor/extents:

  hb_vector_draw_get_flat ()
  hb_vector_draw_get_precision ()
  hb_vector_paint_get_flat ()
  hb_vector_paint_get_precision ()
  hb_vector_paint_get_foreground ()
  hb_vector_paint_get_palette ()

set_glyph_extents has no getter companion since it does not store
its input; it transforms the glyph extents into the context's
pixel-space extents, which are already retrievable via
hb_vector_*_get_extents().

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 03:38:34 -06:00
Behdad Esfahbod 83b4b27f52 [raster] Mark hb_raster_paint_glyph as XSince: REPLACEME
The signature of hb_raster_paint_glyph() changed in the previous
commit (palette and foreground parameters dropped).  Update its
docstring from "Since: 13.0.0" to "XSince: REPLACEME" so the
release engineer documents it under the new release.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 03:37:06 -06:00
Behdad Esfahbod f9de50ab52 [raster] Simplify hb_raster_paint_glyph; add set/get_palette
hb_raster_paint_glyph() took the palette index and foreground
color as per-call arguments, duplicating state that also lives on
the paint context (foreground via hb_raster_paint_set_foreground,
palette previously only available as a per-call arg).  This gave
callers two paths for configuring the same state.

Drop the per-call palette/foreground arguments and require callers
to configure them via setters before painting, matching the
already-established pattern in hb_vector_paint_glyph() and
elsewhere in the subsystem.

- Drop palette and foreground args from hb_raster_paint_glyph().
- Add hb_raster_paint_set_palette() / _get_palette() and a
  hb_raster_paint_get_foreground() companion.
- Store palette on hb_raster_paint_t (default 0).
- Update util/raster-output.hh, util/hb-raster-all.cc, and
  test/fuzzing/hb-raster-fuzzer.cc to the new API.
- Update the hb-raster section-doc example.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 03:35:47 -06:00
Behdad Esfahbod 403c872b13 Merge pull request #5914 from harfbuzz/survey-cleanup
A few cleanups of new libraries
2026-04-13 03:25:23 -06:00
Behdad Esfahbod b8c27ad659 [subset] Rename glyph_index to glyph in CFF charstring-data API
The two experimental CFF charstring-data accessors:

  hb_subset_cff_get_charstring_data (hb_face_t *, hb_codepoint_t);
  hb_subset_cff2_get_charstring_data (hb_face_t *, hb_codepoint_t);

used "glyph_index" as the parameter name, inconsistent with the
rest of the project where glyph-ID parameters are uniformly named
"glyph".  Both APIs are behind HB_EXPERIMENTAL_API so the rename
is safe.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 03:13:37 -06:00
Behdad Esfahbod 59f71c0694 [gpu] Restructure section doc: module intro + Draw subsection
Split the hb-gpu SECTION comment into a brief module-level intro
and a dedicated Draw subsection covering the existing encoder and
shader documentation.

Today the doc block opens with Slug-specific framing ("This module
implements the Slug algorithm...") and uses top-level headings for
encoding, atlas setup, shader compilation, vertex/fragment shader
helpers, and stem darkening.  All of that belongs specifically to
the hb_gpu_draw_t renderer.  Gather it under a single "Draw"
heading and demote the former top-level headings by one level so
the section structure reflects that it documents one renderer.

Also update @short_description to "GPU text rendering" since the
module name no longer hints that encoding is its only role.

No content changes beyond headings and the opening paragraphs; no
API change.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 03:03:55 -06:00
Behdad Esfahbod 1e70544d32 [gpu] Rename hb-gpu-shaders.cc to hb-gpu-draw-shaders.cc
The file implements hb_gpu_draw_shader_source() and only dispatches
draw-subsystem shader sources.  Matching the file-naming convention
recently applied to the .glsl/.msl/.wgsl/.hlsl sources and their
generated .hh artifacts.

No behavior change; updates CMakeLists.txt, src/meson.build, and
src/harfbuzz-world.cc to reference the new filename.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 03:02:38 -06:00
Behdad Esfahbod a44eb976dc [gpu] Rename hb_gpu_draw_darken -> hb_gpu_stem_darken
The previous commit renamed hb_gpu_darken to hb_gpu_draw_darken
for symmetry with hb_gpu_draw (formerly hb_gpu_render).  But the
operation isn't draw-subsystem specific: it adjusts a coverage
value based on foreground brightness and ppem, which is just the
standard stem-darkening recipe.  Name it after what it does.

Paint doesn't need its own variant — it can call this same
function on any alpha/coverage channel it produces.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 02:59:37 -06:00
Behdad Esfahbod daddae08a3 [gpu] Rename fragment-shader entry points with "draw_" prefix
Rename the public fragment-shader entry points provided by the
hb_gpu_draw_t renderer:

  hb_gpu_render(...)   -> hb_gpu_draw(...)
  hb_gpu_darken(...)   -> hb_gpu_draw_darken(...)

Also rename the internal helper:

  _hb_gpu_render_single(...) -> _hb_gpu_draw_single(...)

A COLRv1 paint renderer is planned and will provide its own
fragment entry point (likely hb_gpu_paint returning a vec4); the
existing draw/coverage entry point gets a subsystem-qualified name
now so draw and paint can coexist.

Updates the .glsl/.msl/.wgsl/.hlsl sources, regenerated .hh
artifacts, the documentation block in hb-gpu.cc, and the util/gpu
demo shaders.  No behavior change.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 02:57:07 -06:00
Behdad Esfahbod 60a4e49aec [gpu] Rename draw shader files/symbols with "draw-" prefix
Rename hb-gpu-{fragment,vertex}.{glsl,msl,wgsl,hlsl} and their
generated .hh artifacts to hb-gpu-draw-{fragment,vertex}.{glsl,msl,
wgsl,hlsl}.  Likewise rename the C symbols in each artifact from
hb_gpu_{fragment,vertex}_<lang> to hb_gpu_draw_{fragment,vertex}_<lang>.

These are the shader sources for the hb_gpu_draw_t (Slug-style
coverage) renderer.  A COLRv1 paint renderer is planned and will
introduce its own hb-gpu-paint-*.{glsl,...} shader family, so the
existing shaders need a subsystem-qualified name to disambiguate.

No behavior change; hb_gpu_draw_shader_source() keeps returning the
same strings.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 02:52:02 -06:00
Behdad Esfahbod 83c7371098 [vector] Check offsets.resize result in PDF render
Follow-up to 891cb21c7 in the same direction: hb_vector_paint_render_pdf
called offsets.resize(total_objects) without checking the return value,
then dereferenced offsets.arrayZ[0] unconditionally.  Under failing-malloc
the resize leaves arrayZ null and we crash.

Return nullptr on resize failure; callers already handle a null blob.

Found by the OSS-Fuzz hb-vector-fuzzer with OOM injection, same trip as
the earlier hb_pdf_get_resources crash.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 02:47:18 -06:00
Behdad Esfahbod eeec9bd9fa [gpu] Unify shader source getters; rename for draw/paint split
Replace the two separate getters

  hb_gpu_shader_fragment_source (lang)
  hb_gpu_shader_vertex_source   (lang)

with a single

  hb_gpu_draw_shader_source (stage, lang)

where stage is the new hb_gpu_shader_stage_t enum (VERTEX or
FRAGMENT).  Parameter order is stage-first because "the vertex
shader in GLSL" reads more naturally than the reverse, and stage
is the primary axis (it determines which shader object the source
is compiled into).

The `_draw_` in the new name makes room for the incoming
hb_gpu_paint_shader_source() once the COLRv1 encoder lands —
that family will have its own (likely different) shader sources
per stage and language.

Updated the four in-tree callers: test/api/test-gpu.cc, and the
GPU demos under util/gpu/.  ABI break on a 14.0-only API; the
gpu library is still young enough that this is acceptable.

Marked new API with XSince: REPLACEME.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 02:26:21 -06:00
Behdad Esfahbod 891cb21c7b [vector] Fix NULL write in hb_pdf_get_resources under OOM
hb_pdf_get_resources stashes a heap-allocated hb_pdf_resources_t
pointer into the reused paint->defs vector.  It called
paint->defs.resize(sizeof(void*)) and ignored the return value,
then memcpy'd into paint->defs.arrayZ.  Under failing-malloc
(reached by the fuzzer), resize can fail leaving arrayZ as nullptr,
and the subsequent memcpy dereferences NULL.

Check the resize result.  On failure, destruct + free the
already-constructed resources struct and return nullptr — which
all callers of hb_pdf_get_resources already handle.

Found by the OSS-Fuzz hb-vector-fuzzer after the prior commit
that enabled PDF-format fuzzing.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 02:17:36 -06:00
Behdad Esfahbod 4c94a812b0 [vector] Drop redundant scale-factor > 0 guard in transform_point
hb_vector_transform_point () had a guard "(x_scale_factor > 0 ?
x_scale_factor : 1.f)" on divisions.  The setters on both
hb_vector_paint_t and hb_vector_draw_t already clamp scale factors
to > 0 at input, and every other use site in the vector code trusts
that invariant.  The guard here was redundant; drop it.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 02:01:22 -06:00
Behdad Esfahbod 8862ff55c2 [gpu] Rename hb_gpu_draw_glyph parameter codepoint -> glyph
All sibling APIs (hb_raster_draw_glyph, hb_vector_{draw,paint}_glyph,
hb_raster_paint_glyph) name the glyph ID parameter "glyph".  The gpu
variant was the odd one out calling it "codepoint".  The type is
hb_codepoint_t in either case — only the local parameter name
changes; no ABI impact.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 02:01:21 -06:00
Behdad Esfahbod 3e411b58d6 [api] Return hb_bool_t from hb_raster_draw_glyph and hb_gpu_draw_glyph
Both were declared void, diverging from their sibling APIs
(hb_vector_{draw,paint}_glyph, hb_raster_paint_glyph) which all
return hb_bool_t, and from the font-level hb_font_draw_glyph_or_fail()
pattern.

Switch both to return hb_bool_t and route the internal call
through hb_font_draw_glyph_or_fail() instead of hb_font_draw_glyph().
Returns false when the font has no outlines for the given glyph;
true otherwise.

Libraries are new/experimental; the ABI break is acceptable.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 01:59:18 -06:00
Behdad Esfahbod 8cd50a7b77 [gpu] Add hb_gpu_draw_get_scale companion getter
hb_gpu_draw_set_scale() existed without a paired getter; all other
draw/paint contexts have get/set pairs.  Fill the gap for symmetry.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 01:58:06 -06:00
Behdad Esfahbod 6de5a0eb20 [api] const-correctness sweep for read-only getters
The _get_{buffer,format,extents,transform,scale_factor} getters
across the raster, vector, and gpu subsystems all took non-const
T* despite not mutating the context.  Unlike the core types
(hb_blob_*, hb_buffer_*, etc.) which use const, the newer
subsystems had drifted from that convention.

Add const qualifiers to:
  hb_raster_image_get_{buffer,format,extents}
  hb_raster_draw_get_{transform,scale_factor,extents}
  hb_raster_paint_get_{transform,scale_factor,extents}
  hb_vector_draw_get_{transform,scale_factor,extents}
  hb_vector_paint_get_{transform,scale_factor,extents}

Source-compatible — existing callers passing non-const T* still
bind to the stricter signature; no call-site changes needed.

All 240 tests pass.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 01:56:58 -06:00
Behdad Esfahbod 9d52c16abb [fuzzing] hb-vector-fuzzer: also exercise PDF output format
Previously only HB_VECTOR_FORMAT_SVG was fuzzed.  Factor the
create/paint/render body into a helper and call it twice per
input — once for SVG, once for PDF — so the PDF-specific code
paths get the same coverage:

  - PDF content-stream encoder
  - Type 2/3 shading + stitching function builder
  - Type 6 Coons-patch sweep gradient encoder (hb_pdf_add_sweep_patch)
  - PNG IDAT passthrough
  - Indexed-PNG SMask builder (hb_pdf_build_indexed_smask, zlib inflate
    + PNG un-filter + palette-to-alpha mapping)

Input-fuzzed knobs (precision, flat-draw, flat-paint) are shared
between the two formats.

Smoke-tested on a handful of existing fuzzing/fonts corpus entries;
all pass clean.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 01:40:02 -06:00
Behdad Esfahbod 514820324a [vector] Drop unused includes from draw/paint .cc
Stops clangd whining and trims the build-log noise a bit:

hb-vector-paint.cc: drop hb-blob.hh, <string.h>.  Neither had
  direct uses — the file touches only the public hb_blob_* API
  (which comes via hb-blob.h transitively) and has no mem*/str*
  calls.

hb-vector-draw.cc: drop hb-blob.hh, hb-map.hh, <algorithm>.  Same
  reasoning.

All 240 tests still pass.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 01:37:04 -06:00
Behdad Esfahbod 56ed6e519c [paint] Share sweep-gradient tile walker across cairo/vector backends (#5913)
Move hb_color_lerp and the sweep-gradient tiling template (previously
hb_vector_sweep_gradient_tiles in hb-vector-svg-utils.hh) into
hb-paint.hh, renamed to hb_sweep_gradient_tiles.  They operate on
paint types (hb_color_stop_t, hb_paint_extend_t, hb_color_t), so
hb-paint.hh is the natural home; hb-vector-svg-utils.hh is
vector-specific but the algorithm isn't.

Convert the cairo backend's _hb_cairo_add_sweep_gradient_patches
— which re-implemented the same pad/repeat/reflect sector walk in
~200 lines — to call hb_sweep_gradient_tiles with a lambda that
converts hb_color_t -> hb_cairo_color_t and emits a cairo patch.
The cairo-specific part shrinks to ~30 lines.

Net: -210 lines across the tree (-200 from hb-cairo-utils.cc,
-200 from hb-vector-svg-utils.hh, +200 added to hb-paint.hh).

All 240 tests pass.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 01:32:55 -06:00
Behdad Esfahbod ce705fa022 [blob] RAII refactor of hb_blob_create_from_file_or_fail (#5912)
Split the previously monolithic function — which had three sets of
goto-fail labels (POSIX mmap, Windows mmap, fread fallback) and
relied on intentional fall-through past the mmap section to the
fread code — into three focused helpers:

  _hb_blob_try_mmap (POSIX variant, under HAVE_MMAP)
  _hb_blob_try_mmap (Windows variant, under _WIN32 && !HB_NO_MMAP)
  _hb_blob_read_file (always available; fread fallback)

Each helper uses scope guards (hb_make_scope_guard / HB_SCOPE_GUARD)
to reclaim partial state on failure returns.  On success, the guards
are released where ownership passes to the returned blob.

The main hb_blob_create_from_file_or_fail simply dispatches:

  if (mmap variant available)
    try it; if it returns a blob, done
  fall back to fread

Behaviorally equivalent to the previous goto-based flow, but each
platform's cleanup is now local and the fall-through is explicit.

POSIX tested locally (240 tests pass); Windows path structurally
mirrors the original so should behave identically.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 01:16:42 -06:00
Behdad Esfahbod 8e3a166fd1 Improve hb-cplusplus usability with subsystems (#5911)
* [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>

* [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>

* [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:49:19 -06:00
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