[cairo-commit] src/cairo-svg-surface.c
Emmanuel Pacaud
emmanuel at kemper.freedesktop.org
Thu May 4 09:07:00 PDT 2006
src/cairo-svg-surface.c | 34 +++++++++++++++++++---------------
1 files changed, 19 insertions(+), 15 deletions(-)
New commits:
diff-tree 135449ae03e74910c9ac359772d4ad790f6b7bed (from a428f11738a52ffabbde3925254278585a72aadb)
Author: Emmanuel Pacaud <emmanuel.pacaud at free.fr>
Date: Thu May 4 18:06:06 2006 +0200
SVG: Fix the previous fix for xlink namespace.
It seems libxml2 2.6.24 now requires a node using xlink
namespace to be linked to a node where it can find this
namespace.
diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index a692a7e..dcbdf5f 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -84,8 +84,6 @@ struct cairo_svg_document {
double x_dpi;
double y_dpi;
- xmlNsPtr xlink_ns;
-
xmlDocPtr xml_doc;
xmlNodePtr xml_node_defs;
xmlNodePtr xml_node_main;
@@ -403,7 +401,11 @@ _cairo_svg_surface_create_for_document (
_cairo_dtostr (buffer, sizeof buffer, height);
xmlSetProp (rect, CC2XML ("height"), C2XML (buffer));
- surface->xml_node = xmlNewNode (NULL, CC2XML ("g"));
+ /* Use of xlink namespace requires node to be linked to tree.
+ * So by default we link surface main node to document svg node.
+ * For surfaces that don't own document, their main node will be
+ * unlinked and freed in surface finish. */
+ surface->xml_node = xmlNewChild (document->xml_node_main, NULL, CC2XML ("g"), NULL);
surface->xml_root_node = surface->xml_node;
snprintf (buffer, sizeof buffer, "surface%d", surface->id);
@@ -468,17 +470,16 @@ _cairo_svg_surface_finish (void *abstrac
cairo_svg_document_t *document = surface->document;
if (document->owner == &surface->base) {
- xmlAddChild (document->xml_node_main, xmlCopyNode (surface->xml_root_node, 1));
status = _cairo_svg_document_finish (document);
- } else
+ } else {
+ /* See _cairo_svg_surface_create_for_document */
+ xmlUnlinkNode (surface->xml_root_node);
+ xmlFreeNode (surface->xml_root_node);
status = CAIRO_STATUS_SUCCESS;
+ }
_cairo_svg_document_destroy (document);
- xmlFreeNode (surface->xml_root_node);
- surface->xml_node = NULL;
- surface->xml_root_node = NULL;
-
return status;
}
@@ -648,7 +649,6 @@ emit_composite_image_pattern (xmlNodePtr
double *height,
cairo_bool_t is_pattern)
{
- cairo_svg_document_t *document = svg_surface->document;
cairo_surface_t *surface = pattern->surface;
cairo_image_surface_t *image;
cairo_status_t status;
@@ -671,7 +671,7 @@ emit_composite_image_pattern (xmlNodePtr
xmlSetProp (child, CC2XML ("width"), C2XML (buffer));
_cairo_dtostr (buffer, sizeof buffer, image->height);
xmlSetProp (child, CC2XML ("height"), C2XML (buffer));
- xmlSetNsProp (child, document->xlink_ns, CC2XML ("xlink:href"), C2XML (xmlBufferContent (image_buffer)));
+ xmlSetProp (child, CC2XML ("xlink:href"), C2XML (xmlBufferContent (image_buffer)));
xmlBufferFree (image_buffer);
@@ -771,8 +771,8 @@ emit_composite_meta_pattern (xmlNodePtr
child = xmlNewChild (node, NULL, CC2XML("use"), NULL);
snprintf (buffer, sizeof buffer, "#surface%d", id);
- xmlSetNsProp (child, document->xlink_ns, CC2XML ("xlink:href"), C2XML (buffer));
-
+ xmlSetProp (child, CC2XML ("xlink:href"), C2XML (buffer));
+
if (!is_pattern) {
p2u = pattern->base.matrix;
cairo_matrix_invert (&p2u);
@@ -1364,13 +1364,17 @@ _cairo_svg_surface_mask (void *abst
emit_alpha_filter (document);
- mask_node = xmlNewNode (NULL, CC2XML ("mask"));
+ mask_node = xmlNewChild (document->xml_node_defs, NULL, CC2XML ("mask"), NULL);
snprintf (buffer, sizeof buffer, "mask%d", document->mask_id);
xmlSetProp (mask_node, CC2XML ("id"), C2XML (buffer));
child = xmlNewChild (mask_node, NULL, CC2XML ("g"), NULL);
xmlSetProp (child, CC2XML ("filter"), CC2XML ("url(#alpha)"));
emit_paint (child, surface, op, mask);
+ /* mask node need to be located after surface it references,
+ * but also needs to be linked to xml tree for xlink namespace.
+ * So we unlink readd it here. */
+ xmlUnlinkNode (mask_node);
xmlAddChild (document->xml_node_defs, mask_node);
child = emit_paint (surface->xml_node, surface, op, source);
@@ -1696,7 +1700,7 @@ _cairo_svg_document_create (cairo_output
xmlBufferFree (xml_buffer);
xmlNewNs (node, CC2XML ("http://www.w3.org/2000/svg"), NULL);
- document->xlink_ns = xmlNewNs (node, CC2XML ("http://www.w3.org/1999/xlink"), CC2XML ("xlink"));
+ xmlNewNs (node, CC2XML ("http://www.w3.org/1999/xlink"), CC2XML ("xlink"));
document->alpha_filter = FALSE;
More information about the cairo-commit
mailing list