[seed] cairo: Implement Cairo PDF surfaces
- From: Robert Carr <racarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [seed] cairo: Implement Cairo PDF surfaces
- Date: Wed, 20 May 2009 17:31:13 -0400 (EDT)
commit c3cc2cb4a0cc924c13db59194b94c7b3999d7bde
Author: Robert Carr <racarr svn gnome org>
Date: Wed May 20 17:31:07 2009 -0400
cairo: Implement Cairo PDF surfaces
---
modules/cairo/Makefile.am | 1 +
modules/cairo/seed-cairo-pdf-surface.c | 120 ++++++++++++++++++++++++++++++++
modules/cairo/seed-cairo-pdf-surface.h | 9 +++
modules/cairo/seed-cairo-surface.c | 2 +
modules/cairo/seed-cairo.c | 6 +-
5 files changed, 135 insertions(+), 3 deletions(-)
diff --git a/modules/cairo/Makefile.am b/modules/cairo/Makefile.am
index 7f0315a..c554d6a 100644
--- a/modules/cairo/Makefile.am
+++ b/modules/cairo/Makefile.am
@@ -10,6 +10,7 @@ libcairo_la_SOURCES = \
seed-cairo.c \
seed-cairo-surface.c \
seed-cairo-image-surface.c \
+ seed-cairo-pdf-surface.c \
seed-cairo-matrix.c \
seed-cairo-pattern.c \
seed-cairo-enums.c
diff --git a/modules/cairo/seed-cairo-pdf-surface.c b/modules/cairo/seed-cairo-pdf-surface.c
new file mode 100644
index 0000000..15c49e3
--- /dev/null
+++ b/modules/cairo/seed-cairo-pdf-surface.c
@@ -0,0 +1,120 @@
+#include <seed.h>
+#include <cairo/cairo.h>
+#include <cairo/cairo-pdf.h>
+
+#include "seed-cairo.h"
+#include "seed-cairo-surface.h"
+
+#define CAIRO_SURFACE_PRIV(obj) ((cairo_surface_t *)seed_object_get_private(obj))
+
+#define CHECK_SURFACE(obj) ({ \
+ if (!seed_object_is_of_class (ctx, obj, seed_cairo_pdf_surface_class)){ \
+ seed_make_exception (ctx, exception, "ArgumentError", "Object is not a Cairo Surface"); \
+ return seed_make_undefined (ctx); \
+ } \
+ if (!seed_object_get_private (obj)){ \
+ seed_make_exception (ctx, exception, "ArgumentError", "Cairo surface has been destroyed"); \
+ return seed_make_undefined (ctx);}})
+
+#define CHECK_THIS() if (!seed_object_get_private (this_object)){ \
+ seed_make_exception (ctx, exception, "ArgumentError", "Cairo surface has been destroyed"); \
+ return seed_make_undefined (ctx);}
+
+SeedClass seed_cairo_pdf_surface_class;
+SeedObject pdf_surface_constructor_ref;
+
+
+static SeedObject
+seed_object_from_cairo_pdf_surface (SeedContext ctx, cairo_surface_t *surf)
+{
+ SeedObject jsobj;
+
+ jsobj = cairo_surface_get_user_data (surf, seed_get_cairo_key());
+ if (jsobj)
+ return jsobj;
+
+ jsobj = seed_make_object (ctx, seed_cairo_pdf_surface_class, surf);
+ cairo_surface_set_user_data (surf, seed_get_cairo_key(), jsobj, seed_cairo_destroy_func);
+ return jsobj;
+}
+
+static SeedValue
+seed_cairo_pdf_surface_set_size (SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException *exception)
+{
+ cairo_surface_t *surf;
+ gdouble x, y;
+
+ CHECK_THIS();
+ if (argument_count != 2)
+ {
+ EXPECTED_EXCEPTION("set_size", "2 arguments");
+ }
+ surf = seed_object_get_private (this_object);
+ x = seed_value_to_double (ctx, arguments[0], exception);
+ y = seed_value_to_double (ctx, arguments[1], exception);
+
+ cairo_pdf_surface_set_size (surf, x, y);
+
+ return seed_make_undefined (ctx);
+}
+
+
+static SeedObject
+seed_cairo_construct_pdf_surface (SeedContext ctx,
+ SeedObject constructor,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException * exception)
+{
+ cairo_surface_t *ret;
+ gchar *filename = NULL;
+ gdouble width, height;
+ if (argument_count != 3)
+ {
+ EXPECTED_EXCEPTION("PDFSurface", "3 arguments");
+ }
+
+ if (!seed_value_is_null (ctx, arguments[0]))
+ filename = seed_value_to_string (ctx, arguments[0], exception);
+ width = seed_value_to_double (ctx, arguments[1], exception);
+ height = seed_value_to_double (ctx, arguments[2], exception);
+ ret = cairo_pdf_surface_create (filename, width, height);
+
+ return seed_object_from_cairo_pdf_surface (ctx, ret);
+}
+
+seed_static_value pdf_surface_values[] = {
+ {0, 0, 0, 0}
+};
+
+seed_static_function pdf_surface_funcs[] = {
+ {"set_size", seed_cairo_pdf_surface_set_size, 0},
+ {0, 0, 0}
+};
+
+
+
+
+void
+seed_define_cairo_pdf_surface (SeedContext ctx,
+ SeedObject namespace_ref)
+{
+ seed_class_definition pdf_def = seed_empty_class;
+
+ pdf_def.class_name = "PDFSurface";
+ pdf_def.static_values = pdf_surface_values;
+ pdf_def.parent_class = seed_get_cairo_surface_class ();
+ pdf_def.static_functions = pdf_surface_funcs;
+ seed_cairo_pdf_surface_class = seed_create_class (&pdf_def);
+
+ pdf_surface_constructor_ref = seed_make_constructor (ctx,
+ NULL,
+ //seed_cairo_pdf_surface_class,
+ seed_cairo_construct_pdf_surface);
+ seed_object_set_property (ctx, namespace_ref, "PDFSurface", pdf_surface_constructor_ref);
+}
diff --git a/modules/cairo/seed-cairo-pdf-surface.h b/modules/cairo/seed-cairo-pdf-surface.h
new file mode 100644
index 0000000..6292513
--- /dev/null
+++ b/modules/cairo/seed-cairo-pdf-surface.h
@@ -0,0 +1,9 @@
+#ifndef _SEED_CAIRO_PDF_SURFACE
+#define _SEED_CAIRO_PDF_SURFACe
+
+#include <seed.h>
+#include <cairo/cairo.h>
+
+void seed_define_cairo_pdf_surface (SeedContext ctx, SeedObject namespace_ref);
+
+#endif
diff --git a/modules/cairo/seed-cairo-surface.c b/modules/cairo/seed-cairo-surface.c
index 5d1ce7c..cfafab1 100644
--- a/modules/cairo/seed-cairo-surface.c
+++ b/modules/cairo/seed-cairo-surface.c
@@ -3,6 +3,7 @@
#include "seed-cairo.h"
#include "seed-cairo-image-surface.h"
+#include "seed-cairo-pdf-surface.h"
#define CAIRO_SURFACE_PRIV(obj) ((cairo_surface_t *)seed_object_get_private(obj))
@@ -392,4 +393,5 @@ seed_define_cairo_surface (SeedContext ctx,
seed_cairo_surface_class = seed_create_class (&surface_def);
seed_define_cairo_image_surface (ctx, namespace_ref);
+ seed_define_cairo_pdf_surface (ctx, namespace_ref);
}
diff --git a/modules/cairo/seed-cairo.c b/modules/cairo/seed-cairo.c
index c60e9c6..d1c5a3b 100644
--- a/modules/cairo/seed-cairo.c
+++ b/modules/cairo/seed-cairo.c
@@ -868,7 +868,7 @@ seed_cairo_mask (SeedContext ctx,
if (argument_count == 3)
return seed_cairo_mask_surface (ctx, function, this_object, argument_count, arguments, exception);
cr = seed_object_get_private (this_object);
- pat = seed_object_to_cairo_pattern (ctx, arguments[0]);
+ pat = seed_object_to_cairo_pattern (ctx, arguments[0], exception);
if (!pat)
{
seed_make_exception (ctx, arguments[0], "ArgumentError", "First argument should be a cairo_pattern"
@@ -876,7 +876,7 @@ seed_cairo_mask (SeedContext ctx,
return seed_make_undefined (ctx);
}
cairo_mask (cr, pat);
- seed_make_undefined (ctx);
+ return seed_make_undefined (ctx);
}
static SeedValue
@@ -1743,7 +1743,7 @@ seed_static_function cairo_funcs[] = {
{"fill", seed_cairo_fill, 0},
{"fill_preserve", seed_cairo_fill_preserve, 0},
{"fill_extents", seed_cairo_fill_extents, 0},
- {"mask", seed_cairo_mask, 0}
+ {"mask", seed_cairo_mask, 0},
{"in_fill", seed_cairo_in_fill, 0},
{"paint", seed_cairo_paint, 0},
{"paint_with_alpha", seed_cairo_paint_with_alpha, 0},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]