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>
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>
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>
* [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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Mention the live in-browser playground and the worked
single-file build example at <https://harfbuzz-world.cc/>:
- README.md: extend the existing amalgamated-sources
paragraph with a pointer.
- BUILD.md: add a paragraph at the bottom of the
no-build-system section pointing at the playground
and at the source repo (which is itself a worked
example of `harfbuzz-world.cc` integration).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add web_set_variations(const char *) to both the WebGL and
WebGPU hb-gpu-web wasm modules. Parses a comma-separated
"wght=400,wdth=100" string via hb_variation_from_string,
applies via hb_font_set_variations on the current font, and
rebuilds the shaping buffer. Cheap to call repeatedly --
suitable for live slider pushes once a slider UI lands.
Shell.html grows a matching applyVariations() helper and a
'variations' postMessage case. config-override.h undefs
HB_NO_VAR so the new function actually links. EXPORTED
_FUNCTIONS on both build scripts list _web_set_variations.
Also plumbed in a small cap (32 axes) on the stack so the
parser doesn't need hb's internal containers -- no font has
anywhere near that many.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
HB_LEAN was dropping GSUB/GPOS out of the subset output,
which turns subsetting Arabic / Indic / any complex-script
font into a paperweight: the produced subset has no layout
so it can't shape the text it was subsetted for. That's
not really "lean", that's broken for most non-Latin use.
Subset layout is load-bearing enough that it should stay in
any HB_LEAN / HB_TINY build. Callers that truly don't want
it can still #define HB_NO_SUBSET_LAYOUT themselves.
meson test --no-rebuild is green (241/241).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The iframe-hosted case ran resizeCanvas() at script parse
time, before the iframe had laid out its canvas, which
installed a 0x0 drawing buffer. getContext('webgl2')
grabbed that 0x0 context and every subsequent setup (atlas,
viewport, swap chain) was frozen at 0x0 even when
ResizeObserver later re-ran resizeCanvas with real dims --
the existing context doesn't resize with the canvas
attribute.
Bail out of resizeCanvas when either dimension is 0, so the
canvas keeps its intrinsic default (300x150) until a real
layout arrives. getContext then grabs a non-degenerate
context, and the first ResizeObserver callback bumps it up
to the actual iframe-sized buffer.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Changing canvas.width/height directly doesn't reach
emscripten's GLFW port -- its framebuffer-size callback
fires on window 'resize' events, not canvas mutation
records. When ResizeObserver picks up the iframe's first
real layout, also dispatch a synthetic 'resize' event so
the framebuffer_size callback runs in wasm and glViewport
gets re-set to the real size.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Initial resizeCanvas() runs at script parse time -- when the
shell is inside a just-mounted iframe, the canvas's
clientWidth / clientHeight are 0 (iframe hasn't laid out
yet) and the GL drawing buffer installs at 0x0. A plain
window 'resize' event never fires just because the iframe
has sized itself, so the buffer stays 0x0 and the tab looks
blank forever.
Watch the canvas with a ResizeObserver and re-run
resizeCanvas + requestRedraw on any observed size change,
which catches the first real size the moment the iframe
lays out.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Missed one emission site in the SVG color-glyph path: when a
color glyph is first seen, hb-vector both defines it in
<defs id="cg<N>"> (which I prefixed) and emits an initial
<use href="#cg<N>"> in the body (which I did not). The mix
meant body refs for the first use of every color glyph went
unprefixed, so a caller-prefixed document had refs pointing
to nonexistent IDs and the whole image came out blank.
Fix: route that href="#cg<N>" through the prefix too.
Verified on Noto Emoji subset: rsvg-convert with a "v1-"
prefix now renders the full color glyph (was blank before).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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>
Flat output was still emitting <clipPath id="..."> into <defs>
and referencing them via clip-path="url(#...)". That meant
flat SVGs couldn't be safely concatenated: two documents'
short IDs (c0, clip-g10, ...) would collide and url(#c0)
resolves to whichever element appears first in document
order, producing the wrong clip and giant paint rects
falling through their clips.
SVG 2 lets clip-path take inline basic-shape or path()
values. In flat mode, emit:
push_clip_glyph -> clip-path="path('<glyph-d>')"
push_clip_rectangle -> clip-path="path('M..H..V..H..Z')"
...directly on the wrapping <g>, skipping defs entirely.
The resulting flat SVG truly has no defs for clips and is
safe to embed alongside other hb-vector output.
Gradients still use defs (paint servers need URL refs), but
those only affect color, not geometry -- a gradient
resolution mismatch yields wrong colors, never the
unclipped-rect bleed that was the visible symptom.
Verified on util/gpu/web/ / harfbuzz-world.cc's Noto color
emoji subset: no <clipPath> tags, no clip-path="url(...)",
69 inline clip-path="path('...')" refs instead. Meson
test --suite vector remains 22/22 green.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Be permissive about the embed-mode URL form: ?embed,
?embed=1, ?embed=true all turn the mode on; only explicit
?embed=0 / ?embed=false leave it off.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Lets a host page embed hb-gpu-demo as an iframe and drive it
from outside. harfbuzz-world.cc uses this to share its
text/font controls with the GPU tab without reinventing the
GPU stack.
Shell additions:
- ?embed=1 URL param hides the demo's own chrome (font
picker, text button, backend selector, FPS counter,
keyboard-help overlay) by setting html.embed.
- Message protocol:
{ kind: 'text', value: '…' } -> applyText
{ kind: 'font', bytes: ArrayBuffer } -> _web_load_font
On runtime init the shell posts { kind: 'ready' } to its
parent so the host can send font bytes (which can't ride
on the URL for file-uploaded fonts).
Existing ?text= and ?font= URL params still work and are
useful for "link to a specific demo" sharing.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
src/harfbuzz-world.cc unconditionally #includes hb-number.cc,
hb-ot-cff1-table.cc, and hb-ot-cff2-table.cc in its core
group, then re-#includes the same three files in its
HB_HAS_SUBSET group (carried over from when the subset
library was its own translation unit). In the single-TU
amalgamation that's a redefinition error and prevents
HB_HAS_SUBSET from being enabled.
Wrap each file in the same HB_FOO_CC ifndef/define/ifdef
guard pattern already used by hb-static.cc and hb-zlib.cc, so
a second #include is a no-op.
Verified with a wasm build of harfbuzz-world.cc that has both
the core and subset blocks active, and a full meson test
run (241/241 OK) on the regular library build.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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>
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>
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>
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>
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>
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>
hb-gpu only honors four of view_options_t's eleven options
(--foreground, --background, --font-palette, --custom-palette).
Exposing the full set via --help-view misled users into trying
--stroke, --margin, --rainbow, etc., which silently did nothing.
Merge the four relevant entries into the GPU option group
(pointing at view_options_t's storage fields) and delegate
parsing to view.post_parse() via a new gpu_output_t::post_parse.
Drops the unused view entries from --help while keeping all
the color/palette parsing logic shared with hb-view / hb-raster.
Assisted-by: Claude <noreply@anthropic.com>
Scripted / CI use of hb-gpu -o wants clean stderr. Gate LOGI on
a hb_gpu_demo_quiet flag that hb-gpu flips to 1 when an output
file is specified, so font stats, help text, and toggle-vsync
chatter all stay out of the way.
LOGW / LOGE are intentionally unaffected -- warnings and fatal
errors should always surface regardless of quiet mode.
Assisted-by: Claude <noreply@anthropic.com>
Using output_options_t<false> (no stdout default) was the wrong
choice: post_parse() rejects any invocation without -o, so every
windowed hb-gpu run started failing with "No output file was
specified."
Roll a bespoke char* option instead: if set, render one frame
to PPM (opening the file or stdout inline); otherwise the usual
windowed mode. Keeps both code paths trivial and doesn't
require the caller to specify an output file for interactive
use.
Assisted-by: Claude <noreply@anthropic.com>
Previously clear() bailed outright under !successful, to protect
the Null singleton which lives in (possibly read-only) static
storage. That meant a real instance entering error state would
silently fail to clear, leaving stale contents for the next
caller.
Replace the `!successful` guard with an early-out on already-
empty state. The Null singleton is zero-initialized (population,
occupancy, mask all 0), so the early-out catches it before any
write. Any non-empty instance is by construction a real heap
object with writable storage, so clearing is safe there even
under !successful.
Assisted-by: Claude <noreply@anthropic.com>
The prior commit (2adb01a47c) made hb_bit_set_t::clear() always
zero length/population, parallel to the hb_vector_t::clear()
March fix. But hb_bit_set_t (and hb_hashmap_t) have a different
invariant: an instance returned from a failed create-or-reference
path is an inert / Null singleton in possibly read-only storage,
so clear() MUST bail on !successful or it would segfault.
This was exactly what the `if (unlikely (!successful)) return;`
guard was protecting. test-set caught the regression.
Vector is different: it has no Null singleton returned to users,
so always-clearing is safe there.
The graph/serialize.hh resize(0) -> clear() change from the same
commit is still correct -- that's a caller-supplied vector, not
a set.
Assisted-by: Claude <noreply@anthropic.com>
Two callers were still using vector.resize(0) to drop accumulated
data: graph/serialize.hh's overflow tracking and hb_bit_set_t's
clear() (via its own internal resize()). resize(0) on a vector
in error state short-circuits without zeroing length, leaving
stale entries that downstream code then walks as if valid.
Fix both:
- serialize.hh: call overflows->clear() instead.
- hb-bit-set.hh: reimplement clear() to zero length/population
unconditionally by calling pages.clear() / page_map.clear()
directly, bypassing the internal resize() that bails when
`successful` is false.
Mirrors the March clear() fix in hb-vector.hh (commit d134f88824).
Assisted-by: Claude <noreply@anthropic.com>
After the March refactor that made clear() a direct
shrink_vector(0), reset() going through resize(0) adds an
indirection (resize_full -> alloc(0) no-op -> shrink_vector(0))
for identical observable behavior. Use clear() directly.
Assisted-by: Claude <noreply@anthropic.com>
Three accumulator vectors -- ops, sub_blobs, transform_stack --
can enter error state via failed push_or_fail() under
failing-malloc. Once in error state, resize(0) short-circuits
at the in_error() guard in alloc() and leaves length unchanged.
In hb_gpu_paint_clear that means the next iteration's clear
walks the stale entries again. For sub_blobs this is a
double-destroy: the blob pointers were already freed in the
previous clear, and hb_blob_destroy reads the dead ref_count
field -- heap-use-after-free.
Fix by calling vector.reset(), which clears the error state
before resizing to 0. Matches the pattern hb_gpu_draw_clear
already uses for draw->curves.
Found by oss-fuzz/CIFuzz on hb-gpu-fuzzer; minimized testcase
added to the fuzz corpus.
Assisted-by: Claude <noreply@anthropic.com>
The curve accumulator grew without bound, reaching 2.9 GB on
fuzzer-crafted inputs (VARC components expanded recursively, or
cu2qu subdivisions on degenerate cubics, or a glyf with absurd
contour counts). libFuzzer flags this as OOM.
Add HB_GPU_DRAW_MAX_CURVES = 0x10000 (65536) -- far above any
real glyph's needs -- and refuse to emit beyond it, flipping
success=false so the encoder returns a valid empty/failure
blob. Catches all upstream explosions (glyf / cu2qu / VARC /
any future source) at the single choke point.
Found by oss-fuzz/CIFuzz on hb-gpu-fuzzer.
Assisted-by: Claude <noreply@anthropic.com>