diff --git a/src/context2d.cc b/src/context2d.cc index 47fc077..02f7f59 100644 --- a/src/context2d.cc +++ b/src/context2d.cc @@ -84,6 +84,8 @@ Context2d::Initialize(Handle target) { // Prototype Local proto = t->PrototypeTemplate(); + NODE_SET_PROTOTYPE_METHOD(t, "save", Save); + NODE_SET_PROTOTYPE_METHOD(t, "restore", Restore); NODE_SET_PROTOTYPE_METHOD(t, "fill", Fill); NODE_SET_PROTOTYPE_METHOD(t, "stroke", Stroke); NODE_SET_PROTOTYPE_METHOD(t, "fillRect", FillRect); @@ -306,6 +308,30 @@ Context2d::BezierCurveTo(const Arguments &args) { return Undefined(); } +/* + * Save state. + */ + +Handle +Context2d::Save(const Arguments &args) { + HandleScope scope; + Context2d *context = ObjectWrap::Unwrap(args.This()); + cairo_save(context->getContext()); + return Undefined(); +} + +/* + * Restore state. + */ + +Handle +Context2d::Restore(const Arguments &args) { + HandleScope scope; + Context2d *context = ObjectWrap::Unwrap(args.This()); + cairo_restore(context->getContext()); + return Undefined(); +} + /* * Creates a new subpath. */ diff --git a/src/context2d.h b/src/context2d.h index 973d80d..65aa269 100644 --- a/src/context2d.h +++ b/src/context2d.h @@ -21,6 +21,8 @@ class Context2d: public node::ObjectWrap { rgba_t stroke; static void Initialize(Handle target); static Handle New(const Arguments &args); + static Handle Save(const Arguments &args); + static Handle Restore(const Arguments &args); static Handle BeginPath(const Arguments &args); static Handle ClosePath(const Arguments &args); static Handle Fill(const Arguments &args);