Commit Graph
11 Commits
Author SHA1 Message Date
Behdad Esfahbod e5c87cf042 [util/vector] Produce Y-up extents for auto-fit box
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>
2026-04-18 12:48:23 -06:00
Behdad Esfahbod dfef3f33ae [vector] Global Y-flip in SVG render, eliminate per-glyph flips
SVG render now wraps all body content in a single
<g transform="scale(1,-1)">.  All coordinates inside are
in Y-up (font) space.  The viewBox maps the flipped range.

This eliminates:
- Per-path scale(1,-1) wrappers in draw flush_path_svg
- Per-glyph Y-flip in paint _glyph_impl's push_transform
- The {-xy, -yy, -ty} negation in extents transforms
- Format switch in paint _glyph_impl

paint _glyph_impl now passes the raw transform to
push_transform — no format knowledge needed.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-18 04:50:21 -06:00
Behdad Esfahbod 82734f4ce5 [vector] Simplify draw _glyph_or_fail to just draw + flush
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>
2026-04-18 04:06:26 -06:00
Behdad Esfahbod 992835a182 [vector] Strip SVG dedup from draw, remove svg_prefix API
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>
2026-04-18 03:56:32 -06:00
Behdad Esfahbod c76b3a29a9 [vector] Content-based dedup, remove font reference caching
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>
2026-04-18 03:09:35 -06:00
Behdad Esfahbod bc7e513b2d [vector] Emit SVG coordinates in output-space
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>
2026-04-17 01:07:45 -06:00
Behdad Esfahbod 8b324b69a7 [util/vector] Remove SVG post-processing; write draw blobs directly
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>
2026-04-16 19:28:16 -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 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 12989d4e6a [util] Align vector/raster defaults with view and update vector baselines 2026-02-26 16:54:28 -03:00
Behdad Esfahbod 6653d62480 [test/util] Rename draw suite and tools to vector 2026-02-24 10:17:18 -03:00