[gjs: 5/45] [cairo] Add a PostScript surface



commit 02302488ea54d08fce2e7950b2fcdccdfd67f8b3
Author: Johan Dahlin <johan gnome org>
Date:   Tue Feb 23 09:39:54 2010 -0300

    [cairo] Add a PostScript surface

 Makefile-modules.am        |    1 +
 modules/cairo-private.h    |    6 +++
 modules/cairo-ps-surface.c |   91 ++++++++++++++++++++++++++++++++++++++++++++
 modules/cairo.c            |    7 +++
 4 files changed, 105 insertions(+), 0 deletions(-)
---
diff --git a/Makefile-modules.am b/Makefile-modules.am
index 0fd7300..1f8d550 100644
--- a/Makefile-modules.am
+++ b/Makefile-modules.am
@@ -89,6 +89,7 @@ cairoNative_la_SOURCES =		\
 	modules/cairo-context.c \
 	modules/cairo-surface.c \
 	modules/cairo-image-surface.c \
+	modules/cairo-ps-surface.c \
 	modules/cairo.c
 
 
diff --git a/modules/cairo-private.h b/modules/cairo-private.h
index 0157008..c7ca263 100644
--- a/modules/cairo-private.h
+++ b/modules/cairo-private.h
@@ -53,5 +53,11 @@ jsval gjs_cairo_image_surface_create_proto(JSContext *context, JSObject *module,
 void gjs_cairo_image_surface_init(JSContext *context, JSObject *obj);
 #endif
 
+/* postscript surface */
+#ifdef CAIRO_HAS_PS_SURFACE
+jsval gjs_cairo_ps_surface_create_proto(JSContext *context, JSObject *module,
+                                        const char *proto_name, JSObject *parent);
+#endif
+
 #endif /* __CAIRO_PRIVATE_H__ */
 
diff --git a/modules/cairo-ps-surface.c b/modules/cairo-ps-surface.c
new file mode 100644
index 0000000..13cc6eb
--- /dev/null
+++ b/modules/cairo-ps-surface.c
@@ -0,0 +1,91 @@
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+/* Copyright 2010 litl, LLC. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include <config.h>
+
+#include <gjs/gjs.h>
+#include <cairo.h>
+#include "cairo-private.h"
+
+#if CAIRO_HAS_PS_SURFACE
+#include <cairo-ps.h>
+
+GJS_DEFINE_PROTO("CairoPSSurface", gjs_cairo_ps_surface)
+
+static JSBool
+gjs_cairo_ps_surface_constructor(JSContext *context,
+                                 JSObject  *obj,
+                                 uintN      argc,
+                                 jsval     *argv,
+                                 jsval     *retval)
+{
+    char *filename;
+    double width, height;
+    cairo_surface_t *surface;
+    cairo_status_t status;
+
+    if (!gjs_check_constructing(context))
+        return JS_FALSE;
+
+    if (!gjs_parse_args(context, "PSSurface", "sff", argc, argv,
+                        "filename", &filename,
+                        "width", &width,
+                        "height", &height))
+        return JS_FALSE;
+
+    surface = cairo_ps_surface_create(filename, width, height);
+    status = cairo_surface_status(surface);
+    if (status != CAIRO_STATUS_SUCCESS) {
+        gjs_throw(context, "Failed to create cairo surface: %s",
+                  cairo_status_to_string(status));
+        return JS_FALSE;
+    }
+    gjs_cairo_surface_construct(context, obj, surface);
+
+    return JS_TRUE;
+}
+
+static void
+gjs_cairo_ps_surface_finalize(JSContext *context,
+                              JSObject  *obj)
+{
+    gjs_cairo_surface_finalize_surface(context, obj);
+}
+
+static JSPropertySpec gjs_cairo_ps_surface_proto_props[] = {
+    { NULL }
+};
+
+static JSFunctionSpec gjs_cairo_ps_surface_proto_funcs[] = {
+    // restrictToLevel
+    // getLevels
+    // levelToString
+    // setEPS
+    // getEPS
+    // setSize
+    // dscBeginSetup
+    // dscBeginPageSetup
+    // dscComment
+    { NULL }
+};
+
+#endif /* CAIRO_HAS_PS_SURFACE */
diff --git a/modules/cairo.c b/modules/cairo.c
index 513a237..b84ad2c 100644
--- a/modules/cairo.c
+++ b/modules/cairo.c
@@ -52,6 +52,13 @@ gjs_js_define_cairo_stuff(JSContext      *context,
     gjs_cairo_image_surface_init(context, JSVAL_TO_OBJECT(obj));
 #endif
 
+#if CAIRO_HAS_PS_SURFACE
+    obj = gjs_cairo_ps_surface_create_proto(context, module_obj,
+                                            "PSSurface", surface_proto);
+    if (obj == JSVAL_NULL)
+        return JS_FALSE;
+#endif
+
     return JS_TRUE;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]