From 8434394dc65edc194f43efeaef54704f3d6dfb48 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Wed, 29 Sep 2010 14:21:50 -0700 Subject: [PATCH] Added Canvas#rect() --- src/context2d.cc | 14 ++++++++++++++ src/context2d.h | 1 + test/canvas.test.js | 17 +++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/src/context2d.cc b/src/context2d.cc index 415d79e..47fc077 100644 --- a/src/context2d.cc +++ b/src/context2d.cc @@ -89,6 +89,7 @@ Context2d::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "fillRect", FillRect); NODE_SET_PROTOTYPE_METHOD(t, "strokeRect", StrokeRect); NODE_SET_PROTOTYPE_METHOD(t, "clearRect", ClearRect); + NODE_SET_PROTOTYPE_METHOD(t, "rect", Rect); NODE_SET_PROTOTYPE_METHOD(t, "moveTo", MoveTo); NODE_SET_PROTOTYPE_METHOD(t, "lineTo", LineTo); NODE_SET_PROTOTYPE_METHOD(t, "bezierCurveTo", BezierCurveTo); @@ -449,6 +450,19 @@ Context2d::ClearRect(const Arguments &args) { return Undefined(); } +/* + * Adds a rectangle subpath. + */ + +Handle +Context2d::Rect(const Arguments &args) { + HandleScope scope; + RECT_ARGS; + Context2d *context = ObjectWrap::Unwrap(args.This()); + cairo_rectangle(context->getContext(), x, y, width, height); + return Undefined(); +} + /* * Adds an arc at x, y with the given radis and start/end angles. */ diff --git a/src/context2d.h b/src/context2d.h index 8c33d53..973d80d 100644 --- a/src/context2d.h +++ b/src/context2d.h @@ -33,6 +33,7 @@ class Context2d: public node::ObjectWrap { static Handle FillRect(const Arguments &args); static Handle StrokeRect(const Arguments &args); static Handle ClearRect(const Arguments &args); + static Handle Rect(const Arguments &args); static Handle Arc(const Arguments &args); static Handle GetMiterLimit(Local prop, const AccessorInfo &info); static Handle GetLineCap(Local prop, const AccessorInfo &info); diff --git a/test/canvas.test.js b/test/canvas.test.js index f4f0177..cab1514 100644 --- a/test/canvas.test.js +++ b/test/canvas.test.js @@ -194,6 +194,23 @@ module.exports = { , 'fill with stroke failed'); }, + 'test Canvas#rect()': function(assert){ + var canvas = new Canvas(200, 200) + , ctx = canvas.getContext('2d') + , path = __dirname + '/rect.png'; + + ctx.rect(5,5,50,50); + ctx.strokeStyle = 'yellow'; + ctx.fill(); + ctx.stroke(); + + assertChecksum( + canvas + , path + , '2909bb99d128e3ea1ee839b73dc1a0ed' + , 'Canvas#rect() failed'); + }, + 'test Canvas#fillStyle=': function(assert){ var canvas = new Canvas(200, 200) , ctx = canvas.getContext('2d')