include_point used to flip Y so the computed line-box extents
matched the old Y-down internal model. With the library now
tracking extents in Y-up (font) space and wrapping SVG body
in <g transform="scale(1,-1)">, that flip sent the auto-fit
viewBox above the glyph ink instead of around it.
Regenerate the vector expected SVGs that had captured the
shifted viewBox.
Assisted-by: Claude Opus 4.7 (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>
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 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>
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>
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>
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>
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>
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>
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>
- 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>
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>
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>
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>
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>
- Default hb_vector_{draw,paint}_t::format to HB_VECTOR_FORMAT_INVALID
instead of HB_VECTOR_FORMAT_SVG.
- Update renamed hb_vector_{draw,paint}_set_{flat,precision} API docs
from "Since: 13.0.0" to "XSince: REPLACEME".
- Extract hb_vector_draw_render_svg() helper to match the
hb_vector_draw_render_pdf() pattern; move the misplaced
hb_vector_draw_render doc comment to the actual function and update
it to say "output blob" since the renderer is no longer SVG-only.
- Revert 14.0.0 NEWS entry edits; the API rename will be announced in
the next release entry.
- Update docs/harfbuzz-sections.txt to reflect the API renames.
- hb-vector tool: expose -O/--output-format with supported formats
"svg/pdf", validate format, update description string, and switch
PDF detection to g_ascii_strcasecmp for case-insensitive matching.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Drop "svg" from the names since flat/precision settings apply
equally to PDF output. The new names follow the hb_vector_draw_*
/ hb_vector_paint_* convention:
hb_vector_svg_set_flat -> hb_vector_draw_set_flat
hb_vector_svg_set_precision -> hb_vector_draw_set_precision
hb_vector_svg_paint_set_flat -> hb_vector_paint_set_flat
hb_vector_svg_paint_set_precision -> hb_vector_paint_set_precision
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add hb-vector-pdf-paint.cc with a complete set of PDF paint
callbacks for the HarfBuzz paint API:
push/pop_transform → q + cm / Q
push/pop_clip_glyph → q + path + W n / Q
push/pop_clip_rect → q + re + W n / Q
color → rg + re + f
push/pop_group → q / Q
gradients → solid fallback (first stop color)
The PDF paint backend reuses the draw funcs for glyph clip
path emission and shares the hb_vector_paint_t struct with
the SVG backend via hb-vector-paint.hh.
hb_vector_paint_glyph dispatches to SVG or PDF paint funcs
based on format. hb_vector_paint_render delegates to the
PDF render function for PDF output.
Tested with COLRv0 (RocherColorGX) — color layers render
correctly with proper clipping.
Assisted-by: Claude <noreply@anthropic.com>
Add HB_VECTOR_FORMAT_PDF to hb_vector_format_t. The hb-vector
tool now produces self-contained PDF when invoked with -o out.pdf.
PDF path operators map directly from the draw callbacks:
move_to → m, line_to → l, cubic_to → c, close_path → h,
with quadratic-to-cubic promotion (PDF has no Q operator).
The render function builds a minimal PDF 1.4 with catalog,
page, and content stream objects plus a cross-reference table.
Implementation:
- Extract hb_vector_draw_t struct to hb-vector-draw.hh so
future backends can share it.
- Draw callbacks branch on format for SVG vs PDF syntax.
- hb_vector_draw_glyph and hb_vector_draw_render dispatch by
format.
- vector-output.hh selects format from file extension and
skips paint (color glyphs) for PDF.
Coordinate system needs refinement — the page layout inherits
the SVG Y-flip transform, placing glyphs at the top with
extra whitespace. Correct PDF coordinate handling is a
follow-up.
Assisted-by: Claude <noreply@anthropic.com>