mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-29 09:34:05 +01:00
[vector] Strip clip-glyph dedup in SVG paint
push_clip_glyph kept a hash + linear-scan cache of emitted clip paths to dedup repeated clip-glyph uses within a single COLRv1 paint tree. With paint contexts being one-glyph per use, the cache mostly churned; it also made hb_memcmp trip on sanitizer-null when an empty path matched an equally-empty existing entry (fuzzer-reached null-deref). Drop the cache: always emit a fresh <path> + <clipPath> pair per push_clip_glyph. Removes defined_paths / content_entry_t from the paint struct. Regenerate the two handwriting COLR expected SVGs whose clip-reuse now produces distinct path defs. Assisted-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e5c87cf042
commit
e134bb760e
5 files changed
+39
-68
No files matched your search
+17
-41
@@ -450,47 +450,23 @@ hb_vector_paint_push_clip_glyph (hb_paint_funcs_t *,
|
||||
hb_font_draw_glyph (font, glyph, hb_vector_svg_path_draw_funcs_get (), &sink);
|
||||
}
|
||||
|
||||
uint32_t h = hb_hash (hb_bytes_t (paint->path.arrayZ, paint->path.length));
|
||||
unsigned def_id = (unsigned) -1;
|
||||
for (auto &e : paint->defined_paths)
|
||||
{
|
||||
if (e.hash == h &&
|
||||
e.defs_length == paint->path.length &&
|
||||
0 == hb_memcmp (paint->defs.arrayZ + e.defs_offset,
|
||||
paint->path.arrayZ, paint->path.length))
|
||||
{
|
||||
def_id = e.def_id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (def_id == (unsigned) -1)
|
||||
{
|
||||
def_id = paint->path_def_count++;
|
||||
paint->defs.append_str ("<path id=\"");
|
||||
paint->defs.append_len (pfx, pfx_len);
|
||||
paint->defs.append_c ('p');
|
||||
paint->defs.append_unsigned (def_id);
|
||||
paint->defs.append_str ("\" d=\"");
|
||||
unsigned data_offset = paint->defs.length;
|
||||
paint->defs.append_len (paint->path.arrayZ, paint->path.length);
|
||||
paint->defs.append_str ("\"/>\n");
|
||||
paint->defs.append_str ("<clipPath id=\"");
|
||||
paint->defs.append_len (pfx, pfx_len);
|
||||
paint->defs.append_str ("clip-p");
|
||||
paint->defs.append_unsigned (def_id);
|
||||
paint->defs.append_str ("\"><use href=\"#");
|
||||
paint->defs.append_len (pfx, pfx_len);
|
||||
paint->defs.append_c ('p');
|
||||
paint->defs.append_unsigned (def_id);
|
||||
paint->defs.append_str ("\"/></clipPath>\n");
|
||||
|
||||
hb_vector_paint_t::content_entry_t entry;
|
||||
entry.hash = h;
|
||||
entry.defs_offset = data_offset;
|
||||
entry.defs_length = paint->path.length;
|
||||
entry.def_id = def_id;
|
||||
paint->defined_paths.push (entry);
|
||||
}
|
||||
unsigned def_id = paint->path_def_count++;
|
||||
paint->defs.append_str ("<path id=\"");
|
||||
paint->defs.append_len (pfx, pfx_len);
|
||||
paint->defs.append_c ('p');
|
||||
paint->defs.append_unsigned (def_id);
|
||||
paint->defs.append_str ("\" d=\"");
|
||||
paint->defs.append_len (paint->path.arrayZ, paint->path.length);
|
||||
paint->defs.append_str ("\"/>\n");
|
||||
paint->defs.append_str ("<clipPath id=\"");
|
||||
paint->defs.append_len (pfx, pfx_len);
|
||||
paint->defs.append_str ("clip-p");
|
||||
paint->defs.append_unsigned (def_id);
|
||||
paint->defs.append_str ("\"><use href=\"#");
|
||||
paint->defs.append_len (pfx, pfx_len);
|
||||
paint->defs.append_c ('p');
|
||||
paint->defs.append_unsigned (def_id);
|
||||
paint->defs.append_str ("\"/></clipPath>\n");
|
||||
|
||||
paint->current_body ().append_str ("<g clip-path=\"url(#");
|
||||
paint->current_body ().append_len (pfx, pfx_len);
|
||||
|
||||
@@ -746,7 +746,6 @@ hb_vector_paint_clear (hb_vector_paint_t *paint)
|
||||
paint->clip_path_counter = 0;
|
||||
paint->gradient_counter = 0;
|
||||
paint->color_glyph_depth = 0;
|
||||
paint->defined_paths.clear ();
|
||||
paint->path_def_count = 0;
|
||||
hb_set_clear (paint->active_color_glyphs);
|
||||
paint->color_stops_scratch.clear ();
|
||||
|
||||
@@ -41,14 +41,6 @@ struct hb_vector_paint_t
|
||||
hb_vector_path_sink_t clip_path_sink = {nullptr, 0, 1.f, 1.f};
|
||||
unsigned gradient_counter = 0;
|
||||
unsigned color_glyph_depth = 0;
|
||||
struct content_entry_t
|
||||
{
|
||||
uint32_t hash;
|
||||
unsigned defs_offset;
|
||||
unsigned defs_length;
|
||||
unsigned def_id;
|
||||
};
|
||||
hb_vector_t<content_entry_t> defined_paths;
|
||||
unsigned path_def_count = 0;
|
||||
hb_set_t *active_color_glyphs = nullptr;
|
||||
hb_vector_t<hb_color_stop_t> color_stops_scratch;
|
||||
|
||||
Reference in new issue
Block a user