Commit Graph
21038 Commits
Author SHA1 Message Date
Behdad Esfahbod d5f07d72d0 [gpu] Port paint fragment shader to WGSL; wire WebGPU demo
WGSL transcription of the paint interpreter.  Takes the atlas and
palette as explicit storage-buffer pointer parameters (matching
the WGSL draw helper's calling convention):

  fn hb_gpu_paint (renderCoord: vec2f, glyphLoc: u32,
		   foreground: vec4f,
		   hb_gpu_atlas: ptr<storage, array<vec4<i32>>, read>,
		   hb_gpu_palette: ptr<storage, array<vec4f>, read>) -> vec4f

hb_gpu_paint_shader_source() now returns real content for
HB_GPU_SHADER_LANG_WGSL fragment; HLSL still stubs to "".

util/gpu/web/hb-gpu-web-webgpu.cc:
  - Concats the paint source alongside the draw source into the
    WGSL shader module.
  - Declares @group(0) @binding(2) for hb_gpu_palette.
  - Allocates a 256 * vec4f storage buffer (zero-filled for now;
    real palette upload is TODO), binds it at entry index 2.
  - Fragment main switches from hb_gpu_draw to hb_gpu_paint.

util/gpu/web/gl-stub.h: adds glUniform4fv stub (demo-font.cc now
calls it for the GL palette path) and makes
glGetUniformLocation return -1 so the WebGPU build's
demo_font_upload_palette short-circuits.

Wasm sizes:
  WebGL   index.wasm  : 443628  181597 gz
  WebGPU  webgpu.wasm : 461110  188045 gz

Non-color text should render through WebGPU.  COLRv0 color glyphs
come up transparent until the cross-backend palette upload lands.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 15:27:41 -06:00
Behdad Esfahbod 5e2b77d2ea [gpu] Port paint fragment shader to MSL; wire Metal demo
MSL transcription of the GLSL paint fragment interpreter.  Same
per-pixel op-stream walk and LAYER_SOLID SRC_OVER composite; the
only surface difference is that MSL's hb_gpu_fetch /
hb_gpu_paint take the atlas and palette as explicit buffer
pointer parameters (matching MSL's lack of globally-scoped
device-address-space globals).

  float4 hb_gpu_paint (float2 renderCoord, uint glyphLoc,
		       float4 foreground,
		       device const short4* hb_gpu_atlas,
		       constant float4* hb_gpu_palette);

hb_gpu_paint_shader_source() now returns a real string for
HB_GPU_SHADER_LANG_MSL fragment; vertex and WGSL/HLSL still stub
to "".

util/gpu/demo-metal.mm: concatenates the paint source alongside
the draw source into the Metal library, fragment_main switches
from hb_gpu_draw to hb_gpu_paint, and a 256-element palette
MTLBuffer is created + bound at fragment buffer index 2.  The
palette buffer is zero-filled for now; real palette upload from
the font's active palette is a follow-up (the GL path in
demo-font.cc uses glUniform4fv, which is GL-specific; a cleaner
cross-backend upload will come with the general palette plumbing).

Non-color text (u_foreground path) should render correctly on
Metal.  COLRv0 color glyphs will render transparent until the
palette upload lands -- ready for Mac smoke-testing.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 15:14:36 -06:00
Behdad Esfahbod 34a9f22f25 [util/gpu] Extract demo shaders into .glsl files
demo_vertex_glsl and demo_fragment_glsl were inline R"glsl(...)"
string literals in util/gpu/demo-shader.cc.  Pull them into
dedicated util/gpu/demo-{vertex,fragment}.glsl source files with
their own copyright headers, and wire the existing
gen-gpu-shader-artifacts.py generator to stringize them into
demo-*-glsl.hh at build time.

Also simplifies gen-gpu-shader-artifacts.py: the decl_map had
grown to cover every shader and its entries were all trivial
filename-to-symbol derivations.  Replace the map with direct
derivation (hyphens -> underscores, strip .hh), so adding more
shaders anywhere -- library or demo -- needs no generator edit.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 15:10:09 -06:00
Behdad Esfahbod f3fcd46ba9 [gpu] First working COLRv0 GPU render
Two paint-encoder bugs and two demo-plumbing bugs together
prevented end-to-end rendering.  With all four fixed, BungeeTint
and similar COLRv0 fonts now render through the GL demo in their
proper palette colors.

### Paint encoder

1. hb-gpu-paint-fragment.glsl: the LAYER_SOLID op's payload is a
   blob-relative texel offset, but the shader was passing it to
   hb_gpu_draw() as-is -- which treats its argument as an absolute
   atlas offset.  Add the glyph's `base` to the payload before the
   draw-coverage call so the sub-blob reference resolves inside
   the paint blob instead of elsewhere in the atlas.

2. hb-gpu-paint.cc push_clip_glyph callback: was resetting
   pending_palette_index to 0.  But harfbuzz's COLRv0 paint
   emitter calls custom_palette_color BEFORE push_clip_glyph for
   each layer, so the index set by custom_palette_color was being
   clobbered before the color callback consumed it -- every layer
   ended up tagged palette_index=0.  Leave pending_palette_index
   alone in push_clip_glyph.

### Demo plumbing

3. util/gpu/demo-glstate.cc: demo_glstate_create now glUseProgram's
   its program immediately.  The palette uniform upload reads
   GL_CURRENT_PROGRAM, and glyph upload happens from
   demo_buffer_current_line() -- which runs before
   demo_view_setup() would have bound the program.  Without this,
   glGetIntegerv returned 0 and the palette was never uploaded.

4. util/gpu/demo-font.cc: adds lazy demo_font_upload_palette() on
   first glyph request.  Also tries both "hb_gpu_palette" and
   "hb_gpu_palette[0]" for the uniform lookup since drivers
   disagree.

### Bonus

util/hb-gpu-encode-all.cc: reports paint-encoded and draw-fallback
counts / sizes / timings separately so you can tell where time
goes in mixed-content fonts.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 15:03:58 -06:00
Behdad Esfahbod 7c97464406 [gpu] encode-all: paint-first with draw fallback; skip empty clip glyphs
util/hb-gpu-encode-all.cc now exercises the paint encoder instead
of the draw encoder directly.  Every glyph is routed through
hb_gpu_paint_glyph + hb_gpu_paint_encode; on NULL result (v1
features not yet handled, or fully empty paint tree) it falls
back to hb_gpu_draw_glyph + hb_gpu_draw_encode.  Reports paint
encoded count separately from draw-fallback count.

hb_gpu_paint.cc: the color callback now checks the
hb_gpu_draw_glyph return value and skips the layer when the
clip-glyph has no outline, so fallback-synthesized LAYER_SOLIDs
for glyphs like U+0020 don't produce a 1-op blob that the shader
would sample as zero coverage anyway.

Sample run on BungeeTint-Regular.ttf (COLRv0, 2 layers/glyph):

  glyphs:   2126
  paint:    2126    (all routed through paint)
  empty:    0
  total:    8347.27 KiB
  avg:      3.93 KiB/glyph
  max:      10.84 KiB (gid 1005)
  paint:    13.10ms  (6.2us/glyph)
  encode:    0.27ms  (0.1us/glyph)
  wall:     13.53ms  (157185 glyphs/s)

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 14:41:44 -06:00
Behdad Esfahbod eb46e5349e [gpu] Wire GL demo to the paint pipeline end-to-end
* hb_gpu_paint_glyph() switches from hb_font_paint_glyph_or_fail
  to hb_font_paint_glyph so non-color glyphs also produce a blob
  (harfbuzz synthesizes push_clip_glyph + color(is_foreground) +
  pop_clip which our callbacks turn into a single LAYER_SOLID
  op).  Return value is now "no internal error" rather than
  "glyph had color paint".

* util/gpu/demo-font.cc: drops the draw-only upload path and
  routes every glyph through hb_gpu_paint_{clear,glyph,encode,
  recycle_blob}.  Uploads the active palette to the
  hb_gpu_palette uniform array in demo_font_create.

* util/gpu/demo-shader.cc: concatenates hb_gpu_paint_shader_source
  after the shared + draw sources, and the demo's fragment main
  now calls hb_gpu_paint(texcoord, glyphLoc, u_foreground)
  directly.  Stem-darkening / debug overlay paths preserved
  against the premultiplied alpha channel returned by paint.

MSL / WGSL / HLSL demo paths are unchanged for now -- the paint
shader is GLSL-only and those demos keep using the draw path.

wasm size impact (local Emscripten build):
  baseline                     412722   170342 gz
  +HB_NO_COLOR/HB_NO_PAINT     437752   179165 gz
  +demo paint wiring           443313   181502 gz
  delta (vs baseline)          +30591    +11160

All 241 tests pass.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 14:36:32 -06:00
Behdad Esfahbod ebfea127de [gpu] Add GLSL paint fragment shader (LAYER_SOLID interpreter)
Implements the paint-renderer fragment entry point
hb_gpu_paint(renderCoord, glyphLoc, foreground) -> vec4 as an
interpreter over the blob format documented in hb-gpu-paint.hh.

For this first slice only LAYER_SOLID ops are handled -- enough
to render COLRv0 color glyphs end to end once the demo is
rewired.  LAYER_GRADIENT and PUSH/POP_GROUP cause the interpreter
to stop; COLRv1 support lands in follow-up commits.

The shader:
* Reads the blob header for num_ops and ops_offset.
* Walks the op stream.  For each LAYER_SOLID it fetches the
  clip-glyph coverage via hb_gpu_draw() (provided by
  hb_gpu_draw_shader_source), looks up the color from
  hb_gpu_palette[] or the caller-supplied foreground parameter
  (per the is_foreground flag), and composites SRC_OVER.

hb_gpu_paint_shader_source() now returns the compiled source for
GLSL fragment; other languages and the vertex stage still return
"" until transcribed.

Wires meson.build and gen-gpu-shader-artifacts.py to generate the
.hh artifact.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 14:29:03 -06:00
Behdad Esfahbod 1a94ff1f7b [gpu] Implement hb_gpu_paint_t COLRv0 encoder
Wire the paint-callback pipeline for COLRv0 color glyphs.

Adds:

* push_clip_glyph / pop_clip / color / custom_palette_color
  callbacks.  Each COLRv0 layer's push_clip_glyph is captured,
  then the following color callback rasterizes the clip-glyph
  outline through a scratch hb_gpu_draw_t, appends the resulting
  Slug sub-blob, and emits a LAYER_SOLID op carrying the
  palette_index (preserved via custom_palette_color) plus the
  is_foreground flag.  pop_clip clears the pending state.
* hb_gpu_paint_get_funcs(): cached singleton hb_paint_funcs_t via
  the standard hb_paint_funcs_lazy_loader_t.
* hb_gpu_paint_glyph(): stashes the font scale and invokes
  hb_font_paint_glyph_or_fail() with our funcs and a sentinel
  foreground (the encoder never stores foreground -- the shader
  resolves it per quad from a caller-supplied attribute).
* hb_gpu_paint_encode(): concatenates the 3-texel header, the op
  stream, and the collected sub-blobs into one RGBA16I blob,
  patching each op's sub_blob-index into an absolute texel
  offset.  Returns NULL when no layers accumulated or an
  unsupported (v1) feature was seen.
* hb_gpu_paint_clear(): discards ops, sub-blobs, and pending
  state while preserving the font scale.

The gradient / group / transform callbacks are not wired yet, so
COLRv1 paint graphs silently fall through -- callers should
precheck with hb_ot_color_glyph_has_paint() and route v1 glyphs
elsewhere (or fall back to draw).

Enables HB_NO_COLOR and HB_NO_PAINT in the web demo config
override so the wasm link resolves the new paint pipeline
symbols.  Measured on a local Emscripten build:

  raw  wasm:  412722 -> 437752  (+25030 B, +6.1%)
  gzip wasm:  170342 -> 179165  ( +8823 B, +5.2%)

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 14:26:08 -06:00
Behdad Esfahbod 5f527aeea1 [gpu] Drop hb_paint_funcs_get_empty from hb_gpu_paint_glyph stub
The stub called hb_font_paint_glyph_or_fail() with the empty paint
funcs just to get a truthful has-paint return value.  That pulls in
hb_paint_funcs_get_empty from hb-paint.cc, which HB_LEAN strips out
of the wasm build, breaking the web demo link step.

Since the encoder is still a stub that accumulates nothing, there is
no reason to actually invoke the paint callback walk.  Stash the
font scale and return false directly.  When the real encoder lands
it will naturally pull in whichever paint symbols it needs.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 13:53:48 -06:00
Behdad Esfahbod a0a469bf15 [gpu] Revert demo paint-path wiring
The previous commit routed color-glyph upload to hb_gpu_paint_t and
fell back to hb_gpu_draw_t on NULL blob.  That is fine as long as
hb_gpu_paint_encode() is a stub returning NULL, but when the real
encoder lands the demo would start uploading paint-format blobs
into the atlas while the renderer still uses only the draw-stage
fragment shader -- producing garbage.

Keep the library-side paint stubs (they are legit scaffolding) but
back out the demo changes.  The demo will grow the paint path in
lock-step with the paint shader, not ahead of it.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 13:52:16 -06:00
Behdad Esfahbod 7b5fc7f0c4 [gpu] Add hb_gpu_paint_* glyph/encode/clear/reset/recycle stubs
Reserve the paint-encoder API shape and wire the demo to try the
paint path before falling back to draw.  The encoder itself is
still a stub so the fallback always fires today; when the encoder
lands, color glyphs will flip automatically with no demo changes.

New public API:

  hb_gpu_paint_glyph (paint, font, glyph)
    Stashes the font scale on @paint and calls
    hb_font_paint_glyph_or_fail() with hb_paint_funcs_get_empty()
    so non-color glyphs report false.  Returns the funcs call
    result.

  hb_gpu_paint_encode (paint, &extents)
    Stub, returns NULL.

  hb_gpu_paint_clear (paint)
  hb_gpu_paint_reset (paint)
  hb_gpu_paint_recycle_blob (paint, blob)
    Stubs that preserve the right semantics.  clear is a no-op
    (no accumulator state yet), reset additionally zeroes the
    stashed scale, recycle_blob hb_blob_destroys.

Adds x_scale / y_scale to hb_gpu_paint_t so glyph can stash them
for the encoder to consume later.

util/gpu/demo-font.cc:
  - Creates a paired hb_gpu_paint_t alongside hb_gpu_draw_t.
  - Per glyph: if the face has COLRv1 paint for the glyph, tries
    hb_gpu_paint_glyph + hb_gpu_paint_encode.  On NULL blob, falls
    through to the existing draw path.
  - Changes the per-iteration sync from _reset to _clear for both
    draw and paint: _reset zeroes the font-scale config that
    _glyph immediately re-populates, which wastes work and is
    semantically wrong.  _clear discards accumulator state while
    preserving user config.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 13:38:14 -06:00
Behdad Esfahbod 13231bc7fe [gpu] Document hb_gpu_paint_t encoded-blob design
Add a design-doc comment in hb-gpu-paint.hh pinning the model
before any encoder code lands:

* One blob per glyph, one quad per glyph.  The fragment shader
  walks a flat pre-order op stream and maintains a small (depth-4)
  group stack to composite.
* Op types: LAYER_SOLID, LAYER_GRADIENT, PUSH_GROUP, POP_GROUP.
* Clip-glyph outlines are embedded as Slug-format sub-payloads
  (same format hb_gpu_draw_encode produces).  v1 bakes the full
  paint transform into each outline; v2 may canonicalize and share
  translate-only variants.
* Gradient parameters embedded as RGBA16I texels: inverse transform
  in q15.16, type+extend, subtype params, color stops.
* Colors carry a (palette_index, flags, alpha_q15) triple rather
  than resolved RGBA.  Palette is a shader-side uniform array of
  256 vec4; swapping palettes never requires re-encoding.  The
  encoder preserves palette indices through harfbuzz's paint
  pipeline via a custom_palette_color_func that returns a sentinel
  hb_color_t with the index encoded, decoded again in the color /
  color-stop callbacks.
* Shader entry point:
    vec4 hb_gpu_paint (vec2 renderCoord, uint glyphLoc,
                       vec4 foreground);
  Foreground is an explicit parameter; the caller chooses whether
  to source it from a uniform or a per-quad flat varying (per-quad
  lets styled text runs render in one draw call).
* Out of scope for v1: RECT_CLIP ops (treated as hints, not
  enforced), paint images.

No code yet.  The skeleton hb_gpu_paint_t stays as a bare
hb_object_header_t; encoder state and public API additions come in
follow-up commits.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 13:31:06 -06:00
Behdad Esfahbod c643c5245c [gpu] Merge *-shaders.cc dispatchers into the subsystem .cc files
Each subsystem already had a dedicated source file for its C API;
having the shader-source getter live in a separate `*-shaders.cc`
was unnecessary.  Merge:

  hb-gpu-shaders.cc       -> hb-gpu.cc
  hb-gpu-draw-shaders.cc  -> hb-gpu-draw.cc
  hb-gpu-paint-shaders.cc -> hb-gpu-paint.cc

Each subsystem's .cc is now self-contained: the lifecycle, glyph
accumulation, and shader-source getter all live together.

The large stringized-shader .hh artifacts are included locally at
the bottom of each file, right above the function that uses them,
rather than with the primary includes at the top -- they are only
used by one function.

Updates meson.build, CMakeLists.txt, and harfbuzz-world.cc to
drop the removed files.  All 241 tests still pass.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 12:10:35 -06:00
Behdad Esfahbod 70310b9e65 [gpu] Add hb_gpu_paint_t infrastructure skeleton
Reserve the API shape for the upcoming GPU color-glyph paint
encoder.  The skeleton adds:

  hb_gpu_paint_t opaque type
  hb_gpu_paint_create_or_fail ()
  hb_gpu_paint_reference ()
  hb_gpu_paint_destroy ()
  hb_gpu_paint_set_user_data () / _get_user_data ()
  hb_gpu_paint_shader_source (stage, lang)

Only the lifecycle is functional.  hb_gpu_paint_shader_source()
returns an empty string for all supported (stage, lang) pairs
until the paint-renderer shaders land.

This commit wires up the files, public declarations, section
index, and build system (meson, CMake, harfbuzz-world.cc,
vtable).  Callers can now hold, reference, destroy, and attach
user data to a paint context.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 12:10:35 -06: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