Commit Graph
21194 Commits
Author SHA1 Message Date
Behdad Esfahbod fbc2da4741 [util/vector] Remove write_combined_svg; simplify render
With --draw/--paint forcing a single mode per render, the
draw and paint paths are mutually exclusive — both can't
produce output in the same render.  Remove the combined
SVG merger and simplify to a single blob output.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 19:15:12 -06:00
Behdad Esfahbod 7c54a401c0 [vector-draw] Add foreground/background color API
Add hb_vector_draw_set_{foreground,background}() and getters.

SVG: foreground wraps body in <g fill="rgb(...)">; background
emits a <rect> covering the viewBox before content.

PDF: foreground sets fill color via rg operator before glyph
content; background emits a filled rect at the start of the
content stream.

Default: foreground opaque black, background transparent.

Wire both into the hb-vector CLI util alongside the paint
equivalents.  Remove the old util-side emit_background_rect.

Regenerated vector test expected outputs.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 19:13:33 -06:00
Behdad Esfahbod c2f7639c06 [util/vector] Remove util-side emit_background_rect
The util had its own background rect emitter that wrote
directly to the output file.  Now that hb_vector_paint has
set_background, the library handles it.  Remove the
duplicate to avoid double background emission.

Note: the draw path currently has no background support;
this is consistent — mono/draw SVGs are typically embedded
inline where background comes from the container.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 19:04:47 -06:00
Behdad Esfahbod 549f845139 [util] Add --background=none for transparent background
Allows explicitly requesting transparent output without
needing to spell out --background=00000000.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 19:01:34 -06:00
Behdad Esfahbod 533246778a [NEWS] Nit 2026-04-16 18:56:34 -06:00
Behdad Esfahbod d774a9a4e2 [vector/raster] Add set_background / get_background API
Add hb_vector_paint_set_background() / get_background() and
hb_raster_paint_set_background() / get_background().

For vector: if set to a non-transparent color, the SVG renderer
emits a <rect> covering the viewBox before glyph content, and
the PDF renderer prepends a filled rectangle to the content
stream.  Both support semi-transparent backgrounds (SVG via
fill-opacity, PDF via ExtGState /ca).

For raster: the root surface is pre-filled with the background
color before glyph compositing begins.

Default is transparent (no background emitted).

The hb-vector CLI util wires --background to the new API.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 18:22:07 -06:00
Behdad Esfahbod 05d5e35f36 [vector-paint-pdf] Add SMask alpha for sweep gradient meshes
Sweep gradients use Coons patch meshes (ShadingType 6) which
encode vertex colors as RGB bytes — no alpha channel.

When any stop has alpha < 255, build a parallel DeviceGray
mesh with the alpha channel and wrap it in a Form XObject
soft mask, same pattern as the linear/radial SMask support.

Also refactor: extract add_shading_by_id for mesh shadings
that are already allocated as objects (they contain streams).

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 18:08:04 -06:00
Behdad Esfahbod 692454636a [vector-paint-pdf] Add SMask support for gradient alpha
PDF DeviceRGB shadings have no alpha channel, so gradient
stops with partial opacity (like emoji blushes fading to
transparent) were rendered as solid color.

When any color stop has alpha < 255, build a parallel
DeviceGray shading for the alpha channel, wrap it in a
Form XObject transparency group, and reference it as a
luminosity soft mask via ExtGState.  The mask is vector
(resolution-independent) — the PDF renderer evaluates
the grayscale function analytically.

Applied to both linear (Type 2) and radial (Type 3)
gradient handlers.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 18:08:04 -06:00
Behdad Esfahbod 05e9bd5099 [vector] Fix aggregate init for hb_vector_path_sink_t
Drop default member initializers for x_scale/y_scale since
C++11/14 doesn't allow aggregate initialization of structs
with default member initializers.  All callers now specify
all four fields explicitly.

Fixes CI build failure.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 17:50:47 -06:00
Behdad Esfahbod 3c533add46 [vector-paint-pdf] Normalize gradient color stops before emit
The SVG paint backend normalizes color-line stops to [0, 1]
(via hb_paint_normalize_color_line) and adjusts gradient
coordinates accordingly.  The PDF backend was emitting raw
stop offsets and unadjusted coordinates, causing mismatched
gradient geometry — most visibly, radial gradients with a
non-zero focal radius (like emoji blushes) rendered with
r0=0 instead of the correct adjusted inner radius.

Fetch and normalize stops before building the PDF gradient
function, then shift linear/radial coordinates by (mn, mx)
the same way SVG does.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 17:41:47 -06:00
Behdad Esfahbod c225835410 [vector] Scale clip path coordinates by 1/scale_factor
Clip path coordinates arrive in font-scale (input space) but
need to be in output space for both SVG and PDF.  Add x_scale
and y_scale fields to hb_vector_path_sink_t (default 1.0) and
divide through in the append_xy helpers.

For clip paths, the SVG and PDF paint backends set these to
scale_factor so the emitted coordinates land in output space
without needing a wrapping transform.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 17:25:24 -06:00
Behdad Esfahbod fbdd39bed7 [util/vector] Fix show-extents stroke width scaling
get_normalized_stroke_width() was gated on stroke_enabled,
returning the raw pixel value (1.0) when --stroke wasn't
active.  The show-extents overlay uses this value regardless
of --stroke, so it got a stroke_width of 1 in font-scale
space (= 0.016 pixels after /SCALE).

Remove the stroke_enabled guard so the pixel → font-scale
conversion always applies.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 17:21:04 -06:00
Behdad Esfahbod 8ed9cc3ff5 [vector-draw] Fix SVG show-extents: flush path before next glyph
Free-form draw ops (extents overlay rectangles/circles) emitted
via hb_vector_draw_get_funcs() accumulate in draw->path.  But
the SVG glyph emission clears draw->path when drawing each new
glyph outline, discarding the overlay from the previous glyph.

Flush any accumulated path data to body (wrapped in the Y-flip
<g>) before clearing for the next glyph outline, so overlays
for all glyphs survive to the final SVG.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 17:17:58 -06:00
Behdad Esfahbod d1bb9a595c [util/vector] Drop upem_font; operate in font-scale space
The vector util was creating a separate upem-scaled font clone,
converting all shaping positions from font-scale to upem, and
setting scale_factor to upem/font_size to undo that on emit.

Simplify: use the caller's font directly.  Positions from
shaping are stored as-is (in font-scale = pixel * SCALE).
scale_factor is just SCALE (= 1 << subpixel_bits), so the
lib divides by SCALE on emit to produce pixel-space output.

This removes ~40 lines: the upem_font creation, variation
coord copying, scale_to_upem_x/y helpers, and the complex
upem_per_pixel margin/stroke conversions.  Margin conversion
simplifies from margin * upem * SCALE / x_scale to just
margin * SCALE.

Regenerated vector test expected outputs for the new
coordinate space.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 17:11:45 -06:00
Behdad Esfahbod 36bf8ecaf2 [vector] Auto-flush glyph caches on font change
Track the font pointer and serial in both hb_vector_draw_t and
hb_vector_paint_t.  On each draw/paint_glyph call, compare the
incoming font against the cached values; if the pointer or
serial changed, call changed() to flush all cached glyph data
(defined_glyphs, defs, color glyph cache, counters).

The cached_font holds a reference so pointer-reuse after
destroy is detected correctly.

This makes context reuse across font changes safe without
requiring callers to call any explicit invalidation API.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:59:19 -06:00
Behdad Esfahbod 80ca5617ff [vector] Split path draw funcs into per-format singletons (#5935)
Replace the single hb_vector_path_draw_funcs_get() (which
dispatched on sink->format via a switch in every callback)
with two format-specific singletons:

  hb_vector_svg_path_draw_funcs_get()
  hb_vector_pdf_path_draw_funcs_get()

Each callback set is straight-line code with no branching.
The PDF set omits the quadratic_to callback, so the
framework's null fallback auto-promotes quadratics to cubics
— removing the manual quad-to-cubic conversion that was
previously hand-rolled in the PDF quadratic_to case.

A convenience dispatcher hb_vector_path_draw_funcs_get(format)
is kept for callers that select at runtime.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:58:56 -06:00
Behdad Esfahbod 68afee084c [vector-paint-pdf] Fix use-of-uninitialized in indexed smask
inflate() with Z_FINISH can return Z_STREAM_END after
decompressing fewer bytes than the expected raw_len when
the IDAT data is truncated or the width/height don't match
the actual compressed payload.  The un-filter loop then
reads uninitialized tail bytes from the raw buffer.

Check that stream.total_out matches raw_len after inflate;
bail out if the sizes disagree.

Fixes: https://oss-fuzz.com/testcase-detail/5190826362994688

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:32:38 -06:00
Behdad Esfahbod 3c5352badd Merge pull request #5933 from harfbuzz/paint-clip-path
Arbitrary clip paths in paint sinks
2026-04-16 16:25:37 -06:00
Behdad Esfahbod 76d543adc9 fixup! [draw][paint] Make get_funcs instance-aware; add get_format 2026-04-16 16:23:32 -06:00
Behdad Esfahbod 6636f042fc Address PR #5933 review feedback
- Reset Since tags to XSince: REPLACEME for changed
  get_funcs signatures (gpu, raster, vector draw+paint).
- Replace (transfer none) annotation syntax with prose in
  clip_path_start docs (hb-paint.cc and hb-paint.h).
- Document that returned draw funcs/data are only valid
  until the matching clip_path_end call, and no other paint
  calls should be made in between.
- Use switch instead of ternary for format in
  hb-vector-path.cc.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:22:42 -06:00
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