diff options
author | Emmanuel Pacaud <emmanuel.pacaud@free.fr> | 2007-05-08 09:11:57 +0200 |
---|---|---|
committer | Emmanuel Pacaud <emmanuel.pacaud@free.fr> | 2007-05-08 09:11:57 +0200 |
commit | 0d8a1540ec53ecc309a10e77ea7788fcd16d8345 (patch) | |
tree | 3f2e70b740786adda001303fc39bdb74fd937e1f | |
parent | 936c965777c867bd4de7fd2278335837cc24eb22 (diff) |
SVG: Don't clip SVG element, as clipping region is implicit.
That makes editing of produced SVG easier.
-rw-r--r-- | src/cairo-svg-surface-private.h | 1 | ||||
-rw-r--r-- | src/cairo-svg-surface.c | 53 |
2 files changed, 27 insertions, 27 deletions
diff --git a/src/cairo-svg-surface-private.h b/src/cairo-svg-surface-private.h index c2b2206b..e7cd4db8 100644 --- a/src/cairo-svg-surface-private.h +++ b/src/cairo-svg-surface-private.h @@ -64,6 +64,7 @@ typedef struct cairo_svg_surface { unsigned int clip_level; unsigned int base_clip; + cairo_bool_t is_base_clip_emitted; cairo_paginated_mode_t paginated_mode; diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c index e1230c3b..483440ff 100644 --- a/src/cairo-svg-surface.c +++ b/src/cairo-svg-surface.c @@ -79,7 +79,6 @@ static const char * _cairo_svg_internal_version_strings[CAIRO_SVG_VERSION_LAST] struct cairo_svg_page { unsigned int surface_id; - unsigned int clip_id; unsigned int clip_level; cairo_output_stream_t *xml_node; }; @@ -355,13 +354,7 @@ _cairo_svg_surface_create_for_document (cairo_svg_document_t *document, surface->id = document->surface_id++; surface->base_clip = document->clip_id++; - - _cairo_output_stream_printf (document->xml_node_defs, - "<clipPath id=\"clip%d\">\n" - " <rect width=\"%f\" height=\"%f\"/>\n" - "</clipPath>\n", - surface->base_clip, - width, height); + surface->is_base_clip_emitted = FALSE; surface->xml_node = _cairo_memory_stream_create (); _cairo_array_init (&surface->page_set, sizeof (cairo_svg_page_t)); @@ -415,7 +408,6 @@ _cairo_svg_surface_store_page (cairo_svg_surface_t *surface) cairo_svg_page_t page; page.surface_id = surface->id; - page.clip_id = surface->base_clip; page.clip_level = surface->clip_level; page.xml_node = surface->xml_node; @@ -959,7 +951,7 @@ _cairo_svg_surface_emit_meta_surface (cairo_svg_document_t *document, { cairo_status_t status; cairo_surface_t *paginated_surface; - cairo_surface_t *svg_surface; + cairo_svg_surface_t *svg_surface; cairo_meta_snapshot_t new_snapshot; cairo_array_t *page_set; @@ -986,7 +978,7 @@ _cairo_svg_surface_emit_meta_surface (cairo_svg_document_t *document, meta->content, meta->width_pixels, meta->height_pixels); - svg_surface = _cairo_paginated_surface_get_target (paginated_surface); + svg_surface = (cairo_svg_surface_t *) _cairo_paginated_surface_get_target (paginated_surface); cairo_surface_set_fallback_resolution (paginated_surface, document->owner->x_fallback_resolution, document->owner->y_fallback_resolution); @@ -1004,34 +996,45 @@ _cairo_svg_surface_emit_meta_surface (cairo_svg_document_t *document, } new_snapshot.meta = meta; - new_snapshot.id = ((cairo_svg_surface_t *) svg_surface)->id; + new_snapshot.id = svg_surface->id; status = _cairo_array_append (&document->meta_snapshots, &new_snapshot); if (status) { cairo_surface_destroy (&meta->base); return status; } + if (!svg_surface->is_base_clip_emitted) { + svg_surface->is_base_clip_emitted = TRUE; + _cairo_output_stream_printf (document->xml_node_defs, + "<clipPath id=\"clip%d\">\n" + " <rect width=\"%f\" height=\"%f\"/>\n" + "</clipPath>\n", + svg_surface->base_clip, + svg_surface->width, + svg_surface->height); + } + if (meta->content == CAIRO_CONTENT_ALPHA) { _cairo_svg_surface_emit_alpha_filter (document); _cairo_output_stream_printf (document->xml_node_defs, "<g id=\"surface%d\" " "clip-path=\"url(#clip%d)\" " "filter=\"url(#alpha)\">\n", - ((cairo_svg_surface_t *) svg_surface)->id, - ((cairo_svg_surface_t *) svg_surface)->base_clip); + svg_surface->id, + svg_surface->base_clip); } else { _cairo_output_stream_printf (document->xml_node_defs, "<g id=\"surface%d\" " "clip-path=\"url(#clip%d)\">\n", - ((cairo_svg_surface_t *) svg_surface)->id, - ((cairo_svg_surface_t *) svg_surface)->base_clip); + svg_surface->id, + svg_surface->base_clip); } - contents = ((cairo_svg_surface_t *) svg_surface)->xml_node; - page_set = &((cairo_svg_surface_t *) svg_surface)->page_set; + contents = svg_surface->xml_node; + page_set = &svg_surface->page_set; if (_cairo_memory_stream_length (contents) > 0) - _cairo_svg_surface_store_page ((cairo_svg_surface_t *) svg_surface); + _cairo_svg_surface_store_page (svg_surface); if (page_set->num_elements > 0) { cairo_svg_page_t *page; @@ -2157,10 +2160,8 @@ _cairo_svg_document_finish (cairo_svg_document_t *document) page = _cairo_array_index (&surface->page_set, i); _cairo_output_stream_printf (output, "<page>\n"); _cairo_output_stream_printf (output, - "<g id=\"surface%d\" " - "clip-path=\"url(#clip%d)\">\n", - page->surface_id, - page->clip_id); + "<g id=\"surface%d\">\n", + page->surface_id); _cairo_memory_stream_copy (page->xml_node, output); _cairo_output_stream_printf (output, "</g>\n</page>\n"); } @@ -2168,10 +2169,8 @@ _cairo_svg_document_finish (cairo_svg_document_t *document) } else if (surface->page_set.num_elements > 0) { page = _cairo_array_index (&surface->page_set, surface->page_set.num_elements - 1); _cairo_output_stream_printf (output, - "<g id=\"surface%d\" " - "clip-path=\"url(#clip%d)\">\n", - page->surface_id, - page->clip_id); + "<g id=\"surface%d\">\n", + page->surface_id); _cairo_memory_stream_copy (page->xml_node, output); _cairo_output_stream_printf (output, "</g>\n"); } |