[gjs/cairo: 16/18] [cairo] Add surface/pattern method to Context



commit 920ebe0a6b5d4ab91cfc2290b9f56ca5767ded60
Author: Johan Dahlin <johan gnome org>
Date:   Mon Feb 22 18:20:22 2010 -0300

    [cairo] Add surface/pattern method to Context

 modules/cairo-context.c |  122 +++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 118 insertions(+), 4 deletions(-)
---
diff --git a/modules/cairo-context.c b/modules/cairo-context.c
index 9476ef9..2efd555 100644
--- a/modules/cairo-context.c
+++ b/modules/cairo-context.c
@@ -299,6 +299,119 @@ _GJS_CAIRO_CONTEXT_DEFINE_FUNC1(showText, cairo_show_text, "s", const char*, utf
 _GJS_CAIRO_CONTEXT_DEFINE_FUNC0(stroke, cairo_stroke)
 _GJS_CAIRO_CONTEXT_DEFINE_FUNC0(strokePreserve, cairo_stroke_preserve)
 
+static JSBool
+mask_func(JSContext *context,
+          JSObject  *obj,
+          uintN      argc,
+          jsval     *argv,
+          jsval     *retval)
+{
+    JSObject *pattern_wrapper;
+    cairo_pattern_t *pattern;
+    cairo_t *cr;
+
+    if (!gjs_parse_args(context, "mask", "o", argc, argv,
+                        "pattern", &pattern_wrapper))
+        return JS_FALSE;
+
+    pattern = gjs_cairo_pattern_get_pattern(context, pattern_wrapper);
+    if (!pattern) {
+        gjs_throw(context, "first argument to mask() should be a pattern");
+        return JS_FALSE;
+    }
+
+    cr = gjs_cairo_context_get_cr(context, obj);
+    cairo_mask(cr, pattern);
+
+    return JS_TRUE;
+}
+
+static JSBool
+maskSurface_func(JSContext *context,
+                 JSObject  *obj,
+                 uintN      argc,
+                 jsval     *argv,
+                 jsval     *retval)
+{
+    JSObject *surface_wrapper;
+    double x, y;
+    cairo_surface_t *surface;
+    cairo_t *cr;
+
+    if (!gjs_parse_args(context, "maskSurface", "off", argc, argv,
+                        "surface", &surface_wrapper,
+                        "x", &x,
+                        "y", &y))
+        return JS_FALSE;
+
+    surface = gjs_cairo_surface_get_surface(context, surface_wrapper);
+    if (!surface) {
+        gjs_throw(context, "first argument to maskSurface() should be a surface");
+        return JS_FALSE;
+    }
+
+    cr = gjs_cairo_context_get_cr(context, obj);
+    cairo_mask_surface(cr, surface, x, y);
+
+    return JS_TRUE;
+}
+
+static JSBool
+setSource_func(JSContext *context,
+               JSObject  *obj,
+               uintN      argc,
+               jsval     *argv,
+               jsval     *retval)
+{
+    JSObject *pattern_wrapper;
+    cairo_pattern_t *pattern;
+    cairo_t *cr;
+
+    if (!gjs_parse_args(context, "setSource", "o", argc, argv,
+                        "pattern", &pattern_wrapper))
+        return JS_FALSE;
+
+    pattern = gjs_cairo_pattern_get_pattern(context, pattern_wrapper);
+    if (!pattern) {
+        gjs_throw(context, "first argument to setSource() should be a pattern");
+        return JS_FALSE;
+    }
+
+    cr = gjs_cairo_context_get_cr(context, obj);
+    cairo_set_source(cr, pattern);
+
+    return JS_TRUE;
+}
+static JSBool
+setSourceSurface_func(JSContext *context,
+                      JSObject  *obj,
+                      uintN      argc,
+                      jsval     *argv,
+                      jsval     *retval)
+{
+    JSObject *surface_wrapper;
+    double x, y;
+    cairo_surface_t *surface;
+    cairo_t *cr;
+
+    if (!gjs_parse_args(context, "setSourceSurface", "off", argc, argv,
+                        "surface", &surface_wrapper,
+                        "x", &x,
+                        "y", &y))
+        return JS_FALSE;
+
+    surface = gjs_cairo_surface_get_surface(context, surface_wrapper);
+    if (!surface) {
+        gjs_throw(context, "first argument to setSourceSurface() should be a surface");
+        return JS_FALSE;
+    }
+
+    cr = gjs_cairo_context_get_cr(context, obj);
+    cairo_set_source_surface(cr, surface, x, y);
+
+    return JS_TRUE;
+}
+
 static JSFunctionSpec gjs_cairo_context_proto_funcs[] = {
     // appendPath
     { "arc", arc_func, 0, 0 },
@@ -319,6 +432,7 @@ static JSFunctionSpec gjs_cairo_context_proto_funcs[] = {
     { "getAntiAlias", getAntiAlias_func, 0, 0 },
     // getCurrentPoint
     // getDash
+    // getDashCount
     { "getFillRule", getFillRule_func, 0, 0 },
     // getFontFace
     // getFontMatrix
@@ -341,8 +455,8 @@ static JSFunctionSpec gjs_cairo_context_proto_funcs[] = {
     // inFill
     // inStroke
     { "lineTo", lineTo_func, 0, 0 },
-    // mask
-    // maskSurface
+    { "mask", mask_func, 0, 0 },
+    { "maskSurface", maskSurface_func, 0, 0 },
     { "moveTo", moveTo_func, 0, 0 },
     { "newPath", newPath_func, 0, 0 },
     { "newSubPath", newSubPath_func, 0, 0 },
@@ -377,10 +491,10 @@ static JSFunctionSpec gjs_cairo_context_proto_funcs[] = {
     { "setMiterLimit", setMiterLimit_func, 0, 0 },
     { "setOperator", setOperator_func, 0, 0 },
     // setScaledFont
-    // setSource
+    { "setSource", setSource_func, 0, 0 },
     { "setSourceRGB", setSourceRGB_func, 0, 0 },
     { "setSourceRGBA", setSourceRGBA_func, 0, 0 },
-    // setSourceSurface
+    { "setSourceSurface", setSourceSurface_func, 0, 0 },
     { "setTolerance", setTolerance_func, 0, 0 },
     // showGlyphs
     { "showPage", showPage_func, 0, 0 },



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