diff --git a/src/Canvas.cc b/src/Canvas.cc index e0784e4..76d5363 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -6,6 +6,7 @@ // #include "Canvas.h" +#include "CanvasRenderingContext2d.h" #include "closure.h" #include #include @@ -81,7 +82,7 @@ Canvas::SetWidth(Local prop, Local val, const AccessorInfo &info) if (val->IsNumber()) { Canvas *canvas = ObjectWrap::Unwrap(info.This()); canvas->width = val->Uint32Value(); - canvas->resurface(); + canvas->resurface(info.This()); } } @@ -104,7 +105,7 @@ Canvas::SetHeight(Local prop, Local val, const AccessorInfo &info if (val->IsNumber()) { Canvas *canvas = ObjectWrap::Unwrap(info.This()); canvas->height = val->Uint32Value(); - canvas->resurface(); + canvas->resurface(info.This()); } } @@ -286,9 +287,19 @@ Canvas::~Canvas() { */ void -Canvas::resurface() { +Canvas::resurface(Handle canvas) { + HandleScope scope; + + // Re-surface cairo_surface_destroy(_surface); _surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); + + // Reset context + Local context = canvas->Get(String::New("context")); + Context2d *context2d = ObjectWrap::Unwrap(context->ToObject()); + cairo_t *prev = context2d->context(); + context2d->setContext(cairo_create(surface())); + cairo_destroy(prev); } /* diff --git a/src/Canvas.h b/src/Canvas.h index a82481e..54797a3 100644 --- a/src/Canvas.h +++ b/src/Canvas.h @@ -67,7 +67,7 @@ class Canvas: public node::ObjectWrap { inline uint8_t *data(){ return cairo_image_surface_get_data(_surface); } inline int stride(){ return cairo_image_surface_get_stride(_surface); } Canvas(int width, int height); - void resurface(); + void resurface(Handle canvas); private: ~Canvas(); diff --git a/src/CanvasRenderingContext2d.h b/src/CanvasRenderingContext2d.h index d73dd6f..7030c4e 100644 --- a/src/CanvasRenderingContext2d.h +++ b/src/CanvasRenderingContext2d.h @@ -45,6 +45,7 @@ class Context2d: public node::ObjectWrap { short stateno; canvas_state_t *states[CANVAS_MAX_STATES]; canvas_state_t *state; + Context2d(Canvas *canvas); static Persistent constructor; static void Initialize(Handle target); static Handle New(const Arguments &args); @@ -122,9 +123,6 @@ class Context2d: public node::ObjectWrap { void save(); void restore(); - protected: - Context2d(Canvas *canvas); - private: ~Context2d(); Canvas *_canvas;