diff --git a/src/hb-vector-paint-svg.cc b/src/hb-vector-paint-svg.cc index 54b2c73aa..4e961cfca 100644 --- a/src/hb-vector-paint-svg.cc +++ b/src/hb-vector-paint-svg.cc @@ -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 ("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 ("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 (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 : ""; } /** diff --git a/src/hb-vector-paint.hh b/src/hb-vector-paint.hh index 255400184..53c297ef6 100644 --- a/src/hb-vector-paint.hh +++ b/src/hb-vector-paint.hh @@ -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 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;