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

Benjamin Otte company at kemper.freedesktop.org
Sun Sep 28 08:12:16 PDT 2008


 src/cairo-svg-surface.c |   56 ++++++++++++++++++++++++++++++------------------
 1 file changed, 35 insertions(+), 21 deletions(-)

New commits:
commit 57851464f920d52444d19d25e78293fa0f40c5f9
Author: Benjamin Otte <otte at gnome.org>
Date:   Sun Sep 28 17:02:23 2008 +0200

    [SVG] make backend handle new operators gracefully
    
    Previously, the SVG backend would rash when new operators were added to
    cairo.h, now it returns UNSUPPORTED.
    Also unsupported operators can now be set as NULL, so image fallbacks can
    be used properly.
    Should use fallbacks instead of color-dodge for CAIRO_OPERATOR_STURATE?

diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index bedce5d..13a1261 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -766,6 +766,36 @@ _cairo_svg_document_emit_font_subsets (cairo_svg_document_t *document)
     return status;
 }
 
+char const *_cairo_svg_surface_operators[] = {
+    "clear",
+
+    "src", "src-over", "src-in",
+    "src-out", "src-atop",
+
+    "dst", "dst-over", "dst-in",
+    "dst-out", "dst-atop",
+
+    "xor", "plus",
+    "color-dodge", /* FIXME: saturate ? */
+};
+
+static cairo_bool_t cairo_svg_force_fallbacks = FALSE;
+
+static cairo_bool_t
+_cairo_svg_surface_analyze_operator (cairo_svg_surface_t   *surface,
+				      cairo_operator_t	     op)
+{
+    /* guard against newly added operators */
+    if (op >= ARRAY_LENGTH (_cairo_svg_surface_operators))
+	return CAIRO_INT_STATUS_UNSUPPORTED;
+
+    /* allow operators being NULL if they are unsupported */
+    if (_cairo_svg_surface_operators[op] == NULL)
+	return CAIRO_INT_STATUS_UNSUPPORTED;
+
+    return CAIRO_STATUS_SUCCESS;
+}
+
 static cairo_int_status_t
 _cairo_svg_surface_analyze_operation (cairo_svg_surface_t   *surface,
 				      cairo_operator_t	     op,
@@ -782,7 +812,7 @@ _cairo_svg_surface_analyze_operation (cairo_svg_surface_t   *surface,
 	return CAIRO_INT_STATUS_UNSUPPORTED;
 
     if (document->svg_version >= CAIRO_SVG_VERSION_1_2)
-	return CAIRO_STATUS_SUCCESS;
+	return _cairo_svg_surface_analyze_operator (surface, op);
 
     if (op == CAIRO_OPERATOR_OVER)
 	return CAIRO_STATUS_SUCCESS;
@@ -965,19 +995,6 @@ _cairo_surface_base64_encode (cairo_surface_t       *surface,
     return status;
 }
 
-char const *_cairo_svg_surface_operators[] = {
-    "clear",
-
-    "src", "src-over", "src-in",
-    "src-out", "src-atop",
-
-    "dst", "dst-over", "dst-in",
-    "dst-out", "dst-atop",
-
-    "xor", "plus",
-    "color-dodge", /* FIXME: saturate ? */
-};
-
 static void
 _cairo_svg_surface_emit_operator (cairo_output_stream_t *output,
 				  cairo_svg_surface_t   *surface,
commit fda80cc852a109fe60e3277a1847bc5c24f35d8e
Author: Benjamin Otte <otte at gnome.org>
Date:   Sun Sep 28 14:57:49 2008 +0200

    [SVG] use _cairo_operator_bounded_by_source()
    
    previously, the code was duplicating its functionality

diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index 3854f05..bedce5d 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -965,20 +965,17 @@ _cairo_surface_base64_encode (cairo_surface_t       *surface,
     return status;
 }
 
-static struct {
-    char const *str;
-    cairo_bool_t clip_to_self;
-} _cairo_svg_surface_operators[] = {
-    {"clear", TRUE},
+char const *_cairo_svg_surface_operators[] = {
+    "clear",
 
-    {"src", TRUE},	    {"src-over", FALSE},	    {"src-in", FALSE},
-    {"src-out", FALSE},	    {"src-atop", FALSE},
+    "src", "src-over", "src-in",
+    "src-out", "src-atop",
 
-    {"dst", FALSE},	    {"dst-over", FALSE},	    {"dst-in", FALSE},
-    {"dst-out", FALSE},	    {"dst-atop", FALSE},
+    "dst", "dst-over", "dst-in",
+    "dst-out", "dst-atop",
 
-    {"xor", FALSE},	    {"plus", FALSE},
-    {"color-dodge", FALSE}	/* FIXME: saturate ? */
+    "xor", "plus",
+    "color-dodge", /* FIXME: saturate ? */
 };
 
 static void
@@ -988,8 +985,8 @@ _cairo_svg_surface_emit_operator (cairo_output_stream_t *output,
 {
     if (surface->document->svg_version >= CAIRO_SVG_VERSION_1_2 &&
 	op != CAIRO_OPERATOR_OVER) {
-	_cairo_output_stream_printf (output, " comp-op=\"%s\"", _cairo_svg_surface_operators[op].str);
-	if (_cairo_svg_surface_operators[op].clip_to_self)
+	_cairo_output_stream_printf (output, " comp-op=\"%s\"", _cairo_svg_surface_operators[op]);
+	if (!_cairo_operator_bounded_by_source (op))
 	   _cairo_output_stream_printf (output, " clip-to-self=\"true\"");
     }
 }
@@ -1001,8 +998,8 @@ _cairo_svg_surface_emit_operator_for_style (cairo_output_stream_t *output,
 {
     if (surface->document->svg_version >= CAIRO_SVG_VERSION_1_2 &&
 	op != CAIRO_OPERATOR_OVER) {
-	_cairo_output_stream_printf (output, "comp-op:%s;", _cairo_svg_surface_operators[op].str);
-	if (_cairo_svg_surface_operators[op].clip_to_self)
+	_cairo_output_stream_printf (output, "comp-op:%s;", _cairo_svg_surface_operators[op]);
+	if (!_cairo_operator_bounded_by_source (op))
 	   _cairo_output_stream_printf (output, "clip-to-self:true;");
     }
 }


More information about the cairo-commit mailing list