_glyph_or_fail is now: extend extents, new_path, draw.
No format switch, no flush — just accumulate.
new_path() flushes any pending path and starts a fresh one,
separating glyph outlines so they don't interact under fill
rules.
Flush also happens on foreground change and at render time,
so the last pending path is always emitted.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove format switch from _glyph_or_fail — it now just extends
extents, calls hb_font_draw_glyph with the context's own funcs,
and flushes. All format-specific work is in flush_path() and
the draw callbacks.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Draw SVG output is now flat inline <path> elements — no
<defs>, no <use>, no id references. Each glyph is an
independent <path d="..." transform="..." fill="..."/>.
Remove hb_vector_draw_set_svg_prefix / get_svg_prefix since
draw output no longer emits any ids. Paint keeps svg_prefix
for gradient and clip ids which SVG requires.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The transform is transient per _glyph call, not a global
state for the entire document. Each glyph's <use> already
carries its own transform from the caller's set_transform.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
These are convenience APIs, not typesetting APIs — positioning
is the caller's responsibility via set_transform(). This
matches the GPU API which never had pen parameters.
All callers updated to use set_transform with pen position
before each _glyph call.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace glyph-ID-based dedup with content-based dedup for SVG
path definitions and color glyph groups. Path/paint output is
hashed and compared byte-for-byte against existing defs;
identical content reuses the same def regardless of glyph ID.
This eliminates the font reference held by draw/paint contexts
(cached_font + hb_font_reference), which was keeping the font
and its face alive longer than the caller expected. No font
pointer is stored at all now.
Also removes changed() — with content-based dedup, foreground
and palette changes produce different content that naturally
won't match cached entries.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Nastaliq and other deep-descender scripts were clipped because
the fit used only logical extents (one em height). Now uses
the union of ink and logical extents so all ink is visible.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- demo_buffer_set_features() sets global features for hb_shape
- web_set_features() wasm export parses comma-separated features
- Shell message handler accepts { kind: "features", value }
- Features applied to all shape calls in demo_buffer_add_text
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Allows the host page to simulate keypresses (e.g. 'b' for
dark mode toggle) via postMessage { kind: 'key', value }.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Malicious fonts with extreme scale values cause huge pixel
buffer allocations across multiple push_group surfaces. The
library correctly bounds individual surfaces at 1 GB, but
stacked group surfaces can exceed the fuzzer RSS limit.
Cap the font scale to 1000 in the harness so the exercised
surface stays within fuzzer memory constraints.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When clip nesting exceeds HB_GPU_PAINT_MAX_CLIP_DEPTH (3),
push_clip_glyph sets unsupported=true but still increments
clip_depth. emit_all_clip_sub_blobs then iterated clip_depth
without capping, reading past the fixed-size clip_stack array.
Cap the iteration at HB_GPU_PAINT_MAX_CLIP_DEPTH.
Fixes: https://oss-fuzz.com/testcase-detail/6573156621156352
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Coverage out parameter, premultiplied gradient interpolation,
foreground alpha fix, and the shader signature change.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Update the signature, parameter documentation, and sample code
to reflect the new edge coverage out parameter. Stem darkening
example now shows the coverage-based correction pattern.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hb_gpu_paint() now takes an out float coverage parameter that
receives the maximum slug coverage across all paint layers.
This lets the caller apply stem darkening and gamma correction
to edge antialiasing only, without distorting interior paint
colors (gradients, semi-transparent layers).
The demo shaders (GLSL, MSL, HLSL, WGSL) use the new parameter
to share a single coverage-correction block between draw and
paint paths. Also fixes the blend func to GL_ONE for correct
premultiplied compositing.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Reference the new font before destroying the old one, in case
both pointers are the same object. In practice the caller always
holds its own reference so this cannot trigger, but the pattern
is safer and silences Coverity CID 503195/503196.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add sample code for both draw and paint contexts, note that
render clears accumulated content (get extents first), and
document the semi-transparent overlap compositing behavior.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The OpenType COLR spec requires gradient interpolation in
premultiplied space. The shader was interpolating unpremultiplied
stop colors directly, which produced washed-out transitions when
a stop fades toward transparency (e.g. opaque red to transparent
gives desaturated pink instead of red at decreasing opacity).
Premultiply stop colors before mix(), unpremultiply the result.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hb_gpu_paint() returns premultiplied RGBA, as documented in
hb-gpu.cc. The GL demo was using GL_SRC_ALPHA which
double-applied alpha, darkening semi-transparent colors.
Use GL_ONE as the API docs prescribe.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
These backends use immediate-mode foreground: they pass their
foreground color to hb_font_paint_glyph() and use the resolved
color from the callback directly. The is_foreground substitution
was redundant (a no-op when foreground alpha is 255) and prevented
semi-transparent foreground alpha from working correctly.
Now the foreground is passed as-is (including its alpha) to
hb_font_paint_glyph(), and the color callback ignores
is_foreground — the color already carries the correct value.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The previous commit scaled all four components of the foreground
uniform by the baked paint-tree alpha, which darkened the RGB
towards black. The foreground is unpremultiplied, so only the
alpha channel should be modulated; the shader's later premultiply
step handles the rest.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Explain the two valid usage modes: immediate (use @color directly)
and deferred (substitute own foreground RGB, combine alpha). Note
that deferred mode requires passing an opaque foreground to
hb_font_paint_glyph().
hb_color_stop_t defers to hb_paint_color_func_t for the
is_foreground/color contract.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When is_foreground was set, the shader replaced the entire baked
color with the foreground uniform, discarding the paint-tree alpha
encoded in the color's alpha channel. This meant COLRv1 glyphs
with a separate alpha on their foreground color sentinel would
lose that alpha at render time.
Now the shader multiplies the foreground uniform by the baked alpha
(ct.a / 32767 for LAYER_SOLID, b.a / 32767 for gradient stops),
preserving the paint-tree modulation.
Updated all four shader languages (GLSL, HLSL, MSL, WGSL) and
regenerated the .hh artifacts.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The synthesized fallback should signal is_foreground=true so
backends like cairo that handle foreground specially can detect
it. Pass alpha=255 since the caller passes opaque foreground
to paint_glyph; backends that care about foreground will apply
their own alpha.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The COLR walker's get_color bakes foreground_alpha into
the returned color. Since our backends don't substitute
paint->foreground in their callbacks (they trust the walker's
resolved color), passing foreground with its own alpha would
double-count it.
Force alpha=255 when passing foreground to hb_font_paint_glyph
and _or_fail, matching what cairo does. The backend applies
foreground alpha through its own mechanisms (draw fill-opacity,
raster compositing).
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The PDF draw context was dropping foreground alpha because
it had no resource dict for ExtGState. Semi-transparent
fills (e.g. --rainbow) rendered fully opaque.
Add a per-flush ExtGState with /ca (fill opacity) when
alpha < 255. The ExtGState entries are inlined in the
page's resource dict — no separate PDF objects needed.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The SVG and PDF paint_color callbacks were substituting
paint->foreground when is_foreground=true, ignoring the
color the COLR walker already resolved. The original paint
API contract is: if is_foreground, the color IS the
foreground — use it directly.
Same fix for gradient color stops: the color line already
has foreground colors resolved by the walker. Drop the
redundant substitution + alpha multiplication.
This removes the dependency on paint->foreground in the
paint callbacks, eliminating the dual-foreground path.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The synthesized mono fallback was passing is_foreground=true,
which caused the backend to modulate the foreground alpha
with the color's alpha — squaring the alpha when the color
was the foreground itself.
Instead, pass the foreground as a literal color (is_foreground=
false). This avoids any interaction with the backend's own
foreground state and passes the caller's foreground value
straight through.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
changed() was clearing defs, path, and group_stack (the
accumulated output) in addition to the glyph caches. When
set_foreground was called per-glyph (e.g. --rainbow), each
color change wiped all previous glyphs — only the last one
survived in the rendered output.
Only clear the caches (defined_outlines, defined_clips,
active_color_glyphs, defined_color_glyphs). Leave the
output buffers and counters intact.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The recently added --stroke option is only meaningful in
hb-view (cairo rendering). The experimental utils
(hb-raster, hb-vector, hb-gpu) don't support stroked
outline rendering. Hide from --help but keep functional;
--rainbow still enables it implicitly.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The PDF push_transform and per-glyph cm were emitting
matrix entries (xx, yx, xy, yy) at default precision=2.
For small values like 1/31.25 = 0.032, this rounded to
0.03 — a 6.25% error that accumulated through nested
transforms, visibly distorting color emoji rendering.
Use scale_precision (min 7) for matrix entries, matching
the SVG paint backend.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The SVG global transform prefix emitted x0/y0 raw without
dividing by scale_factor. The PDF per-glyph cm was reduced
to identity + translation, losing the matrix entries from
paint->transform when non-identity.
Fix: divide x0/y0 by sf in SVG; emit full matrix in PDF cm.
Update stale comment.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Same treatment as SVG: scale all PDF paint coordinates by
1/scale_factor so clip paths, transforms, gradients, images,
and sweep meshes emit in fractional pixel values.
The per-glyph cm matrix becomes a simple translation (the
content is already in output-space). Revert the 1000000
fill rect bandaid back to 32767.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Scale all SVG paint and draw coordinates by 1/scale_factor
so paths, clips, gradients, transforms, and images emit
fractional pixel values instead of font-scale integers.
The per-glyph <use> transform now applies only a Y-flip
(scale(1,-1)) instead of scale(1/sf,-1/sf), since the
content is already in output-space.
Revert the 1000000 fill rect bandaid back to 32767 — in
output-space, 32767 pixels is always large enough.
SVG paint callbacks:
- push_clip_glyph: path sink divides by scale_factor
- push_clip_rectangle: coords divided by sx/sy
- push_transform: translation (dx,dy) divided by sx/sy
- gradient coords: divided by sx/sy
- sweep center: divided by sx/sy
- image extents: divided by sx/sy
SVG draw:
- Glyph outline path sink divides by scale_factor
Regenerated all vector test expected outputs.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Nothing SVG-specific remains in this header — it holds
blob recycling, transform helpers, extents helpers, and
the SVG instance transform. Rename to reflect its actual
role as shared vector internals.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace hb_vector_scale_precision() free function with
hb_buf_t::scale_precision() method.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The decimal point helper was the only content in the separate
.cc file. Move it into hb-vector.cc and remove the extra
compilation unit.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>