Commit Graph
21174 Commits
Author SHA1 Message Date
Behdad EsfahbodandClaude Opus 4.6 f7ebd549ed [util/hb-view] --show-extents: foreground color, no per-color split
Drop the bespoke red pen dot + magenta extents rectangle in
favor of a single foreground-color overlay that matches the
look raster, vector, and gpu now produce after their port to
the shared helper: stroked rect around each glyph's ink box,
plus a filled dot at the pen origin.

Cairo's annotation pass stays native (post-glyph drawing
through cairo, not via hb_paint funcs); only the colors and
the dot rendering changed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:22:42 -06:00
Behdad EsfahbodandClaude Opus 4.6 c152eaceb3 [util] --show-extents: add a filled dot at the pen origin
Extend the shared overlay helper (and rename it from
util_emit_extents_rect_into_* to util_emit_extents_overlay_
into_*) to emit two pieces of geometry per glyph: the
existing stroked rect around the ink box, plus a filled
dot at the pen origin via hb_draw_circle.  Both go in the
foreground color through the same draw / paint flow.

The dot helps debug glyph positioning at a glance and gives
the previously-uncalled hb_draw_circle a real caller in the
suite.

Raster, vector, and gpu utils pick up the dot automatically
via the renamed helper.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:22:42 -06:00
Behdad EsfahbodandClaude Opus 4.6 88dc4c9926 NEWS: Document get_funcs signature change and draw helpers
* Add the six raster/vector/gpu draw+paint get_funcs
  signature change to "Changed API, general".
* List hb_vector_draw_get_format / hb_vector_paint_get_format
  under "New API, Vector library".
* Add a "New API, Draw" section for the new shape helpers
  (hb_draw_line, hb_draw_rectangle, hb_draw_circle) and the
  hb_draw_line_cap_t / HB_DRAW_LINE_CAP_* constants that
  came in earlier this dev cycle but weren't yet listed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:22:14 -06:00
Behdad EsfahbodandClaude Opus 4.6 48fdb0ec34 [cairo] Implement arbitrary-path clip in paint funcs
Wire push_clip_path_start / push_clip_path_end into the
cairo paint backend.  start() saves the cairo state, opens
a fresh path, and hands the caller hb_cairo_draw_get_funcs
with the cairo_t as draw data — same draw funcs that
push_clip_glyph already uses internally to walk a glyph
outline as a cairo path.  end() closes the path and calls
cairo_clip; pop_clip's cairo_restore tears down the saved
state as before.

Lets cairo paint consumers compose arbitrary-path clips
(say, an outline for a non-glyph shape) the same way
push_clip_glyph builds a glyph clip.

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 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 fe77507f14 [util/gpu] Port --show-extents to the shared paint helper
Use util_emit_extents_rect_into_{draw,paint} from
helper-extents-overlay.hh so the GPU demo's extents
overlay matches the raster and vector ports — same
coordinate, padding, and stroke convention; same
foreground-color fill via the arbitrary-path clip API in
paint mode.

Adds --show-extents support for the paint (color-glyph)
path, which previously only the draw path implemented.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:19:17 -06:00
Behdad EsfahbodandClaude Opus 4.6 cf5325f4f5 [util/vector] Port --show-extents to the paint API
Bake the per-glyph extents rectangle into the same draw or
paint context that rendered the glyph, via the shared
helper from helper-extents-overlay.hh.  Matches the raster
util's port: in paint mode, the rect goes through
push_clip_path_start/end + paint_color (foreground); in
draw mode, hb_draw_rectangle on hb_vector_draw_get_funcs
appends to the scratch which the next glyph's entry-flush
(or render) emits as its own <path>/fill.

Drops the standalone emit_extents_overlay function and
its FF0000-dot + FF00FF-stroke SVG markup — the new
overlay renders in the glyph's foreground color, same as
the raster port.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:19:17 -06:00
Behdad EsfahbodandClaude Opus 4.6 38f1760d7d [vector-draw] Flush pending free-form path on glyph entry
The previous render-side flush handled the trailing batch
of free-form draw ops, but each new hb_vector_draw_glyph
call wipes the scratch first thing — so any rect (etc.)
queued between two glyphs was silently dropped.

Add a flush at the top of hb_vector_draw_glyph that emits
the accumulated scratch as its own <path>/fill before
proceeding.  Lets callers interleave hb_draw_*() calls
between glyphs and have every batch land in the output.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad EsfahbodandClaude Opus 4.6 acfb6784c3 [vector-draw] Flush leftover scratch path on render
hb_vector_draw_glyph for SVG copies the glyph outline into
defs and emits a <use> in body, but didn't clear the
internal draw->path scratch on its way out — and the PDF
path wasn't clearing it after appending to body either.
The render functions then mutually-excluded body vs path
emission with an else-if, so any free-form draw ops a
caller did via hb_draw_*() on hb_vector_draw_get_funcs()
would either inherit the trailing glyph bytes (SVG) or be
silently dropped (PDF render only fired when body was
empty).

Two-line fix: clear draw->path at the end of each glyph
emission so subsequent draw-funcs calls start with an
empty scratch, and turn the render branches into two
sibling ifs so any leftover free-form path gets flushed
as its own <path d="..."/> (SVG) or path + "f\n" (PDF)
alongside the body content.

Unblocks --show-extents in hb-vector by letting the util
just call hb_draw_rectangle on the draw context after each
glyph.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -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 EsfahbodandClaude Opus 4.6 77817c597e [util/raster] Port --show-extents draw mode; factor shared math
Add util_emit_extents_rect_into_draw in helper-extents-
overlay.hh — takes a draw funcs pair + glyph extents + pen
position + stroke_width and emits the padded stroked rect
in one place.  util_emit_extents_rect_into_paint (renamed
from _paint for clarity) now wraps it in the
push_clip_path_start/_end + paint_color + pop_clip dance.

Both raster draw loops (finish_draw_solid accumulated into
one rdr, finish_draw_palette per-glyph) now bake the extents
ring into the draw context with util_emit_extents_rect_into_
draw, alongside the glyph outline in foreground color.
finish_paint's call site collapses from an inline
coord-normalize-and-pad block to a single helper call.

Uses copysignf on the padding so the "outward" shift tracks
the y_bearing/height sign instead of needing a caller-side
normalize; pairs with the hb_draw_rect fix for negative
w/h in the same branch.

Drop the now-unused collect_ink_extents_rects /
overlay_rects_bgra / overlay_rects_rgb / rect_i_t helpers
that implemented the old manual BGRA overlay pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad EsfahbodandClaude Opus 4.6 134066df57 [util/raster] Port --show-extents to the paint API (paint mode)
Replace the manual BGRA 1-pixel overlay with a per-glyph
hb_paint_push_clip_path_start/_end + hb_draw_rect + paint
foreground sequence, wrapped in the new shared helper
util_emit_extents_rect_paint in helper-extents-overlay.hh.
Each glyph now bakes its own extents ring into the glyph's
rendered mask via the raster-paint backend's arbitrary-
path clip, so compositing picks it up alongside the glyph
ink (same code path as the color layers).

Pads the nominal rect outward by stroke_width/2 so the
stroke's inner edge sits at the ink box — otherwise the
inner half would knock out against glyph ink under non-
zero-winding clipping.  Normalizes w/h to positive before
padding so the outward shift is unambiguous regardless of
y_bearing / height sign conventions.

Draw-mode loops (finish_draw_solid, finish_draw_palette)
still use the old collect+overlay path and will follow up.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad EsfahbodandClaude Opus 4.6 8f735c05cd [draw] Normalize w/h in hb_draw_rect
Negative w/h are documented as supported but the stroked
variant's math (outer grows by stroke_width, inner shrinks
by stroke_width) silently inverts — outer ends up smaller
than inner, the ring becomes a filled outer rect, and
arbitrary-path clip users (who feed raw font glyph extents
with y_bearing-style negative height) see the clip fill
everything instead of just the stroke ring.

Normalize w/h to non-negative at the top of hb_draw_rect
so the rest of the stroke math produces the expected
outer-contains-inner ring.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad EsfahbodandClaude Opus 4.6 f3c36ef3d6 [test] Add API tests for push_clip_path_start/_end
Folded into the existing test-paint binary.  Two tests,
both font-independent (registered ahead of the glyph-based
flavor setup so they run even on builds without the test
COLRv1 font):

* test_push_clip_path_nil_returns_null: an unset paint-funcs
  table returns NULL from push_clip_path_start and clears
  the out-param draw_data, and push_clip_path_end is safe
  to call on the nil stub.

* test_push_clip_path_round_trip: registered start/end fire
  in order, the returned draw-funcs + draw-data round-trip
  through the public entry points, and every hb_draw_*()
  call reaches the sink accumulator.  Asserts the count
  includes hb_draw_close_path's synthetic back-to-start
  line_to so the contract is documented by the test.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad EsfahbodandClaude Opus 4.6 9674752f61 [cmake] Rename hb-vector-svg-path to hb-vector-path
Follow-up to the meson rename so CMake builds pick up the
file too.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad EsfahbodandClaude Opus 4.6 2b732039d1 NEWS: Document arbitrary-path clip paint API
Add the push_clip_path_start / _end additions under a new
"Paint API" bullet and list the six new public symbols
(two entry points, two setters, two func_t typedefs) in
the "New API, Paint" block.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad EsfahbodandClaude Opus 4.6 0477004945 [gpu-paint] Implement arbitrary-path clip
Each GPU paint clip becomes a Slug sub-blob in c->sub_blobs
(curves + band index + extents) that the encoded shader
tests against independently — there's no glyph-id lookup at
shader time.  That means an arbitrary user-drawn path is
representable on GPU: hand the caller the same
hb_gpu_draw_get_funcs() the glyph-clip path already feeds
through hb_gpu_draw_glyph, and encode the result into a
sub-blob the same way.

push_clip_path_start preps scratch_draw (the existing
per-clip encoder scratch) with the paint's font scale and
captures cur_transform for the forthcoming sub-blob.
push_clip_path_end runs hb_gpu_draw_encode on the captured
geometry and commits the resulting sub-blob and its design-
unit extents to clip_stack.  pending_clip_t grows a
sub_blob_index field and four extent fields; emit_clip_sub_
blob short-circuits for path clips (sub_blob_index >= 0) by
accumulating the stored extents and returning the pre-baked
index, skipping re-encoding per layer.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad EsfahbodandClaude Opus 4.6 100c992dc5 [raster-paint] Implement arbitrary-path clip
Wire push_clip_path_start / push_clip_path_end into the
raster backend.  Factor the existing emitter-based clip
helper in two so both paths share the mask-render +
clip-intersect tail:

  * hb_raster_paint_finalize_path_clip does the render,
    alpha-buffer allocate, and intersect-with-old-clip
    work.
  * The emitter-based helper now preps clip_rdr with the
    current effective transform, calls emit() to populate
    edges, then calls the finalize helper.
  * push_clip_path_start preps clip_rdr exactly the same
    way and hands the caller the raster-draw funcs +
    clip_rdr as draw-data; the caller drives the path in.
    _end just runs the finalize pass.

Since clip_rdr is shared across all clip pushes, this
reuses the object's recycled mask-image and edge buffers
without extra allocations per clip.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad EsfahbodandClaude Opus 4.6 afb6a5411e [vector-paint-pdf] Implement arbitrary-path clip
Wire push_clip_path_start / push_clip_path_end through the
PDF backend using the shared hb_vector_path_sink_t.  start()
emits 'q' to save state and hands back a sink that streams
PDF path operators directly into the body buffer; end()
closes with 'W n' to install the accumulated path as the
clip.  The existing pop_clip closes the q/Q pair.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad EsfahbodandClaude Opus 4.6 834826289e [vector] Fold svg-path sink into a format-aware vector-path
Rename hb-vector-svg-path.{cc,hh} to hb-vector-path.{cc,hh}
and make the sink format-aware (SVG or PDF), so the PDF
backend can reuse it for arbitrary-path clipping without
spinning up its own path serializer.

hb_vector_svg_path_sink_t gains a hb_vector_format_t field
and becomes hb_vector_path_sink_t; the draw callbacks
switch on format and emit SVG path-data or PDF path
operators into the external buffer.  hb-vector-draw.cc and
hb-vector-paint.cc (push_clip_glyph + the recent arbitrary
clip-path start) are updated to the new name with
format=SVG.  No behavior change on the SVG side.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad EsfahbodandClaude Opus 4.6 e358e565e5 [vector-paint] Implement arbitrary-path clip
Wire push_clip_path_start / push_clip_path_end into the
vector-paint (SVG) backend.  start() clears the per-paint
scratch path and hands back the SVG path sink + its draw
funcs; end() emits a <clipPath><path d="..."/></clipPath>
into defs and opens a matching <g clip-path="url(...)"> on
the body.  The existing pop_clip closes that group.

IDs use the "cp" prefix to distinguish from "c" (rects) and
"clip-g" (glyph clips).  clip_path_counter is reset along
with the other body counters on paint reset.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad EsfahbodandClaude Opus 4.6 93777bcb19 [paint] Use language="plain" in clip-path usage block
HarfBuzz gtk-doc convention is |[<!-- language="plain" -->,
not "C".  Aligns with every other code block in src/.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad EsfahbodandClaude Opus 4.6 a0c670108e [paint] Add usage example to hb_paint_push_clip_path_start docs
Illustrate the expected call sequence: start → draw_* →
close_path → end → (painted ops) → pop_clip, so
implementers of the paint API don't have to reassemble the
contract from the individual function docs.

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 90595602d3 [font] Document paint_glyph_or_fail success/failure modes
Spell out when the function succeeds: COLRv0 paint layers,
COLRv1 paint graph, or a bitmap image rendered by the font's
callbacks.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:16:38 -06:00
Behdad Esfahbod 18825a19a1 Address PR #5931 review feedback
- Reset Since tags to XSince: REPLACEME for new non-or_fail
  glyph functions (gpu, raster, vector paint).
- Remove duplicate doc comment on static
  hb_vector_paint_glyph_impl helper.
- Fix hb_gpu_paint_glyph doc: remove internal LAYER_SOLID
  reference.
- Drop hb_ot_color_has_svg() from color-detection in all utils
  (cairo, raster, vector, hb-raster-all); HarfBuzz does not
  render SVG table natively, so checking it caused fallback to
  monochrome drawing of the actual outlines.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:16:38 -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 bc328d4d8c [vector] Fix sign of ty in EXPAND extents transform
The per-glyph EXPAND extents transform negated xy and yy to
convert from font Y-up to SVG/PDF Y-down, but kept ty
(the pen's Y translation) positive.  The actual SVG instance
transform negates both the scale and the translation:

  translate(tx/sf, -ty/sf) scale(1/sf, -1/sf)

So the rendered Y position of glyph-local point (x, y) is
(-y - ty) / sf, but the EXPAND was computing (-y + ty) / sf.
The wrong sign caused pen_y offsets (large in Nastaliq due to
vertical glyph stacking) to inflate the viewBox downward
instead of cancelling out.

Visible as excess whitespace below the descender in SVG output
for scripts like Nastaliq that use large y_offsets.

Fix: negate ty in the extents_transform, matching the SVG emit.
Applied to both hb-vector-draw and hb-vector-paint EXPAND paths.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 15:40:59 -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 5ce8f73bad [util/vector] Apply margin in pixel units
The other utils (hb-view, hb-raster) treat --margin as pixels, but
hb-vector was applying it directly to the upem-space extents.  For a
font with upem=1000 rendered at font-size=72, the default 16-pixel
margin came out as 16/1000*72 = ~1.15 pixels per side, much smaller
than expected.

Convert margin from pixels to upem before adding it to the extents,
matching the per-axis x_scale/y_scale used elsewhere in the file.

Now hb-vector and hb-raster produce matching surface dimensions for
the same input (e.g. NotoNastaliqUrdu "اردو" at 72px: 137x213 in both).

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 14:35:58 -06:00
Behdad EsfahbodandClaude Opus 4.6 e933f71b0d [cairo][util/hb-view] Honor --draw / --paint via cairo color mode
hb-cairo's render_color_glyph drops _or_fail in favor of
the synthesizing hb_font_paint_glyph, so the paint callback
handles every glyph (color or mono) through the paint
pipeline instead of returning NOT_IMPLEMENTED on non-color
glyphs and forcing cairo to fall through to the outline
path.

Hb-view's helper-cairo then picks paint vs draw the same
way the other utils do — --paint wins over --draw,
otherwise auto-detect via the font's color tables — and
expresses "draw" by setting CAIRO_COLOR_MODE_NO_COLOR on
the font options (which makes cairo skip render_color_glyph
entirely, falling through to render_glyph for the cheaper
outline path).  No new public API.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 14:07:38 -06:00
Behdad EsfahbodandClaude Opus 4.6 ffd4772e05 [util] Add --draw / --paint flags to raster, vector, gpu
Move the force_draw / force_paint flags from gpu-output.hh
into the shared view-options.hh so all rendering utils
expose --draw and --paint with the same semantics: --paint
wins over --draw, otherwise auto-detect via the font's
color tables.

raster and vector previously only ran the paint pipeline
when the font had a color table; they now also honor
--paint (renders mono fonts via paint synthesis) and
--draw (forces the outline path even on color fonts).

Vector's per-glyph try-paint-then-fall-back-to-draw is
replaced with a single mode decision up front.  Each
glyph then goes through hb_vector_{paint,draw}_glyph
(non-_or_fail), which handles the synthesis fallback
internally — color glyphs render in either mode (paint
synthesizes for non-color fonts; draw renders nothing for
color-only glyphs without an outline, which matches user
intent for --draw).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 13:56:32 -06:00
Behdad EsfahbodandClaude Opus 4.6 dba4dab3ef [vector-paint] Fold scale_factor into PDF per-glyph cm
Follow-up to 152aa0fd8c.  The SVG branch of
hb_vector_paint_glyph divides the instance transform by
x_scale_factor/y_scale_factor (via
hb_vector_svg_append_instance_transform) so input-space
glyph paths land in the pixel-space viewBox.  The PDF
branch emitted the raw paint matrix, which kept the CTM in
input space while the MediaBox lived in pixel space —
at any non-identity scale_factor, the glyph rendered
entirely outside the page.

Divide the matrix columns by sx/sy in the emitted cm so
PDF matches SVG.  Covers hb-vector's font-size != 20 case
and the website's scale_factor = 64 case, where emoji
rendered blank at 72 px.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 02:42:29 -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 152aa0fd8c [vector] Divide explicit set_extents by scale_factor
hb_vector_{paint,draw}_set_extents stored caller-supplied
extents as-is, while per-glyph extents accumulated via
hb_vector_set_glyph_extents_common were divided by
scale_factor on the way in.  When callers passed extents in
input-space (the natural unit alongside the glyph geometry
they're feeding) and a non-1 scale_factor, the resulting
viewBox didn't match what the glyphs drew.

Make set_extents divide by scale_factor too, matching the
accumulate path; callers can now pass input-space extents
uniformly.

Also:

* hb-vector-paint's global transform wrapper dropped the
  redundant /scale_factor division.  Each per-glyph
  <use transform="... scale(1/scale_factor, ...)"> already
  applies scale_factor; wrapping the body in another
  /scale_factor matrix double-scaled the output, shrinking
  color-glyph output to 1/scale_factor^2 of its intended
  size.  The wrapper now only fires when the user set a
  non-identity paint->transform, and emits that transform
  as-is.

* util/vector-output.hh simplification: now that set_extents
  handles the divide, drop the local pre-multiply of extents
  by upem_to_pixel -- pass the upem-space extents through.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 22:04:26 -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 d60ffa956f [util/vector] Emit SVG/PDF in pixel units, not upem
vector-output.hh fed upem-space coordinates to the draw/paint
context and then set scale_factor=1, so the resulting SVG's
viewBox / width / height were in upem (e.g. ~2500×1400 for a
48 px "Hello" in a 1000-upem font).  Browsers sized the
inline SVG at 1 upem-unit-per-CSS-pixel, rendering it ~20×
too large.

Fix: compute the upem→pixel ratio from x_scale / y_scale
(already available) and

  * scale the explicit extents by that ratio before calling
    set_extents (so viewBox and width/height come out in
    pixels), and
  * pass its inverse as set_scale_factor so upem-space input
    coordinates (pen position, glyph outline points) get
    divided to pixels internally.

No test expected-output changes -- the vector tests render
at FONT_SIZE_UPEM where upem_to_pixel = 1 and the patch is a
no-op.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 17:31:37 -06:00
Behdad Esfahbod f53d20c425 [gpu] Use centralized paint helpers; rename sweep tiler
Two cleanups:

* Drop hb-gpu-paint's local reduce_linear_anchors and
  normalize_stops, use the shared
  hb_paint_reduce_linear_anchors() and
  hb_paint_normalize_color_line() from hb-paint.hh.  All
  four backends (cairo, raster, vector, gpu) now share one
  implementation.

* Rename the sweep-gradient tiler from hb_sweep_gradient_tiles
  to hb_paint_sweep_gradient_tiles to match the namespace
  convention of the other paint helpers.

No behavior change.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 17:31:37 -06:00
Behdad Esfahbod 80807b128d [vector] Normalize color-line stops to [0, 1] before emit
SVG <stop offset="..."> requires offsets in [0, 1].  Out-of-
range stops were silently clamped by browsers, producing
visually wrong gradients for COLR fonts whose color lines
extend past those bounds.

Use the centralized hb_paint_normalize_color_line() to rescale
stops in place; shift the gradient axis (linear) / centers and
radii (radial) / start+end angles (sweep) by (mn, mx) along
the gradient axis to keep the visible gradient in the same
place.

Drop the now-unused local hb_vector_color_stop_cmp -- the
shared normalize helper sorts internally.

Regenerate the two affected basic.tests expected SVGs.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 17:31:37 -06:00
Behdad Esfahbod 6bbf421030 [paint] Centralize normalize_color_line in hb-paint.hh
Same routine appeared in hb-cairo-utils and hb-raster-paint.
Move to hb-paint.hh as hb_paint_normalize_color_line() and
update both call sites.  Behavior unchanged.

(hb-vector-paint and hb-gpu-paint still need normalization
work, separately.)

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 17:31:37 -06:00
Matej Smycka 488922519f [arabic] Fix overflow handling in apply_stch (#5929) 2026-04-15 16:19:06 -06:00
Behdad Esfahbod 14259b79dc [util/gpu/web] Silence "empty character constant" warnings
EM_ASM stringifies its body, but the C tokenizer still parses
single-quoted '' as an empty char constant.  Use double-quoted
"" -- valid JS empty string, no warning.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 15:46:02 -06:00
Behdad Esfahbod f8491cdb66 [paint] Centralize reduce_anchors in hb-paint.hh
hb-cairo-utils and hb-raster-paint each carried their own
identical static copy of the COLR 3-anchor → 2-point gradient
projection.  Drop both, use the shared
hb_paint_reduce_linear_anchors() added in the previous commit.
Behavior unchanged.

(hb-gpu-paint keeps its own copy intentionally -- it has
slightly different surrounding code paths and we don't want
to perturb the GPU encoder in this round.)

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 15:44:28 -06:00
Behdad Esfahbod ce4199c303 [vector] Fix linear-gradient anchor reduction
hb-vector-paint emitted (2*x1 - x2, 2*y1 - y2) as the SVG end
point -- the reflection of P2 about P1, not the projection.
For COLR linear gradients the SVG end should be P1 projected
onto the line through P0 perpendicular to (P2 - P0); that's
the gradient's actual axis (perpendicular to the rotation
line).  With the old formula, fonts with rotation references
far from the color line ended up with massively over-scaled
gradient axes -- e.g. BungeeSpice's ABC showed solid red where
raster shows a full red->yellow gradient.

Add hb_paint_reduce_linear_anchors() to hb-paint.hh as the
shared canonical implementation (matches hb-raster-paint and
hb-cairo) and use it from hb-vector-paint.

Regenerate the two affected basic.tests expected SVGs; the
new gradient endpoints are now consistent with the cairo /
raster outputs.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 15:44:10 -06:00
Behdad Esfahbod 7f6d75cd9e [util/gpu/web] Export _web_set_palette in both build scripts
The previous palette commit added the C entry point and the
shell.html message handler but forgot to list _web_set_palette
in EXPORTED_FUNCTIONS, so emscripten dead-stripped it and the
'palette' postMessage was a silent no-op in the iframe.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 15:29:42 -06:00
Behdad Esfahbod 59d819f09c [util/gpu/web] Live palette via postMessage
Add web_set_palette() to both GL and WebGPU bindings (forwards
to demo_font_set_palette + buffer rebuild) and accept a
{ kind: 'palette', value: <int> } message in shell.html.  Lets
the harfbuzz-world.cc host page push the user's CPAL pick into
the embedded GPU iframe alongside text / font / variations.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 15:22:13 -06:00
Behdad Esfahbod c559eb8bc9 [vector] NEWS: document hb_vector_*_flat removal
PR #5927 dropped the flat-mode API.  Add a Removed API entry,
cross-link it to the svg-prefix replacement bullet, and clean up
the now-stale Changed/New API entries that mentioned set_flat.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 15:07:11 -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