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>
Last free function calls in vector code converted to methods.
Zero hb_buf_append_* free function calls remain.
Also fix stale comment referencing old function name.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Convert hb-vector-svg.hh and hb-vector-path.cc to use
hb_buf_t methods instead of hb_buf_append_* free functions.
Add append_hex_byte method to hb_buf_t (avoids static local
symbol leak from inline method).
Remove hb_buf_append_hex_byte free function from svg.hh
(now a method).
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace all hb_vector_t<char> with hb_buf_t throughout the
vector code — struct fields, local variables, function
parameters. Convert hb_buf_append_* free function calls
to hb_buf_t method calls (.append_str, .append_num,
.append_c, .append_len, .append_unsigned).
Drop the keep_nonzero parameter from append_num — callers
that need it already use hb_vector_scale_precision for
sufficient precision.
Rename hb-vector-svg-utils.{cc,hh} → hb-vector-utils.{cc,hh}
since hb_buf_t and the numeric helpers are format-agnostic.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hb_pdf_emit_glyph_path was allocating a full hb_vector_draw_t
on the stack (with its own heap-allocated buffers) just to
emit one glyph path. Use paint->path (the existing scratch
buffer) with the PDF path sink directly — no temporary draw
context, no extra allocations.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add hb_buf_t inheriting from hb_vector_t<char> with:
- precision field (default 2)
- append_num, append_c, append_str, append_len, append_unsigned
convenience methods
Convert defs/body/path in both hb_vector_draw_t and
hb_vector_paint_t from hb_vector_t<char> to hb_buf_t.
Remove the standalone precision field from both structs;
set_precision/get_precision are now methods that propagate
to the buffers. C API functions are thin wrappers.
Callers can still use the old free functions (hb_buf_t
IS-A hb_vector_t<char>). The new methods allow gradual
migration.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The SVG color glyph cache keys on (glyph, palette, foreground)
but changing these setters didn't invalidate the cache, so
stale rendered color glyphs could be reused.
Call changed() from set_foreground, set_palette,
set_custom_palette_color, and clear_custom_palette_colors
when the value actually changes.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace the single unified draw callbacks (which switched on
format in every callback) with separate SVG and PDF callback
sets, matching the path sink split pattern.
SVG: straight-line M/L/Q/C/Z operators with comma separators.
PDF: straight-line m/l/c/h operators with space separators.
PDF omits quadratic_to — null fallback auto-promotes to cubic.
Also split append_xy and flush_path into format-specific
methods (append_xy_svg/pdf, flush_path_svg/pdf) in the .hh.
hb_vector_draw_funcs_get() now takes format and dispatches.
hb_vector_draw_get_funcs() passes draw->format through.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Extract all SVG-specific paint callbacks (push_transform,
push_clip_glyph, push_clip_rectangle, push_clip_path,
pop_clip, color, image, gradients, push/pop_group,
color_glyph, custom_palette_color) and the SVG render
function into a new file, matching the existing PDF split.
hb-vector-paint.cc retains the public API, format dispatch,
glyph_impl, clear, and render.
Also:
- Move ensure_initialized to a method on hb_vector_paint_t
- Move hb_vector_color_glyph_cache_key helper to .hh
- Rename hb_vector_paint_funcs_get → hb_vector_paint_svg_funcs_get
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The SVG and PDF paint backends use large clipped rectangles
to fill solid colors and gradient backgrounds. The old
constant 32767 was sized for upem-space coordinates (~2048
max). After the pixel-space change, coordinates can be in
font-scale (upem * SCALE, e.g. 131072 for a 2048-upem font
at SCALE=64). Values above 32767 fell outside the fill
rect, causing COLRv0 glyph layers to be clipped at the top.
Bump all instances to 1000000 as a bandaid; proper fix is
to emit paint coordinates in output-space.
Regenerated vector test expected outputs.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The GPU util's auto-detect only checked hb_ot_color_has_paint
(COLRv1). COLRv0 fonts like BungeeTint have layers but no
paint tree, so they were incorrectly routed to the mono draw
path.
Add hb_ot_color_has_layers and hb_ot_color_has_png to the
check, matching the raster and vector utils.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use hb_memcpy instead of casting uint8_t* to uint32_t*
to avoid -Wcast-align on platforms with strict alignment.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The paint SVG backend bakes all colors directly — no CSS
var(--hb-...) references remain in the output. So the util's
SVG parser, var resolver, palette cache, and slice_svg
infrastructure are all dead code.
write_blob is now just fwrite.
Removes ~340 lines: slice_svg, write_slice_resolving_palette_vars,
parse_var_color_expr, find_next_var_expr, find_matching_paren,
emit_css_color, lookup_palette_color, init_palette_color_cache,
skip_ascii_ws, trim_ascii_ws_right, parsed_var_color_expr_t,
and associated palette cache state.
Regenerated vector test expected outputs (color font SVGs
now emit directly without var resolution pass).
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Now that the draw library handles per-glyph foreground fills
and background rects, the util no longer needs to parse and
re-emit SVG for draw blobs. Draw blobs are written directly
to the output file, same as PDF.
Paint SVG still needs var(--hb-...) resolution, so paint
blobs go through the existing write_slice_resolving_palette_vars
path.
Removes ~120 lines: emit_fill_group_open/close,
emit_draw_body_with_palette, emit_fill_stroke_attrs_for_color,
emit_stroke_attrs, and the draw-specific branches in write_blob.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move the path→body flush logic into draw->flush_path() and
use it everywhere: per-glyph emission, pre-glyph flush, and
render-time final flush.
The helper applies the current foreground color to every
flushed path — both glyph outlines and free-form draw ops
(like show-extents overlays) inherit the foreground that
was set at flush time.
SVG: fill="rgb(...)" on the <path> inside the Y-flip <g>.
PDF: rg operator before each fill.
Regenerated vector test expected outputs.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move foreground fill from a global wrapper (SVG <g fill>,
PDF initial rg) to per-glyph emission:
SVG: each <use> gets fill="rgb(...)" from the current
draw->foreground at emission time.
PDF: each glyph path gets an rg operator before fill.
This lets callers change foreground between glyph calls
(e.g. per-glyph palette cycling) without post-processing.
Wire per-glyph palette cycling for the draw path in the
hb-vector util, matching how paint already does it.
Regenerated vector test expected outputs.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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>
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>
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>
Allows explicitly requesting transparent output without
needing to spell out --background=00000000.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
- 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>
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>
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>
* 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>
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>
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>
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>