From 7336835d3c5e0e779a61dc1e5dbfef4484416eaf Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Tue, 5 Oct 2010 15:11:47 -0700 Subject: [PATCH] Added setTransform(). Closes #15 --- lib/canvas.js | 5 +++++ src/context2d.cc | 15 ++++++++++++++- src/context2d.h | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/canvas.js b/lib/canvas.js index 0bb9c1a..91c1d05 100644 --- a/lib/canvas.js +++ b/lib/canvas.js @@ -146,6 +146,11 @@ Context2d.prototype.createRadialGradient = function(x0, y0, r0, x1, y1, r1){ return new CanvasGradient(x0, y0, r0, x1, y1, r1); }; +Context2d.prototype.setTransform = function(){ + this.resetTransform(); + return this.transform.apply(this, arguments); +}; + /** * Set the fill style with the given css color string. * diff --git a/src/context2d.cc b/src/context2d.cc index 37d5b9e..9bafb90 100644 --- a/src/context2d.cc +++ b/src/context2d.cc @@ -78,6 +78,7 @@ Context2d::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "rotate", Rotate); NODE_SET_PROTOTYPE_METHOD(t, "translate", Translate); 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, "fill", Fill); NODE_SET_PROTOTYPE_METHOD(t, "stroke", Stroke); @@ -485,7 +486,7 @@ Context2d::Rotate(const Arguments &args) { } /* - * Transform. + * Modify the CTM. */ Handle @@ -507,6 +508,18 @@ Context2d::Transform(const Arguments &args) { return Undefined(); } +/* + * Reset the CTM, used internally by setTransform(). + */ + +Handle +Context2d::ResetTransform(const Arguments &args) { + HandleScope scope; + Context2d *context = ObjectWrap::Unwrap(args.This()); + cairo_identity_matrix(context->getContext()); + return Undefined(); +} + /* * Translate transformation. */ diff --git a/src/context2d.h b/src/context2d.h index b348c9f..a242152 100644 --- a/src/context2d.h +++ b/src/context2d.h @@ -30,6 +30,7 @@ class Context2d: public node::ObjectWrap { static Handle Translate(const Arguments &args); static Handle Scale(const Arguments &args); static Handle Transform(const Arguments &args); + static Handle ResetTransform(const Arguments &args); static Handle BeginPath(const Arguments &args); static Handle ClosePath(const Arguments &args); static Handle Fill(const Arguments &args);