Browse Source

Merge branch 'clip'

v1.x
Tj Holowaychuk 14 years ago
parent
commit
a42f7013d4
  1. 18
      src/context2d.cc
  2. 1
      src/context2d.h
  3. 18
      test/canvas.test.js

18
src/context2d.cc

@ -80,6 +80,7 @@ Context2d::Initialize(Handle<Object> 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<Value>
Context2d::Clip(const Arguments &args) {
HandleScope scope;
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
cairo_t *ctx = context->getContext();
cairo_clip_preserve(ctx);
return Undefined();
}
/*
* Fill the path.
*/
Handle<Value>
@ -563,7 +577,7 @@ Context2d::Fill(const Arguments &args) {
}
/*
* Stroke the shape.
* Stroke the path.
*/
Handle<Value>

1
src/context2d.h

@ -33,6 +33,7 @@ class Context2d: public node::ObjectWrap {
static Handle<Value> ResetTransform(const Arguments &args);
static Handle<Value> BeginPath(const Arguments &args);
static Handle<Value> ClosePath(const Arguments &args);
static Handle<Value> Clip(const Arguments &args);
static Handle<Value> Fill(const Arguments &args);
static Handle<Value> Stroke(const Arguments &args);
static Handle<Value> SetSource(const Arguments &args);

18
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');
}
}
Loading…
Cancel
Save