From 992835a182ae2202fa6299031ff7ac8151b6a63f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 18 Apr 2026 03:53:18 -0600 Subject: [PATCH] [vector] Strip SVG dedup from draw, remove svg_prefix API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Draw SVG output is now flat inline elements — no , no , no id references. Each glyph is an independent . 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) --- src/hb-vector-draw.cc | 115 +----------------- src/hb-vector-draw.hh | 10 -- src/hb-vector.h | 7 -- test/vector/data/expected/basic/cff1.svg | 11 +- .../data/expected/basic/cff2-var-cntr.svg | 11 +- .../data/expected/basic/cff2-var-wght900.svg | 9 +- test/vector/data/expected/basic/default.svg | 11 +- .../data/expected/basic/glyf-var-wght900.svg | 11 +- .../expected/basic/glyf-vvar-ttb-wght900.svg | 11 +- .../basic/iran-nastaliq-y-offsets.svg | 23 ++-- test/vector/data/expected/basic/multiline.svg | 11 +- test/vector/data/expected/basic/ttb.svg | 11 +- .../data/expected/basic/upem-default.svg | 11 +- .../expected/varc/conditional-default.svg | 5 +- .../expected/varc/conditional-wght840p3.svg | 5 +- test/vector/data/expected/varc/default.svg | 8 +- test/vector/data/expected/varc/wght840p3.svg | 8 +- 17 files changed, 46 insertions(+), 232 deletions(-) diff --git a/src/hb-vector-draw.cc b/src/hb-vector-draw.cc index 00c1277dc..6c99a3ef5 100644 --- a/src/hb-vector-draw.cc +++ b/src/hb-vector-draw.cc @@ -555,41 +555,6 @@ hb_vector_draw_glyph_or_fail (hb_vector_draw_t *draw, if (!draw->path.length) return false; - /* Content-based dedup: hash the path data, look for an - * existing def with identical bytes in defs. */ - uint32_t h = hb_hash (hb_bytes_t (draw->path.arrayZ, draw->path.length)); - unsigned def_id = (unsigned) -1; - for (auto &e : draw->defined_paths) - { - if (e.hash == h && - e.defs_length == draw->path.length && - 0 == hb_memcmp (draw->defs.arrayZ + e.defs_offset, - draw->path.arrayZ, draw->path.length)) - { - def_id = e.def_id; - break; - } - } - if (def_id == (unsigned) -1) - { - def_id = draw->path_def_count++; - draw->defs.append_str ("defs.append_len (draw->id_prefix.arrayZ, draw->id_prefix.length); - draw->defs.append_c ('p'); - draw->defs.append_unsigned (def_id); - draw->defs.append_str ("\" d=\""); - unsigned data_offset = draw->defs.length; - draw->defs.append_len (draw->path.arrayZ, draw->path.length); - draw->defs.append_str ("\"/>\n"); - hb_vector_draw_t::path_entry_t entry; - entry.hash = h; - entry.defs_offset = data_offset; - entry.defs_length = draw->path.length; - entry.def_id = def_id; - draw->defined_paths.push (entry); - } - draw->path.clear (); - float xx = draw->transform.xx; float yx = draw->transform.yx; float xy = draw->transform.xy; @@ -597,41 +562,18 @@ hb_vector_draw_glyph_or_fail (hb_vector_draw_t *draw, float tx = draw->transform.x0; float ty = draw->transform.y0; - draw->body.append_str ("body.append_len (draw->id_prefix.arrayZ, draw->id_prefix.length); - draw->body.append_c ('p'); - draw->body.append_unsigned (def_id); + draw->body.append_str ("body.append_len (draw->path.arrayZ, draw->path.length); draw->body.append_str ("\" transform=\""); hb_vector_svg_append_instance_transform (&draw->body, draw->get_precision (), draw->x_scale_factor, draw->y_scale_factor, xx, yx, xy, yy, tx, ty); - draw->body.append_str ("\""); - /* Per-glyph fill from current foreground. */ - { - unsigned r = hb_color_get_red (draw->foreground); - unsigned g = hb_color_get_green (draw->foreground); - unsigned b = hb_color_get_blue (draw->foreground); - unsigned a = hb_color_get_alpha (draw->foreground); - if (r || g || b || a != 255) - { - draw->body.append_str (" fill=\"rgb("); - draw->body.append_unsigned (r); - draw->body.append_c (','); - draw->body.append_unsigned (g); - draw->body.append_c (','); - draw->body.append_unsigned (b); - draw->body.append_str (")\""); - if (a < 255) - { - draw->body.append_str (" fill-opacity=\""); - draw->body.append_num (a / 255.f, 4); - draw->body.append_c ('"'); - } - } - } - draw->body.append_str ("/>\n"); + draw->body.append_str ("\" fill=\""); + draw->body.append_svg_color (draw->foreground, true); + draw->body.append_str ("\"/>\n"); + draw->path.clear (); return true; } @@ -661,49 +603,6 @@ hb_vector_draw_glyph (hb_vector_draw_t *draw, hb_vector_draw_glyph_or_fail (draw, font, glyph, extents_mode); } -/** - * hb_vector_draw_set_svg_prefix: - * @draw: a draw context. - * @prefix: a null-terminated ASCII string to prepend to every emitted - * SVG `id` and `url(#...)` reference, or `NULL` for none. - * - * Namespaces the draw's SVG output. Callers that inject multiple - * hb-vector SVGs into the same document must set a distinct prefix - * per context so that the short IDs hb-vector uses for shared glyph - * outlines don't collide in the DOM. - * - * No effect on PDF output. - * - * XSince: REPLACEME - */ -void -hb_vector_draw_set_svg_prefix (hb_vector_draw_t *draw, - const char *prefix) -{ - draw->id_prefix.resize (0); - if (prefix) - draw->id_prefix.append_str (prefix); -} - -/** - * hb_vector_draw_get_svg_prefix: - * @draw: a draw context. - * - * Returns the SVG id prefix previously set on @draw, or `""` if - * none was set. - * - * Return value: the SVG id prefix. - * - * XSince: REPLACEME - */ -const char * -hb_vector_draw_get_svg_prefix (const hb_vector_draw_t *draw) -{ - if (!draw->id_prefix.length) return ""; - const_cast (draw->id_prefix).alloc (draw->id_prefix.length + 1, false); - draw->id_prefix.arrayZ[draw->id_prefix.length] = '\0'; - return draw->id_prefix.arrayZ; -} /** * hb_vector_draw_set_precision: @@ -1037,8 +936,6 @@ hb_vector_draw_clear (hb_vector_draw_t *draw) draw->defs.clear (); draw->body.clear (); draw->path.clear (); - draw->defined_paths.clear (); - draw->path_def_count = 0; } /** diff --git a/src/hb-vector-draw.hh b/src/hb-vector-draw.hh index 5ccf81813..7d5f0dda5 100644 --- a/src/hb-vector-draw.hh +++ b/src/hb-vector-draw.hh @@ -21,7 +21,6 @@ struct hb_vector_draw_t bool has_extents = false; hb_color_t foreground = HB_COLOR (0, 0, 0, 255); hb_color_t background = HB_COLOR (0, 0, 0, 0); - hb_vector_buf_t id_prefix; hb_vector_buf_t defs; hb_vector_buf_t body; @@ -38,15 +37,6 @@ struct hb_vector_draw_t } unsigned get_precision () const { return path.precision; } - struct path_entry_t - { - uint32_t hash; - unsigned defs_offset; - unsigned defs_length; - unsigned def_id; - }; - hb_vector_t defined_paths; - unsigned path_def_count = 0; hb_blob_t *recycled_blob = nullptr; void flush_path () diff --git a/src/hb-vector.h b/src/hb-vector.h index 4e2b1e2ae..70f584f35 100644 --- a/src/hb-vector.h +++ b/src/hb-vector.h @@ -190,13 +190,6 @@ hb_vector_draw_set_background (hb_vector_draw_t *draw, HB_EXTERN hb_color_t hb_vector_draw_get_background (const hb_vector_draw_t *draw); -HB_EXTERN void -hb_vector_draw_set_svg_prefix (hb_vector_draw_t *draw, - const char *prefix); - -HB_EXTERN const char * -hb_vector_draw_get_svg_prefix (const hb_vector_draw_t *draw); - HB_EXTERN hb_blob_t * hb_vector_draw_render (hb_vector_draw_t *draw); diff --git a/test/vector/data/expected/basic/cff1.svg b/test/vector/data/expected/basic/cff1.svg index e16414b9f..be4131b42 100644 --- a/test/vector/data/expected/basic/cff1.svg +++ b/test/vector/data/expected/basic/cff1.svg @@ -1,11 +1,6 @@ - - - - - - - - + + + diff --git a/test/vector/data/expected/basic/cff2-var-cntr.svg b/test/vector/data/expected/basic/cff2-var-cntr.svg index 10e0e89d4..197ca6844 100644 --- a/test/vector/data/expected/basic/cff2-var-cntr.svg +++ b/test/vector/data/expected/basic/cff2-var-cntr.svg @@ -1,11 +1,6 @@ - - - - - - - - + + + diff --git a/test/vector/data/expected/basic/cff2-var-wght900.svg b/test/vector/data/expected/basic/cff2-var-wght900.svg index 65dd45784..4e2cd00bd 100644 --- a/test/vector/data/expected/basic/cff2-var-wght900.svg +++ b/test/vector/data/expected/basic/cff2-var-wght900.svg @@ -1,9 +1,6 @@ - - - - - - + + + diff --git a/test/vector/data/expected/basic/default.svg b/test/vector/data/expected/basic/default.svg index 57508cd37..7da5392cc 100644 --- a/test/vector/data/expected/basic/default.svg +++ b/test/vector/data/expected/basic/default.svg @@ -1,11 +1,6 @@ - - - - - - - - + + + diff --git a/test/vector/data/expected/basic/glyf-var-wght900.svg b/test/vector/data/expected/basic/glyf-var-wght900.svg index ca10fd1f7..1bdb94536 100644 --- a/test/vector/data/expected/basic/glyf-var-wght900.svg +++ b/test/vector/data/expected/basic/glyf-var-wght900.svg @@ -1,11 +1,6 @@ - - - - - - - - + + + diff --git a/test/vector/data/expected/basic/glyf-vvar-ttb-wght900.svg b/test/vector/data/expected/basic/glyf-vvar-ttb-wght900.svg index 8eba4a832..8d04b20a6 100644 --- a/test/vector/data/expected/basic/glyf-vvar-ttb-wght900.svg +++ b/test/vector/data/expected/basic/glyf-vvar-ttb-wght900.svg @@ -1,11 +1,6 @@ - - - - - - - - + + + diff --git a/test/vector/data/expected/basic/iran-nastaliq-y-offsets.svg b/test/vector/data/expected/basic/iran-nastaliq-y-offsets.svg index 51abc9059..4c1c05f68 100644 --- a/test/vector/data/expected/basic/iran-nastaliq-y-offsets.svg +++ b/test/vector/data/expected/basic/iran-nastaliq-y-offsets.svg @@ -1,19 +1,10 @@ - - - - - - - - - - - - - - - - + + + + + + + diff --git a/test/vector/data/expected/basic/multiline.svg b/test/vector/data/expected/basic/multiline.svg index 77991bc44..30aade0d2 100644 --- a/test/vector/data/expected/basic/multiline.svg +++ b/test/vector/data/expected/basic/multiline.svg @@ -1,11 +1,6 @@ - - - - - - - - + + + diff --git a/test/vector/data/expected/basic/ttb.svg b/test/vector/data/expected/basic/ttb.svg index 8fee1a62a..faa56b403 100644 --- a/test/vector/data/expected/basic/ttb.svg +++ b/test/vector/data/expected/basic/ttb.svg @@ -1,11 +1,6 @@ - - - - - - - - + + + diff --git a/test/vector/data/expected/basic/upem-default.svg b/test/vector/data/expected/basic/upem-default.svg index 57508cd37..7da5392cc 100644 --- a/test/vector/data/expected/basic/upem-default.svg +++ b/test/vector/data/expected/basic/upem-default.svg @@ -1,11 +1,6 @@ - - - - - - - - + + + diff --git a/test/vector/data/expected/varc/conditional-default.svg b/test/vector/data/expected/varc/conditional-default.svg index 971950e2f..fcf59132c 100644 --- a/test/vector/data/expected/varc/conditional-default.svg +++ b/test/vector/data/expected/varc/conditional-default.svg @@ -1,7 +1,4 @@ - - - - + diff --git a/test/vector/data/expected/varc/conditional-wght840p3.svg b/test/vector/data/expected/varc/conditional-wght840p3.svg index ec8e37652..69b040a6f 100644 --- a/test/vector/data/expected/varc/conditional-wght840p3.svg +++ b/test/vector/data/expected/varc/conditional-wght840p3.svg @@ -1,7 +1,4 @@ - - - - + diff --git a/test/vector/data/expected/varc/default.svg b/test/vector/data/expected/varc/default.svg index 25cca1283..7a81c91a5 100644 --- a/test/vector/data/expected/varc/default.svg +++ b/test/vector/data/expected/varc/default.svg @@ -1,9 +1,5 @@ - - - - - - + + diff --git a/test/vector/data/expected/varc/wght840p3.svg b/test/vector/data/expected/varc/wght840p3.svg index e7466ae31..f0e6beb74 100644 --- a/test/vector/data/expected/varc/wght840p3.svg +++ b/test/vector/data/expected/varc/wght840p3.svg @@ -1,9 +1,5 @@ - - - - - - + +