From 6876138c5a30fbf0fedcde835f543f324d020624 Mon Sep 17 00:00:00 2001 From: Kwon-Young Choi Date: Tue, 3 May 2022 11:12:19 +0200 Subject: [PATCH 1/2] add glyph utf8 string as class attribute in svg export --- src/cairo-svg-surface.c | 51 ++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c index dfb72b2ad..1d8042558 100644 --- a/src/cairo-svg-surface.c +++ b/src/cairo-svg-surface.c @@ -3998,12 +3998,14 @@ _cairo_svg_surface_fill_stroke (void *abstract_surface, } static cairo_int_status_t -_cairo_svg_surface_show_glyphs_impl (cairo_svg_stream_t *output, - cairo_svg_surface_t *surface, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font) +_cairo_svg_surface_show_text_glyphs_impl (cairo_svg_stream_t *output, + cairo_svg_surface_t *surface, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + const char *utf8, + int utf8_len, + cairo_scaled_font_t *scaled_font) { cairo_status_t status; cairo_svg_document_t *document = surface->document; @@ -4048,12 +4050,16 @@ _cairo_svg_surface_show_glyphs_impl (cairo_svg_stream_t *output, if (unlikely (status)) { return status; } - + char * utf8_str = _cairo_malloc_ab(utf8_len + 1, sizeof(char)); + strncpy(utf8_str, utf8, utf8_len); + utf8_str[utf8_len] = '\0'; _cairo_svg_stream_printf (output, - "\n", + "\n", subset_glyph.font_id, subset_glyph.subset_glyph_index, - glyphs[i].x, glyphs[i].y); + glyphs[i].x, glyphs[i].y, + utf8_str); + free(utf8_str); } _cairo_svg_stream_printf (output, "\n"); @@ -4087,13 +4093,18 @@ _cairo_svg_surface_show_glyphs_impl (cairo_svg_stream_t *output, } static cairo_int_status_t -_cairo_svg_surface_show_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) +_cairo_svg_surface_show_text_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const char *utf8, + int utf8_len, + cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) { cairo_svg_surface_t *surface = abstract_surface; cairo_int_status_t status; @@ -4104,10 +4115,12 @@ _cairo_svg_surface_show_glyphs (void *abstract_surface, : CAIRO_INT_STATUS_UNSUPPORTED; } - _CAIRO_SVG_SURFACE_CALL_OPERATOR_IMPL (_cairo_svg_surface_show_glyphs_impl, + _CAIRO_SVG_SURFACE_CALL_OPERATOR_IMPL (_cairo_svg_surface_show_text_glyphs_impl, source, glyphs, num_glyphs, + utf8, + utf8_len, scaled_font) } @@ -4160,9 +4173,9 @@ static const cairo_surface_backend_t cairo_svg_surface_backend = { _cairo_svg_surface_stroke, _cairo_svg_surface_fill, _cairo_svg_surface_fill_stroke, - _cairo_svg_surface_show_glyphs, + NULL, /* show_glyphs */ NULL, /* has_show_text_glyphs */ - NULL, /* show_text_glyphs */ + _cairo_svg_surface_show_text_glyphs, _cairo_svg_surface_get_supported_mime_types, }; From 53dde33e204068a8a139c34853d8903a7dc22211 Mon Sep 17 00:00:00 2001 From: Kwon-Young Choi Date: Wed, 4 May 2022 08:33:33 +0200 Subject: [PATCH 2/2] malloc null check --- src/cairo-svg-surface.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c index 1d8042558..56edf8fab 100644 --- a/src/cairo-svg-surface.c +++ b/src/cairo-svg-surface.c @@ -4051,6 +4051,9 @@ _cairo_svg_surface_show_text_glyphs_impl (cairo_svg_stream_t *output, return status; } char * utf8_str = _cairo_malloc_ab(utf8_len + 1, sizeof(char)); + if (unlikely (utf8_str == NULL)) { + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } strncpy(utf8_str, utf8, utf8_len); utf8_str[utf8_len] = '\0'; _cairo_svg_stream_printf (output,