[gjs] cairo: bind cairo_set_dash
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] cairo: bind cairo_set_dash
- Date: Fri, 10 Dec 2010 16:11:17 +0000 (UTC)
commit 1a699b86aa173ec275b5c3e24ddc6bff09c454ec
Author: Colin Walters <walters verbum org>
Date: Thu Nov 18 15:36:00 2010 -0500
cairo: bind cairo_set_dash
https://bugzilla.gnome.org/show_bug.cgi?id=633477
modules/cairo-context.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++-
test/js/testCairo.js | 1 +
2 files changed, 66 insertions(+), 1 deletions(-)
---
diff --git a/modules/cairo-context.c b/modules/cairo-context.c
index 188d285..7b9575f 100644
--- a/modules/cairo-context.c
+++ b/modules/cairo-context.c
@@ -535,6 +535,70 @@ maskSurface_func(JSContext *context,
}
static JSBool
+setDash_func(JSContext *context,
+ uintN argc,
+ jsval *vp)
+{
+ jsval *argv = JS_ARGV(context, vp);
+ JSObject *obj = JS_THIS_OBJECT(context, vp);
+ guint i;
+ cairo_t *cr;
+ JSObject *dashes;
+ double offset;
+ JSBool retval = JS_FALSE;
+ guint len;
+ GArray *dashes_c = NULL;
+
+ if (!gjs_parse_args(context, "setDash", "of", argc, argv,
+ "dashes", &dashes, "offset", &offset))
+ return JS_FALSE;
+
+ JS_AddObjectRoot(context, &dashes);
+
+ if (!JS_IsArrayObject(context, dashes)) {
+ gjs_throw(context, "dashes must be an array");
+ goto out;
+ }
+
+ if (!JS_GetArrayLength(context, dashes, &len)) {
+ gjs_throw(context, "Can't get length of dashes");
+ goto out;
+ }
+
+ dashes_c = g_array_sized_new (FALSE, FALSE, sizeof(double), len);
+ for (i = 0; i < len; ++i) {
+ jsval elem;
+ double b;
+
+ elem = JSVAL_VOID;
+ if (!JS_GetElement(context, dashes, i, &elem)) {
+ goto out;
+ }
+ if (elem == JSVAL_VOID)
+ continue;
+
+ if (!JS_ValueToNumber(context, elem, &b))
+ goto out;
+ if (b <= 0) {
+ gjs_throw(context, "Dash value must be positive");
+ goto out;
+ }
+
+ g_array_append_val(dashes_c, b);
+ }
+
+ cr = gjs_cairo_context_get_context(context, obj);
+ cairo_set_dash(cr, (double*)dashes_c->data, dashes_c->len, offset);
+ JS_SET_RVAL(context, vp, JSVAL_VOID);
+ retval = JS_TRUE;
+ out:
+ if (dashes_c != NULL)
+ g_array_free (dashes_c, TRUE);
+ JS_RemoveObjectRoot(context, &dashes);
+ return retval;
+}
+
+static JSBool
setSource_func(JSContext *context,
uintN argc,
jsval *vp)
@@ -854,7 +918,7 @@ static JSFunctionSpec gjs_cairo_context_proto_funcs[] = {
{ "scale", (JSNative)scale_func, 0, JSFUN_FAST_NATIVE },
{ "selectFontFace", (JSNative)selectFontFace_func, 0, JSFUN_FAST_NATIVE },
{ "setAntialias", (JSNative)setAntialias_func, 0, JSFUN_FAST_NATIVE },
- // setDash
+ { "setDash", (JSNative)setDash_func, 0, JSFUN_FAST_NATIVE },
// setFontFace
// setFontMatrix
// setFontOptions
diff --git a/test/js/testCairo.js b/test/js/testCairo.js
index 65837ed..6589179 100644
--- a/test/js/testCairo.js
+++ b/test/js/testCairo.js
@@ -112,6 +112,7 @@ function testContextMethods() {
cr.showText("foobar");
cr.moveTo(0, 0);
+ cr.setDash([1, 0.5], 1)
cr.lineTo(1, 0);
cr.lineTo(1, 1);
cr.lineTo(0, 1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]