From 179b0c44f0402db367cae98b3085419c8ca1ce0d Mon Sep 17 00:00:00 2001
From: Johan Dahlin <johan@gnome.org>
Date: Fri, 26 Mar 2010 18:20:31 -0300
Subject: [PATCH] [cairo] Make SVG/PDF/PS surfaces optional

The conditional compilation for SVG/PDF/PS surface support were
not quite working, make sure that the gjs_cairo_surface_from_XXX
are always available even if cairo doesn't support it so a nice
exception is raised when an application tries to use a surface
which isn't supported in either cairo or gjs.

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=614055
---
 modules/cairo-context.c     |    4 ++--
 modules/cairo-pdf-surface.c |   11 ++++++++++-
 modules/cairo-private.h     |    6 +++---
 modules/cairo-ps-surface.c  |   11 ++++++++++-
 modules/cairo-svg-surface.c |   11 ++++++++++-
 5 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/modules/cairo-context.c b/modules/cairo-context.c
index 49e86e5..aff594a 100644
--- a/modules/cairo-context.c
+++ b/modules/cairo-context.c
@@ -648,7 +648,7 @@ getTarget_func(JSContext *context,
     /* surface belongs to the context, so keep the reference */
     surface_wrapper = gjs_cairo_surface_from_surface(context, surface);
     if (!surface_wrapper) {
-        gjs_throw(context, "failed to create surface");
+        /* exception already set */
         return JS_FALSE;
     }
 
@@ -681,7 +681,7 @@ getGroupTarget_func(JSContext *context,
     /* surface belongs to the context, so keep the reference */
     surface_wrapper = gjs_cairo_surface_from_surface(context, surface);
     if (!surface_wrapper) {
-        gjs_throw(context, "failed to create surface");
+        /* exception already set */
         return JS_FALSE;
     }
 
diff --git a/modules/cairo-pdf-surface.c b/modules/cairo-pdf-surface.c
index 081c410..73df854 100644
--- a/modules/cairo-pdf-surface.c
+++ b/modules/cairo-pdf-surface.c
@@ -101,5 +101,14 @@ gjs_cairo_pdf_surface_from_surface(JSContext       *context,
 
     return object;
 }
-
+#else
+JSObject *
+gjs_cairo_pdf_surface_from_surface(JSContext       *context,
+                                   cairo_surface_t *surface)
+{
+    gjs_throw(context,
+        "could not create PDF surface, recompile cairo and gjs with "
+        "PDF support.");
+    return NULL;
+}
 #endif /* CAIRO_HAS_PDF_SURFACE */
diff --git a/modules/cairo-private.h b/modules/cairo-private.h
index 2474d8a..9d5948d 100644
--- a/modules/cairo-private.h
+++ b/modules/cairo-private.h
@@ -73,9 +73,9 @@ jsval            gjs_cairo_ps_surface_create_proto      (JSContext       *contex
                                                          JSObject        *module,
                                                          const char      *proto_name,
                                                          JSObject        *parent);
+#endif
 JSObject *       gjs_cairo_ps_surface_from_surface       (JSContext       *context,
                                                           cairo_surface_t *surface);
-#endif
 
 /* pdf surface */
 #ifdef CAIRO_HAS_PDF_SURFACE
@@ -83,9 +83,9 @@ jsval            gjs_cairo_pdf_surface_create_proto     (JSContext       *contex
                                                          JSObject        *module,
                                                          const char      *proto_name,
                                                          JSObject        *parent);
+#endif
 JSObject *       gjs_cairo_pdf_surface_from_surface     (JSContext       *context,
                                                          cairo_surface_t *surface);
-#endif
 
 /* svg surface */
 #ifdef CAIRO_HAS_SVG_SURFACE
@@ -93,9 +93,9 @@ jsval            gjs_cairo_svg_surface_create_proto     (JSContext       *contex
                                                          JSObject        *module,
                                                          const char      *proto_name,
                                                          JSObject        *parent);
+#endif
 JSObject *       gjs_cairo_svg_surface_from_surface     (JSContext       *context,
                                                          cairo_surface_t *surface);
-#endif
 
 /* pattern */
 jsval            gjs_cairo_pattern_create_proto         (JSContext       *context,
diff --git a/modules/cairo-ps-surface.c b/modules/cairo-ps-surface.c
index 87f6301..014ddab 100644
--- a/modules/cairo-ps-surface.c
+++ b/modules/cairo-ps-surface.c
@@ -110,5 +110,14 @@ gjs_cairo_ps_surface_from_surface(JSContext       *context,
 
     return object;
 }
-
+#else
+JSObject *
+gjs_cairo_ps_surface_from_surface(JSContext       *context,
+                                  cairo_surface_t *surface)
+{
+    gjs_throw(context,
+        "could not create PS surface, recompile cairo and gjs with "
+        "PS support.");
+    return NULL;
+}
 #endif /* CAIRO_HAS_PS_SURFACE */
diff --git a/modules/cairo-svg-surface.c b/modules/cairo-svg-surface.c
index 21365ca..9a96065 100644
--- a/modules/cairo-svg-surface.c
+++ b/modules/cairo-svg-surface.c
@@ -101,5 +101,14 @@ gjs_cairo_svg_surface_from_surface(JSContext       *context,
 
     return object;
 }
-
+#else
+JSObject *
+gjs_cairo_svg_surface_from_surface(JSContext       *context,
+                                   cairo_surface_t *surface)
+{
+    gjs_throw(context,
+        "could not create SVG surface, recompile cairo and gjs with "
+        "SVG support.");
+    return NULL;
+}
 #endif /* CAIRO_HAS_SVG_SURFACE */
-- 
1.6.6.1
