Commit Graph
583 Commits
Author SHA1 Message Date
Behdad EsfahbodandClaude Opus 4.6 591748f1e1 [draw][paint] Make get_funcs instance-aware; add get_format
The six public draw / paint funcs getters across raster,
vector, and gpu used to be singletons:

  hb_raster_draw_get_funcs (void)
  hb_raster_paint_get_funcs (void)
  hb_vector_draw_get_funcs (void)
  hb_vector_paint_get_funcs (void)
  hb_gpu_draw_get_funcs (void)
  hb_gpu_paint_get_funcs (void)

That works fine for raster and gpu, where there's a single
backend per type, but breaks for the vector backend where
SVG and PDF have separate funcs sets — callers using the
public getter always got SVG funcs and silently produced
SVG markup inside PDF output streams when invoking the new
arbitrary-path clip API on a PDF context.

Make all six take a const-pointer to the relevant context
instance.  vector_paint dispatches on paint->format; the
other five just use the instance for symmetry today (room
for future format-style dispatch later).

Also expose hb_vector_draw_get_format / hb_vector_paint_
get_format public getters so callers (or third parties)
can ask a vector context for its format without poking at
internals.

Also: hb_vector_paint_push_clip_path_end now wraps the
emitted SVG clipPath's path in transform="scale(1,-1)" so
free-form arbitrary clips at base body level land in the
same coord system the per-glyph <use scale(_,-sy)>
wrappers establish.  Without this, free-form clip-path
arbitrary outlines emitted between paint_glyph calls came
out mirrored across the X axis.

Updates internal callers (hb_vector_paint_glyph,
hb_pdf_emit_glyph_path, hb_raster_paint_push_clip_path_
start, hb_gpu_paint_push_clip_path_start, the GPU pen
adapter), util sites (raster-output.hh, vector-output.hh,
gpu/demo-font.cc), API tests (test-raster.cc, test-gpu.cc),
and the docs section index.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:21:49 -06:00
Behdad EsfahbodandClaude Opus 4.6 98470a3e02 [draw] Rename hb_draw_rect to hb_draw_rectangle
API rename for the not-yet-released stroked/filled
rectangle helper added to hb-draw — full names
(hb_draw_line, hb_draw_circle, hb_draw_rectangle) read
better than mixed full/abbreviated.

Updates the public header, impl, the gpu doc reference,
the GPU API test, the GPU demo's extents overlay, the
extents-overlay paint helper, and the docs section
listing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad Esfahbod 599c99b589 [paint] Add arbitrary-path clip API
Add push_clip_path_start / push_clip_path_end to the
hb_paint_funcs_t vtable, for callers that want to clip paint
output to an arbitrary shape (not just a glyph or rectangle).

  hb_draw_funcs_t *df = hb_paint_push_clip_path_start (pf, pd, &dd);
  hb_draw_move_to (df, dd, NULL, ...);
  hb_draw_line_to (df, dd, NULL, ...);
  ...
  hb_draw_close_path (df, dd, NULL);
  hb_paint_push_clip_path_end (pf, pd);
  /* paint ops here are clipped to the emitted path */
  hb_paint_pop_clip (pf, pd);

The backend hands back a draw_funcs + draw_data pair (transfer
none) that accumulates the clip path; end() signals the
caller is done drawing clip geometry and the accumulated
path becomes an active clip.  pop_clip closes the scope,
symmetric with push_clip_glyph / push_clip_rectangle.

Only public API and the nil vtable stubs land here.  Backend
implementations (hb-vector, hb-raster, hb-gpu) follow in
separate commits.

Partial: https://github.com/harfbuzz/harfbuzz/issues/5930

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad Esfahbod 390ec06fa7 Merge pull request #5931 from harfbuzz/paint_or_fails
[vector/raster/gpu] Add *_glyph_or_fail() variants across all three
2026-04-16 16:13:05 -06:00
Behdad Esfahbod 64d2c7311b [paint] Promote reduce_anchors / normalize_color_line / sweep_tiles to public (#5932)
Every COLRv1 renderer ends up rewriting these three helpers;
they now live on hb-paint.h so Skia, FreeType-SVG, and other
downstream paint-API implementers can consume a single
canonical implementation.

  * hb_paint_reduce_linear_anchors() -- 3-anchor (P0, P1, P2)
    to 2-point axis projection.
  * hb_paint_normalize_color_line() -- sort + rescale stops
    to [0, 1]; returns (min, max) so callers can shift
    gradient geometry to match.
  * hb_paint_sweep_gradient_tiles() + matching
    hb_paint_sweep_gradient_tile_func_t callback typedef --
    iterates the full 0..2π sweep produced by a color-stop
    list, invoking the callback once per (start, end)
    angular segment.  Handles PAD / REPEAT / REFLECT.

Implementation moves from src/hb-paint.hh (private, static
inline) to src/hb-paint.cc (public, HB_EXTERN).  The sweep
tiler loses its C++ template/lambda flavor and grows a
user_data parameter alongside the function-pointer callback;
the three in-tree callers (cairo, vector-paint, vector-paint-pdf)
now use standalone trampoline functions + context structs
instead of captured lambdas.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/5928

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 14:56:15 -06:00
Behdad Esfahbod 98f3a42ee2 [vector/raster/gpu] Add *_glyph_or_fail() variants across all three
Consolidate the {vector,raster,gpu}_{draw,paint}_glyph APIs
to match the hb_font_{draw,paint}_glyph / _or_fail pattern:

  * Each existing *_glyph() public function now returns void.
    For the draw variants this is purely a return-value drop.
    For the paint variants the void entry additionally gains a
    synthesize fallback for non-color glyphs (calls
    hb_font_paint_glyph instead of _or_fail) so a mono glyph
    still produces output via a foreground-colored outline.

  * New *_glyph_or_fail() variants return hb_bool_t, reporting
    exactly what hb_font_{draw,paint}_glyph_or_fail() would.
    Callers that care about distinguishing color paint from
    synthesized outline now have a clean boolean signal.

Refactors the internal impls behind a shared static helper
parameterised by a `fallible` flag; the two public entries
delegate, passing true (for _or_fail) or false (for the void
alias).

For GPU specifically, paint_glyph_or_fail no longer folds the
encoder's unsupported flag into its return -- that state was
always better reported from hb_gpu_paint_encode() (which
returns NULL), and conflating the two prevented callers from
telling "font has no paint data" from "encoder hit a limit".

While in there, remove a dead branch at the end of
hb_vector_paint_glyph's SVG case (both inner blocks had
already returned; the tail was unreachable).

Updates docs/harfbuzz-sections.txt with the six new symbols
and the NEWS note with the Changed API callouts.  Updates
in-tree callers (hb-vector-svg-all, hb-raster-all, test-gpu,
util/vector-output.hh) to the _or_fail variants where they
previously read the return value.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/5926

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 00:36:37 -06:00
Behdad Esfahbod d8980e94e0 [draw] Add line/rect/circle drawing helpers (#5925)
* [gpu] Add hb_gpu_draw_line / _rect / _circle shape helpers

The GPU draw encoder already consumes arbitrary curves via the
hb_draw_funcs_t machinery -- that's how glyph outlines feed in.
Expose three convenience helpers so callers can emit common
shapes (tapered line, rectangle, circle) without having to
hand-roll the curve math:

    hb_gpu_draw_line   (draw, x0,y0,w0, x1,y1,w1);
    hb_gpu_draw_rect   (draw, x,y,w,h, stroke_width);
    hb_gpu_draw_circle (draw, cx,cy,r, stroke_width);

stroke_width = NaN means "filled".  A finite positive value
produces a stroked outline by emitting an outer contour CCW
and an inner contour CW so the fill rule carves a hole.

For shapes beyond these three helpers, callers can feed any
outline through hb_draw_move_to / _line_to / _quadratic_to /
_cubic_to / _close_path with the funcs from
hb_gpu_draw_get_funcs() and the hb_gpu_draw_t as data -- the
helpers are thin wrappers over that path.

Useful for game UI: health bars, progress rings, custom
line-art decorations, rendered through the same slug shader
as text.

Assisted-by: Claude <noreply@anthropic.com>

* [util/gpu] Add --show-extents flag

Exercises hb_gpu_draw_rect: when the flag is set, each glyph
blob encodes its ink-extent frame as an extra stroked
rectangle alongside the glyph outline, so the frame is cached
with the glyph and renders with no extra draw call.

The frame is padded outward by stroke_width / 2 so the stroke
sits entirely outside the glyph ink (otherwise the inner half
would knock out against the glyph shape, since both fill in
the same blob).

Cmdline-only for now -- a runtime 'e' toggle would require a
buffer re-shape hook that native hb-gpu doesn't yet expose.

Assisted-by: Claude <noreply@anthropic.com>

* [util/gpu] Cmdline toggles mirroring interactive keybindings

Add --dark / --no-vsync / --fullscreen / --no-stem-darken /
--debug so scripts and CI can start hb-gpu in any of the
states previously reachable only by pressing a key
interactively.  Applied via the same keystroke path by
synthesizing the corresponding key characters through
demo_view_type() at startup -- single source of truth for
each toggle.

Assisted-by: Claude <noreply@anthropic.com>

* [draw] Promote shape helpers from hb-gpu-draw to hb-draw

Three shape-emitting helpers (line, rect, circle) operate on
any hb_draw_funcs_t, not specifically the GPU backend.  Move
them out of the GPU-only API surface into the core hb-draw
API so any pen (raster, vector, gpu, user-supplied) gets
them.

API rename / move:

  hb_gpu_draw_line   -> hb_draw_line   (in src/hb-draw.h)
  hb_gpu_draw_rect   -> hb_draw_rect
  hb_gpu_draw_circle -> hb_draw_circle

Signatures gain a (dfuncs, draw_data, st) prefix to match the
existing hb_draw_move_to / line_to / cubic_to / close_path
shape -- the helpers are thin wrappers over those.

Callers in test/api/test-gpu.cc and util/gpu/demo-font.cc
updated to call hb_draw_* with hb_gpu_draw_get_funcs() and a
local hb_draw_state_t.

Updated harfbuzz-sections.txt with the new entries; removed
hb_gpu_draw_line / _rect / _circle from hb-gpu.h.

Assisted-by: Claude <noreply@anthropic.com>

* [draw] hb_draw_line: NaN second width defaults to first

Common case is a uniform-width line.  Letting @w1 default to
@w0 when NaN is passed makes the call shorter:

  hb_draw_line (..., x0, y0, 4, x1, y1, NAN);  /* uniform 4 */

Mirrors the NaN-as-sentinel convention used in hb_draw_rect /
hb_draw_circle for the stroke_width parameter.

Assisted-by: Claude <noreply@anthropic.com>

* [draw] hb_draw_line: add cap parameter (butt / square)

Add hb_draw_line_cap_t enum with HB_DRAW_LINE_CAP_BUTT (the
existing default behavior) and HB_DRAW_LINE_CAP_SQUARE, which
extends each endpoint along the line direction by half its
local stroke width.

Square caps let four hb_draw_line() calls form a closed
rectangle without gaps at the corners -- a meaningfully
cheaper alternative to hb_draw_rect() for thin outlined
rectangles, since each line's bbox is just stroke_width tall
instead of covering the full rectangle interior.

Round caps not implemented yet; can be added as a third enum
value when a use case shows up.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-15 21:49:45 -06:00
Behdad Esfahbod addaafd255 [vector] Rename svg_{set,get}_prefix to {set,get}_svg_prefix
Verb-then-thing matches the rest of the hb-vector setter/getter
naming (set_precision, set_palette, etc.).  Update the renamed
internal references and the NEWS / harfbuzz-sections.txt entries
to match.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 15:07:05 -06:00
Behdad EsfahbodandClaude Opus 4.6 ca75fd5ff9 [vector] Drop hb_vector_{draw,paint}_{set,get}_flat (#5927)
Flat mode disabled glyph reuse / caching to produce inline-
everything SVG output.  Its main use case was making
hb-vector SVGs safe to concatenate side-by-side in a single
document, but the recently-added svg_set_prefix API solves
that without giving up the cache.  No remaining callers in
tree (util/vector-output.hh's --flat option goes too).

Removes:
  - hb_vector_draw_set_flat / get_flat
  - hb_vector_paint_set_flat / get_flat
  - the `flat` field on both contexts
  - all `if (flat)` / `bool can_cache = !flat` branches
  - the --flat option in util/vector-output.hh
  - the four "flat*" expected files in test/vector/basic
  - the flat_draw / flat_paint params in the vector fuzzer
  - sections-list entries

meson test --no-rebuild green (241/241).

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 15:03:43 -06:00
Behdad EsfahbodandClaude Opus 4.6 ec63b7d921 [docs] Surface API-reference links in each integration section
The integration chapter explained how to use hb-glib /
hb-ft / hb-cairo / hb-uniscribe / hb-coretext / hb-icu but
never linked to the actual symbol pages.  Readers had to
guess the docbook page name to find the function reference.

Add a "API reference: <link>" line at the top of each of
the five C-binding integration sections (Python intentionally
omitted -- uharfbuzz lives outside this manual).

doc-check is green.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 14:40:41 -06:00
Behdad EsfahbodandClaude Opus 4.6 45d2856376 [docs] Link to harfbuzz-world.cc from the install manual
Add a "Single-file build with harfbuzz-world.cc" section
right after the configuration knob list.  Names the
amalgamation file, references the HB_TINY / HB_HAS_*
machinery the section above just covered, and points at
the harfbuzz-world.cc playground + source as a worked
example.

doc-check is green.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 13:46:40 -06:00
Behdad EsfahbodandClaude Opus 4.6 c3b0c4e282 [vector] Add hb_vector_{draw,paint}_svg_{set,get}_prefix
New public API for namespacing SVG output: callers that embed
multiple hb-vector-produced SVGs into the same document can
set a distinct id prefix per context, so hb-vector's short
internal IDs (p<N>, c<N>, clip-g<N>, gr<N>, cg<N>) don't
collide across snippets.

Example collision the new API prevents: page embeds two
hb-vector SVGs produced by different contexts.  Both use
id="clip-g10"; the browser's url(#clip-g10) resolves to
whichever element appears first, so paint layers in the
second SVG get clipped against the first SVG's glyph outline
-- visible as giant unclipped color rects bleeding across
the wrong glyph shape.

With the new API the second caller passes e.g. "b-" as its
prefix; the clash disappears.  Empty/NULL prefix preserves
the existing output byte-for-byte.

Affects every id / url(#...) / href="#..." emission in SVG
output:
  - hb-vector-draw: <path id="p..."> + <use href="#p...">
  - hb-vector-paint: <path>, <clipPath>, <linearGradient>,
    <radialGradient>, <g id="cg..."> color-glyph cache, and
    every corresponding url(#...) / href="#..." ref.
PDF output is unaffected (no ids).

Docs/harfbuzz-sections.txt updated; check-symbols passes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 11:48:54 -06:00
Behdad Esfahbod fd2a6968ab [draw] hb_draw_line: add cap parameter (butt / square)
Add hb_draw_line_cap_t enum with HB_DRAW_LINE_CAP_BUTT (the
existing default behavior) and HB_DRAW_LINE_CAP_SQUARE, which
extends each endpoint along the line direction by half its
local stroke width.

Square caps let four hb_draw_line() calls form a closed
rectangle without gaps at the corners -- a meaningfully
cheaper alternative to hb_draw_rect() for thin outlined
rectangles, since each line's bbox is just stroke_width tall
instead of covering the full rectangle interior.

Round caps not implemented yet; can be added as a third enum
value when a use case shows up.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-15 02:35:10 -06:00
Behdad Esfahbod e731c38975 [draw] Promote shape helpers from hb-gpu-draw to hb-draw
Three shape-emitting helpers (line, rect, circle) operate on
any hb_draw_funcs_t, not specifically the GPU backend.  Move
them out of the GPU-only API surface into the core hb-draw
API so any pen (raster, vector, gpu, user-supplied) gets
them.

API rename / move:

  hb_gpu_draw_line   -> hb_draw_line   (in src/hb-draw.h)
  hb_gpu_draw_rect   -> hb_draw_rect
  hb_gpu_draw_circle -> hb_draw_circle

Signatures gain a (dfuncs, draw_data, st) prefix to match the
existing hb_draw_move_to / line_to / cubic_to / close_path
shape -- the helpers are thin wrappers over those.

Callers in test/api/test-gpu.cc and util/gpu/demo-font.cc
updated to call hb_draw_* with hb_gpu_draw_get_funcs() and a
local hb_draw_state_t.

Updated harfbuzz-sections.txt with the new entries; removed
hb_gpu_draw_line / _rect / _circle from hb-gpu.h.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-15 02:27:43 -06:00
Behdad Esfahbod f6cd414c9f [gpu] Add hb_gpu_paint_set_scale / _get_scale
Mirror the draw API.  hb_gpu_paint_t already had x_scale / y_scale
fields and hb_gpu_paint_glyph() set them directly, but no public
setter / getter -- callers that want to use the paint funcs
without going through paint_glyph had no way to wire the scale.

Add the public setters / getters and route paint_glyph through
them, matching hb_gpu_draw_glyph's pattern.  Document on both
draw and paint that the convenience wrappers call _set_scale.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 19:08:03 -06:00
Behdad Esfahbod 5779d9315d [docs] Fix build 2026-04-14 15:33:02 -06:00
Behdad Esfahbod e66500fd8e [gpu] hb_gpu_paint: bake resolved color into blob, drop palette binding
Add a raster-style configuration surface to hb_gpu_paint_t:

  hb_gpu_paint_set_foreground / hb_gpu_paint_get_foreground
  hb_gpu_paint_set_palette    / hb_gpu_paint_get_palette
  hb_gpu_paint_clear_custom_palette_colors
  hb_gpu_paint_set_custom_palette_color

hb_gpu_paint_glyph now passes paint->palette and paint->foreground
through to hb_font_paint_glyph, and the custom-palette-color
callback consults the user's overrides map (same pattern as
hb_raster_paint_t) before letting harfbuzz fall back to the font's
own palette.

With that in place, the color() callback can bake the already-
resolved RGBA into the encoded op directly, quantized as signed
Q15 in the existing second texel, instead of recording a palette
index and trusting the shader to look it up.  The is_foreground
flag stays in the op so a runtime foreground-color change (e.g.
dark-mode toggle) still works without re-encoding.

Shader side: drop the hb_gpu_palette uniform/storage binding and
its HB_GPU_PALETTE_SIZE knob from all four paint-fragment shaders
(GLSL / MSL / WGSL / HLSL); read the per-layer color straight out
of the blob texel.  This removes a per-backend binding slot and
the 256-entry uniform-array size ceiling that blocked fonts like
Noto-COLRv1 (~6200 entries).

Trade-off: changing the palette selection or overrides invalidates
previously encoded blobs and requires re-encoding.  In practice
palette switches are rare, and the rendering hot path gets
simpler.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 18:44:58 -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 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 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
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 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 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 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 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 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
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
Khaled Hosny cfb70b0b91 14.1.0 2026-04-04 20:31:18 +02:00
Behdad Esfahbod 33baa306b2 [gpu] Fix docs for hb_gpu_draw_set_scale
Use XSince: REPLACEME and add to harfbuzz-sections.txt.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-02 01:19:42 -06:00
Khaled Hosny da69b6585c 14.0.0 2026-04-01 14:54:05 +02:00
Behdad Esfahbod 90e2f5f8b9 [docs] Update vector and subset library logos
New artwork from hb-libs2.png.

Assisted-by: Claude <noreply@anthropic.com>
2026-03-31 19:16:46 -06:00
Behdad Esfahbod 355bd4b011 Tweak logos 2026-03-31 11:31:42 -06:00
Behdad EsfahbodandClaude Opus 4.6 be79d54265 [docs] Point to GitHub README for overview, clarify this is API reference
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 00:39:15 -06:00
Behdad EsfahbodandClaude Opus 4.6 c68696c4fa [docs] Update docs opening paragraph
Mention subsetting, rasterization, GPU, and platform integrations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 00:34:24 -06:00
Behdad EsfahbodandClaude Opus 4.6 30ed85024d [docs] Add library logos to docs front page
Show subset, raster, vector, GPU logos inline at 64px
next to the main HarfBuzz logo.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 00:31:59 -06:00
Behdad EsfahbodandClaude Opus 4.6 2a31d1c745 [docs] Add per-library logos
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 00:22:06 -06:00
Behdad Esfahbod 5955ab5198 [docs] Add favicon for generated docs
The generated gtk-doc site only shipped the existing logo assets, so
harfbuzz.github.io had no root favicon for browsers to discover.

Add a small 64x64 favicon.ico derived from the existing docs logo
and install it as a gtk-doc HTML asset so the Pages deployment
copies it to the site root.

Testing:
- meson test -C build

Assisted-by: OpenAI Codex
2026-03-30 16:58:23 -06:00
Behdad EsfahbodandClaude Opus 4.6 99c17acbcd [gpu] Add HB_HAS_GPU to harfbuzz-sections.txt
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 03:06:31 -06:00
Behdad EsfahbodandClaude Opus 4.6 0582846c08 [gpu] Simplify shader API: return single string per language
Change hb_gpu_shader_{fragment,vertex}_sources() (array + count)
to hb_gpu_shader_{fragment,vertex}_source() returning a single
const char *.  Each language variant is one complete string.

Simplifies the demo shader compilation and documentation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 17:10:04 -06:00
Behdad EsfahbodandClaude Opus 4.6 d9a81a9cc5 [gpu] Add hb-gpu to docs sections and docs index
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:40:13 -06:00
Khaled Hosny 5ad3909af4 13.2.0 2026-03-19 00:45:24 +02:00
Khaled Hosny 257769a9d2 [ot-shape] Add hb_ot_shape_get_buffer_format_serial() (#5857) 2026-03-18 10:24:52 -06:00
Khaled Hosny 8168bf5fe0 [docs] Remove note about old HarfBuzz
Old HarfBuzz is long long dead that this note is likely to just confuse
people now.
2026-03-14 10:51:47 +02:00
Khaled Hosny 8fbf89c638 [docs] Re-order API sections a bit
Keep libharfbuzz APIs together, except for the integration APIs which
now comes last.
2026-03-13 15:28:29 +02:00
Behdad Esfahbod 3786b83fa6 [amalgamation] Add HB_HAS_SUBSET and share SVG helpers (#5835)
Add HB_HAS_SUBSET to hb-features.h and wire it through the same
HAVE_* feature plumbing used by the other HB_HAS_* macros.

Refactor the raster/vector SVG helper code so the duplicated
private helpers live in shared internal headers, avoiding
duplicate definitions when sources are combined in a single
translation unit.

Testing: meson compile -C build

Assisted-by: OpenAI Codex
2026-03-12 08:32:37 -06:00
Behdad Esfahbod 4da15dadff [meson] Add raster/vector feature macros
Raster and vector libraries were configurable, but hb-features.h.in
did not expose matching HB_HAS_* macros.

Set HAVE_RASTER and HAVE_VECTOR during configuration, include both
features in the generated hb-features.h list, and add them to the
gtk-doc section index.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-03-12 02:53:11 -03:00
Khaled Hosny 68d19d6964 13.1.0 2026-03-11 04:01:41 +02:00
Behdad Esfahbod dfc64f02c0 raster: add PNG serialization API for images 2026-03-09 23:37:36 +02:00
Khaled Hosny f5190a73aa [usermanual] Document hb-info, hb-raster, and hb-vector 2026-03-08 00:03:57 +02:00