[vector-svg] Streamline set_svg_prefix()

This commit is contained in:
Behdad Esfahbod authored and Khaled Hosny committed 2026-04-20 01:29:49 +02:00
1 parent 6ef43b340d
commit 74514fc7d6
3 files changed
+30 -20

No files matched your search

+10 -10
View File
@@ -440,8 +440,8 @@ hb_vector_paint_push_clip_glyph (hb_paint_funcs_t *,
if (unlikely (!paint->ensure_initialized ()))
return;
const char *pfx = paint->id_prefix.arrayZ;
unsigned pfx_len = paint->id_prefix.length;
const char *pfx = paint->id_prefix;
unsigned pfx_len = paint->id_prefix_length;
paint->path.clear ();
{
@@ -486,8 +486,8 @@ hb_vector_paint_push_clip_rectangle (hb_paint_funcs_t *,
if (unlikely (!paint->ensure_initialized ()))
return;
const char *pfx = paint->id_prefix.arrayZ;
unsigned pfx_len = paint->id_prefix.length;
const char *pfx = paint->id_prefix;
unsigned pfx_len = paint->id_prefix_length;
unsigned clip_id = paint->clip_rect_counter++;
paint->defs.append_str ("<clipPath id=\"");
paint->defs.append_len (pfx, pfx_len);
@@ -540,8 +540,8 @@ hb_vector_paint_push_clip_path_end (hb_paint_funcs_t *,
if (unlikely (!paint->ensure_initialized ()))
return;
const char *pfx = paint->id_prefix.arrayZ;
unsigned pfx_len = paint->id_prefix.length;
const char *pfx = paint->id_prefix;
unsigned pfx_len = paint->id_prefix_length;
unsigned clip_id = paint->clip_path_counter++;
/* The accumulated path is in font Y-up coords (the
@@ -667,8 +667,8 @@ hb_vector_paint_linear_gradient (hb_paint_funcs_t *,
float mn, mx;
hb_paint_normalize_color_line (stops.arrayZ, stops.length, &mn, &mx);
const char *pfx = paint->id_prefix.arrayZ;
unsigned pfx_len = paint->id_prefix.length;
const char *pfx = paint->id_prefix;
unsigned pfx_len = paint->id_prefix_length;
unsigned grad_id = paint->gradient_counter++;
/* Reduce COLR's 3-anchor (P0, P1, P2) to SVG's 2-point
@@ -735,8 +735,8 @@ hb_vector_paint_radial_gradient (hb_paint_funcs_t *,
float gy1 = y0 + mx * (y1 - y0);
float gr1 = r0 + mx * (r1 - r0);
const char *pfx = paint->id_prefix.arrayZ;
unsigned pfx_len = paint->id_prefix.length;
const char *pfx = paint->id_prefix;
unsigned pfx_len = paint->id_prefix_length;
unsigned grad_id = paint->gradient_counter++;
paint->defs.append_str ("<radialGradient id=\"");
+18 -9
View File
@@ -99,6 +99,7 @@ hb_vector_paint_destroy (hb_vector_paint_t *paint)
hb_vector_paint_pdf_free_resources (paint);
hb_blob_destroy (paint->recycled_blob);
hb_set_destroy (paint->active_color_glyphs);
hb_free (paint->id_prefix);
hb_object_actually_destroy (paint);
hb_free (paint);
}
@@ -645,9 +646,22 @@ void
hb_vector_paint_set_svg_prefix (hb_vector_paint_t *paint,
const char *prefix)
{
paint->id_prefix.resize (0);
if (prefix)
paint->id_prefix.append_str (prefix);
char *old = paint->id_prefix;
paint->id_prefix = nullptr;
paint->id_prefix_length = 0;
if (prefix && *prefix)
{
unsigned len = strlen (prefix);
char *copy = (char *) hb_malloc (len + 1);
if (likely (copy))
{
hb_memcpy (copy, prefix, len);
copy[len] = '\0';
paint->id_prefix = copy;
paint->id_prefix_length = len;
}
}
hb_free (old);
}
/**
@@ -666,12 +680,7 @@ hb_vector_paint_set_svg_prefix (hb_vector_paint_t *paint,
const char *
hb_vector_paint_get_svg_prefix (const hb_vector_paint_t *paint)
{
if (!paint->id_prefix.length) return "";
/* id_prefix is appended via append_str which does NOT
* NUL-terminate; ensure a trailing NUL. */
const_cast<hb_vector_buf_t &> (paint->id_prefix).alloc (paint->id_prefix.length + 1, false);
paint->id_prefix.arrayZ[paint->id_prefix.length] = '\0';
return paint->id_prefix.arrayZ;
return paint->id_prefix ? paint->id_prefix : "";
}
/**
+2 -1
View File
@@ -53,7 +53,8 @@ struct hb_vector_paint_t
hb_color_t background = HB_COLOR (0, 0, 0, 0);
int palette = 0;
hb_hashmap_t<unsigned, hb_color_t> custom_palette_colors;
hb_vector_buf_t id_prefix;
char *id_prefix = nullptr;
unsigned id_prefix_length = 0;
hb_vector_buf_t defs;
hb_vector_buf_t path;