[gjs/cairo] [cairo] Add a write_to_png method to ImageSurface



commit d677913a855a9b10ebaad3987ddb8a7c00ed0f62
Author: Johan Dahlin <johan gnome org>
Date:   Wed Feb 17 21:13:54 2010 -0200

    [cairo] Add a write_to_png method to ImageSurface
    
    This is temporary, it will move to the base class when
    we sort out Surface inheritance.

 examples/cairo.js             |    3 ++-
 modules/cairo-image-surface.c |   25 +++++++++++++++++++++++++
 modules/cairo-private.h       |    4 ++--
 3 files changed, 29 insertions(+), 3 deletions(-)
---
diff --git a/examples/cairo.js b/examples/cairo.js
index 5fb6941..7b40971 100644
--- a/examples/cairo.js
+++ b/examples/cairo.js
@@ -2,4 +2,5 @@ const Cairo = imports.cairo;
 
 let imageSurface = new Cairo.ImageSurface(Cairo.Format.RGB24, 100, 100);
 let context = new Cairo.Context(imageSurface);
-print(context);
+
+imageSurface.write_to_png("test.png");
diff --git a/modules/cairo-image-surface.c b/modules/cairo-image-surface.c
index 99f2e86..db75cb5 100644
--- a/modules/cairo-image-surface.c
+++ b/modules/cairo-image-surface.c
@@ -107,6 +107,28 @@ cairo_image_surface_finalize(JSContext *context,
     g_slice_free(GjsCairoImageSurface, priv);
 }
 
+static JSBool
+write_to_png_func(JSContext *context,
+                  JSObject  *obj,
+                  uintN      argc,
+                  jsval     *argv,
+                  jsval     *retval)
+{
+    char *filename;
+    cairo_surface_t *surface;
+
+    if (!gjs_parse_args(context, "write_to_png", "s", argc, argv,
+                        "filename", &filename))
+        return JS_FALSE;
+
+    surface = gjs_cairo_image_surface_get_surface(context, obj);
+    if (!surface)
+        return JS_FALSE;
+    cairo_surface_write_to_png(surface, filename);
+    g_free(filename);
+    return JS_TRUE;
+}
+
 static struct JSClass gjs_js_cairo_image_surface_class = {
     "CairoImageSurface", /* means "new CairoContext()" works */
     JSCLASS_HAS_PRIVATE |
@@ -131,6 +153,9 @@ static JSPropertySpec gjs_js_cairo_image_surface_proto_props[] = {
 };
 
 static JSFunctionSpec gjs_js_cairo_image_surface_proto_funcs[] = {
+    // FIXME: belongs in the base class, but we put it here to
+    //        be able to bootstrap basic cairo functionallity first.
+    { "write_to_png", write_to_png_func, 0, 0 },
     { NULL }
 };
 
diff --git a/modules/cairo-private.h b/modules/cairo-private.h
index 0c2381f..050beac 100644
--- a/modules/cairo-private.h
+++ b/modules/cairo-private.h
@@ -25,8 +25,8 @@
 
 #include <cairo.h>
 
-JSBool gjs_js_define_cairo_stuff(JSContext      *context,
-                                 JSObject       *module_obj);
+JSBool gjs_js_define_cairo_stuff(JSContext *context,
+                                 JSObject  *module_obj);
 
 jsval gjs_cairo_context_create_proto(JSContext *context);
 jsval gjs_cairo_image_surface_create_proto(JSContext *context);



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