diff --git a/src/context2d.cc b/src/context2d.cc index 9bafb90..db53ccf 100644 --- a/src/context2d.cc +++ b/src/context2d.cc @@ -80,6 +80,7 @@ Context2d::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "transform", Transform); NODE_SET_PROTOTYPE_METHOD(t, "resetTransform", ResetTransform); NODE_SET_PROTOTYPE_METHOD(t, "scale", Scale); + NODE_SET_PROTOTYPE_METHOD(t, "clip", Clip); NODE_SET_PROTOTYPE_METHOD(t, "fill", Fill); NODE_SET_PROTOTYPE_METHOD(t, "stroke", Stroke); NODE_SET_PROTOTYPE_METHOD(t, "fillRect", FillRect); @@ -549,7 +550,20 @@ Context2d::Scale(const Arguments &args) { } /* - * Fill the shape. + * Use path as clipping region. + */ + +Handle +Context2d::Clip(const Arguments &args) { + HandleScope scope; + Context2d *context = ObjectWrap::Unwrap(args.This()); + cairo_t *ctx = context->getContext(); + cairo_clip_preserve(ctx); + return Undefined(); +} + +/* + * Fill the path. */ Handle @@ -563,7 +577,7 @@ Context2d::Fill(const Arguments &args) { } /* - * Stroke the shape. + * Stroke the path. */ Handle diff --git a/src/context2d.h b/src/context2d.h index a242152..a61f452 100644 --- a/src/context2d.h +++ b/src/context2d.h @@ -33,6 +33,7 @@ class Context2d: public node::ObjectWrap { static Handle ResetTransform(const Arguments &args); static Handle BeginPath(const Arguments &args); static Handle ClosePath(const Arguments &args); + static Handle Clip(const Arguments &args); static Handle Fill(const Arguments &args); static Handle Stroke(const Arguments &args); static Handle SetSource(const Arguments &args); diff --git a/test/canvas.test.js b/test/canvas.test.js index 0804507..d234030 100644 --- a/test/canvas.test.js +++ b/test/canvas.test.js @@ -462,5 +462,23 @@ module.exports = { , '2ba95ccadd5c38949a5ea493dbc78e08' , 'Context2d invalid fillStyle did not retain previous value'); + }, + + 'test Context2d#clip()': function(assert){ + var canvas = new Canvas(200, 200) + , ctx = canvas.getContext('2d') + , path = __dirname + '/images/clip.png'; + + ctx.arc(50,50,50,0,Math.PI * 2); + ctx.stroke(); + ctx.clip(); + ctx.fillStyle = 'rgba(0,0,0,.5)'; + ctx.fillRect(0,0,100,100); + + assertChecksum( + canvas + , path + , '6199442d05718481ac5ccd034239f6f1' + , 'Context2d#clip() failed'); } } \ No newline at end of file