diff --git a/lib/context2d.js b/lib/context2d.js index 07fadaf..43fc6bf 100644 --- a/lib/context2d.js +++ b/lib/context2d.js @@ -138,6 +138,17 @@ Context2d.prototype.__defineSetter__('fillStyle', function(val){ } }); +/** + * Get previous fill style. + * + * @return {CanvasGradient|String} + * @api public + */ + +Context2d.prototype.__defineGetter__('fillStyle', function(){ + return this.lastFillStyle || this.fillColor; +}); + /** * Set the stroke style with the given css color string. * @@ -153,6 +164,18 @@ Context2d.prototype.__defineSetter__('strokeStyle', function(val){ } }); +/** + * Get previous stroke style. + * + * @return {CanvasGradient|String} + * @api public + */ + +Context2d.prototype.__defineGetter__('strokeStyle', function(){ + return this.lastStrokeStyle || this.strokeColor; +}); + + /** * Set font. * diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index 437893a..96850fb 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -97,6 +97,8 @@ Context2d::Initialize(Handle target) { proto->SetAccessor(String::NewSymbol("globalCompositeOperation"), GetGlobalCompositeOperation, SetGlobalCompositeOperation); proto->SetAccessor(String::NewSymbol("globalAlpha"), GetGlobalAlpha, SetGlobalAlpha); proto->SetAccessor(String::NewSymbol("shadowColor"), GetShadowColor, SetShadowColor); + proto->SetAccessor(String::NewSymbol("fillColor"), GetFillColor); + proto->SetAccessor(String::NewSymbol("strokeColor"), GetStrokeColor); proto->SetAccessor(String::NewSymbol("miterLimit"), GetMiterLimit, SetMiterLimit); proto->SetAccessor(String::NewSymbol("lineWidth"), GetLineWidth, SetLineWidth); proto->SetAccessor(String::NewSymbol("lineCap"), GetLineCap, SetLineCap); @@ -1033,6 +1035,18 @@ Context2d::SetFillColor(const Arguments &args) { return Undefined(); } +/* + * Get fill color. + */ + +Handle +Context2d::GetFillColor(Local prop, const AccessorInfo &info) { + char buf[64]; + Context2d *context = ObjectWrap::Unwrap(info.This()); + rgba_to_string(context->state->fill, buf); + return String::New(buf); +} + /* * Set stroke color, used internally for strokeStyle= */ @@ -1051,6 +1065,18 @@ Context2d::SetStrokeColor(const Arguments &args) { return Undefined(); } +/* + * Get stroke color. + */ + +Handle +Context2d::GetStrokeColor(Local prop, const AccessorInfo &info) { + char buf[64]; + Context2d *context = ObjectWrap::Unwrap(info.This()); + rgba_to_string(context->state->stroke, buf); + return String::New(buf); +} + /* * Bezier curve. */ diff --git a/src/CanvasRenderingContext2d.h b/src/CanvasRenderingContext2d.h index 6fbef7e..32e88d2 100644 --- a/src/CanvasRenderingContext2d.h +++ b/src/CanvasRenderingContext2d.h @@ -80,6 +80,8 @@ class Context2d: public node::ObjectWrap { static Handle GetGlobalCompositeOperation(Local prop, const AccessorInfo &info); static Handle GetGlobalAlpha(Local prop, const AccessorInfo &info); static Handle GetShadowColor(Local prop, const AccessorInfo &info); + static Handle GetFillColor(Local prop, const AccessorInfo &info); + static Handle GetStrokeColor(Local prop, const AccessorInfo &info); static Handle GetMiterLimit(Local prop, const AccessorInfo &info); static Handle GetLineCap(Local prop, const AccessorInfo &info); static Handle GetLineJoin(Local prop, const AccessorInfo &info);