From 3fe077d71383467232f7ffb1d8a10180d823e4ae Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 15 Apr 2026 11:34:51 -0600 Subject: [PATCH] [vector] Flat mode: inline clip-path="path('...')" instead of Flat output was still emitting into 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('')" push_clip_rectangle -> clip-path="path('M..H..V..H..Z')" ...directly on the wrapping , 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 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) --- src/hb-vector-paint.cc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/hb-vector-paint.cc b/src/hb-vector-paint.cc index cc7c559eb..9ca2fce31 100644 --- a/src/hb-vector-paint.cc +++ b/src/hb-vector-paint.cc @@ -479,6 +479,20 @@ hb_vector_paint_push_clip_glyph (hb_paint_funcs_t *, if (unlikely (!hb_vector_paint_ensure_initialized (paint))) return; + if (paint->flat) + { + /* Inline clip: emit clip-path="path('...')" so the + * output has no defs to reference and the whole SVG + * is safe to concatenate with other hb-vector output. */ + paint->path.clear (); + hb_vector_svg_path_sink_t sink = {&paint->path, paint->precision}; + hb_font_draw_glyph (font, glyph, hb_vector_svg_path_draw_funcs_get (), &sink); + hb_buf_append_str (&paint->current_body (), "current_body (), paint->path.arrayZ, paint->path.length); + hb_buf_append_str (&paint->current_body (), "')\">\n"); + return; + } + if (!hb_set_has (paint->defined_outlines, glyph)) { hb_set_add (paint->defined_outlines, glyph); @@ -518,6 +532,23 @@ hb_vector_paint_push_clip_rectangle (hb_paint_funcs_t *, if (unlikely (!hb_vector_paint_ensure_initialized (paint))) return; + if (paint->flat) + { + /* Inline clip as a polygon via clip-path="path('...')". */ + hb_buf_append_str (&paint->current_body (), "current_body (), xmin, paint->precision); + hb_buf_append_c (&paint->current_body (), ' '); + hb_buf_append_num (&paint->current_body (), ymin, paint->precision); + hb_buf_append_str (&paint->current_body (), "H"); + hb_buf_append_num (&paint->current_body (), xmax, paint->precision); + hb_buf_append_str (&paint->current_body (), "V"); + hb_buf_append_num (&paint->current_body (), ymax, paint->precision); + hb_buf_append_str (&paint->current_body (), "H"); + hb_buf_append_num (&paint->current_body (), xmin, paint->precision); + hb_buf_append_str (&paint->current_body (), "Z')\">\n"); + return; + } + unsigned clip_id = paint->clip_rect_counter++; hb_buf_append_str (&paint->defs, "defs, clip_id);