[cairo-commit] 3 commits - src/cairo-svg-surface.c

Emmanuel Pacaud emmanuel at kemper.freedesktop.org
Sun Mar 12 10:35:31 PST 2006


 src/cairo-svg-surface.c |   53 ++++++++++++++++++++++++++++++++++--------------
 1 files changed, 38 insertions(+), 15 deletions(-)

New commits:
diff-tree 118f71b43870551db520ad56234c650aa4b61296 (from parents)
Merge: 66599911e0664afd145975e3afb0f580e6d1bb3c 92e09ee72fdde9059300b2b63d87e2bbd4286605
Author: Emmanuel Pacaud <emmanuel.pacaud at free.fr>
Date:   Sun Mar 12 19:30:29 2006 +0100

    Merge branch 'master' of git+ssh://emmanuel@git.cairographics.org/git/cairo

diff-tree 66599911e0664afd145975e3afb0f580e6d1bb3c (from 7563a23921a4d6f9f826a13b42d61f3ba3c31c10)
Author: Emmanuel Pacaud <emmanuel.pacaud at free.fr>
Date:   Thu Mar 9 22:09:14 2006 +0100

    Don't duplicate unmodified SVG surfaces

diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index b5cee75..58faa32 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -91,6 +91,9 @@ struct cairo_svg_surface {
     xmlNodePtr  xml_root_node;
 
     unsigned int clip_level;
+
+    cairo_bool_t modified;
+    unsigned int previous_id;
 };
 
 static cairo_svg_document_t *
@@ -217,6 +220,9 @@ _cairo_svg_surface_create_for_document (
     xmlSetProp (surface->xml_node, CC2XML ("id"), C2XML (buffer));
     snprintf (buffer, sizeof buffer, "url(#clip%d)", clip_id);
     xmlSetProp (surface->xml_node, CC2XML ("clip-path"), C2XML (buffer));
+
+    surface->modified = TRUE;
+    surface->previous_id = surface->id;
     
     return &surface->base;
 }
@@ -459,10 +465,11 @@ emit_composite_svg_pattern (xmlNodePtr n
     xmlNodePtr child;
     char buffer[CAIRO_SVG_DTOSTR_BUFFER_LEN];
 
-    xmlAddChild (document->xml_node_defs, xmlCopyNode (surface->xml_root_node, 1));
+    if (surface->modified)
+	    xmlAddChild (document->xml_node_defs, xmlCopyNode (surface->xml_root_node, 1));
     
     child = xmlNewChild (node, NULL, CC2XML("use"), NULL);
-    snprintf (buffer, sizeof buffer, "#surface%d", surface->id);
+    snprintf (buffer, sizeof buffer, "#surface%d", surface->previous_id);
     xmlSetProp (child, CC2XML ("xlink:href"), C2XML (buffer));
 
     if (!is_pattern) {
@@ -476,9 +483,13 @@ emit_composite_svg_pattern (xmlNodePtr n
     if (height != NULL)
 	    *height = surface->height;
 
-    surface->id = document->surface_id++;
-    snprintf (buffer, sizeof buffer, "surface%d", surface->id);
-    xmlSetProp (surface->xml_root_node, CC2XML ("id"), C2XML (buffer));
+    if (surface->modified) {
+	    surface->modified = FALSE;
+	    surface->previous_id = surface->id;
+	    surface->id = document->surface_id++;
+	    snprintf (buffer, sizeof buffer, "surface%d", surface->id);
+	    xmlSetProp (surface->xml_root_node, CC2XML ("id"), C2XML (buffer));
+    }
 
     return child;
 }
@@ -925,6 +936,7 @@ _cairo_svg_surface_fill (void			*abstrac
     xmlBufferFree (info.path);
     xmlBufferFree (style);
 
+    surface->modified = TRUE;
     return status;
 }
 
@@ -987,8 +999,10 @@ _cairo_svg_surface_paint (void		    *abs
 			  cairo_pattern_t   *source)
 {
     cairo_svg_surface_t *surface = abstract_surface;
-    
+
     emit_paint (surface->xml_node, surface, op, source);
+    
+    surface->modified = TRUE;
     return CAIRO_STATUS_SUCCESS;
 }
 
@@ -1017,6 +1031,7 @@ _cairo_svg_surface_mask (void		    *abst
 
     document->mask_id++;
 
+    surface->modified = TRUE;
     return CAIRO_STATUS_SUCCESS;
 }
 
@@ -1122,6 +1137,7 @@ _cairo_svg_surface_stroke (void			*abstr
     xmlBufferFree (info.path);
     xmlBufferFree (style);
 
+    surface->modified = TRUE;
     return status;
 }
 
@@ -1133,6 +1149,7 @@ _cairo_svg_surface_show_glyphs (void			*
 				int			 num_glyphs,
 				cairo_scaled_font_t	*scaled_font)
 {
+    cairo_svg_surface_t *surface = abstract_surface;
     cairo_path_fixed_t path;
     cairo_status_t status;
 
@@ -1156,6 +1173,7 @@ _cairo_svg_surface_show_glyphs (void			*
 
     _cairo_path_fixed_fini (&path);
 
+    surface->modified = TRUE;
     return status;
 }
 
diff-tree 7563a23921a4d6f9f826a13b42d61f3ba3c31c10 (from 3333bba82d26a0b11961af3cb5c29c79a1a0d07b)
Author: Emmanuel Pacaud <emmanuel.pacaud at free.fr>
Date:   Sun Mar 5 23:49:38 2006 +0100

    Fix self-copy test

diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index 76e7c6a..b5cee75 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -88,6 +88,7 @@ struct cairo_svg_surface {
     cairo_svg_document_t *document;
 
     xmlNodePtr  xml_node;
+    xmlNodePtr  xml_root_node;
 
     unsigned int clip_level;
 };
@@ -209,10 +210,8 @@ _cairo_svg_surface_create_for_document (
     _cairo_dtostr (buffer, sizeof buffer, height);
     xmlSetProp (clip_rect, CC2XML ("height"), C2XML (buffer));
     
-    surface->xml_node = xmlNewChild (surface->id == 0 ? 
-				     document->xml_node_main : 
-				     document->xml_node_defs, 
-				     NULL, CC2XML ("g"), NULL);
+    surface->xml_node = xmlNewNode (NULL, CC2XML ("g"));
+    surface->xml_root_node = surface->xml_node;
 	
     snprintf (buffer, sizeof buffer, "surface%d", surface->id);
     xmlSetProp (surface->xml_node, CC2XML ("id"), C2XML (buffer));
@@ -240,14 +239,19 @@ _cairo_svg_surface_finish (void *abstrac
     cairo_status_t status;
     cairo_svg_surface_t *surface = abstract_surface;
     cairo_svg_document_t *document = surface->document;
+    
 
-    if (document->owner == &surface->base)
+    if (document->owner == &surface->base) {
+	xmlAddChild (document->xml_node_main, xmlCopyNode (surface->xml_root_node, 1));
 	status = _cairo_svg_document_finish (document);
-    else
+    } else
 	status = CAIRO_STATUS_SUCCESS;
 
     _cairo_svg_document_destroy (document);
 
+    xmlFreeNode (surface->xml_root_node);
+    surface->xml_node = NULL;
+
     return status;
 }
 
@@ -450,13 +454,12 @@ emit_composite_svg_pattern (xmlNodePtr n
 			    cairo_bool_t is_pattern)
 {
     cairo_svg_surface_t *surface = (cairo_svg_surface_t *) pattern->surface;
+    cairo_svg_document_t *document = surface->document;
     cairo_matrix_t p2u;
     xmlNodePtr child;
     char buffer[CAIRO_SVG_DTOSTR_BUFFER_LEN];
 
-    /* FIXME: self copy is not supported yet */
-    if (surface->id == 0)
-	return NULL;
+    xmlAddChild (document->xml_node_defs, xmlCopyNode (surface->xml_root_node, 1));
     
     child = xmlNewChild (node, NULL, CC2XML("use"), NULL);
     snprintf (buffer, sizeof buffer, "#surface%d", surface->id);
@@ -473,6 +476,10 @@ emit_composite_svg_pattern (xmlNodePtr n
     if (height != NULL)
 	    *height = surface->height;
 
+    surface->id = document->surface_id++;
+    snprintf (buffer, sizeof buffer, "surface%d", surface->id);
+    xmlSetProp (surface->xml_root_node, CC2XML ("id"), C2XML (buffer));
+
     return child;
 }
 
@@ -1167,10 +1174,8 @@ _cairo_svg_surface_intersect_clip_path (
     char buffer[CAIRO_SVG_DTOSTR_BUFFER_LEN];
 
     if (path == NULL) {
-	while (surface->clip_level > 0) {
-	    surface->xml_node = surface->xml_node->parent;
-	    surface->clip_level--;
-	}
+	surface->xml_node = surface->xml_root_node;
+	surface->clip_level = 0;
 	return CAIRO_STATUS_SUCCESS;
     }
 


More information about the cairo-commit mailing list