From 1f82f638900c2e7141be324f259960cbfee23f5a Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Tue, 23 Nov 2010 14:14:48 -0800 Subject: [PATCH] removed old parseColor dependants --- lib/context2d.js | 107 ++---------------------------------------- src/CanvasGradient.cc | 8 ++-- src/CanvasGradient.h | 2 +- 3 files changed, 9 insertions(+), 108 deletions(-) diff --git a/lib/context2d.js b/lib/context2d.js index fc435c9..b0ddef6 100644 --- a/lib/context2d.js +++ b/lib/context2d.js @@ -53,34 +53,6 @@ var fontre = new RegExp('^ *' + '((?:' + string + ')( *, *(?:' + string + '))*)' ); -/** - * Return a function used to normalize an RGBA color `prop` - * or the pattern previously set. - * - * @param {String} prop - * @return {Function} - * @api private - */ - -function getter(prop) { - return function(){ - var val = this[prop]; - if (val instanceof CanvasGradient) return val; - if (1 == val[3]) { - return '#' - + val[0].toString(16) - + val[1].toString(16) - + val[2].toString(16); - } else { - return 'rgba(' - + val[0] + ', ' - + val[1] + ', ' - + val[2] + ', ' - + val[3] + ')'; - } - } -} - /** * Parse font `str`. * @@ -106,26 +78,6 @@ var parseFont = exports.parseFont = function(str){ return font; }; -/** - * Add `color` stop at the given `offset`. - * - * @param {Number} offset - * @param {String} color - * @api public - */ - -CanvasGradient.prototype.addColorStop = function(offset, color){ - var rgba; - if (rgba = parseColor(color)) { - this.addColorStopRGBA( - offset - , rgba[0] - , rgba[1] - , rgba[2] - , rgba[3]); - } -}; - /** * Create a linear gradient at the given point `(x0, y0)` and `(x1, y1)`. * @@ -174,7 +126,6 @@ Context2d.prototype.setTransform = function(){ /** * Set the fill style with the given css color string. * - * @see exports.parseColor() * @api public */ @@ -183,30 +134,13 @@ Context2d.prototype.__defineSetter__('fillStyle', function(val){ this.lastFillStyle = val; this.setFillPattern(val); } else if ('string' == typeof val) { - var rgba; - if (rgba = parseColor(val)) { - this.lastFillStyle = rgba; - this.setFillRGBA( - rgba[0] - , rgba[1] - , rgba[2] - , rgba[3]); - } + this.setFillStyle(val); } }); -/** - * Get the current fill style string. - * - * @api public - */ - -Context2d.prototype.__defineGetter__('fillStyle', getter('lastFillStyle')); - /** * Set the stroke style with the given css color string. * - * @see exports.parseColor() * @api public */ @@ -215,55 +149,20 @@ Context2d.prototype.__defineSetter__('strokeStyle', function(val){ this.lastStrokeStyle = val; this.setStrokePattern(val); } else if ('string' == typeof val) { - var rgba; - if (rgba = parseColor(val)) { - this.lastStrokeStyle = rgba; - this.setStrokeRGBA( - rgba[0] - , rgba[1] - , rgba[2] - , rgba[3]); - } + this.setStrokeStyle(val); } }); -/** - * Get the current stroke style string. - * - * @api public - */ - -Context2d.prototype.__defineGetter__('strokeStyle', getter('lastStrokeStyle')); - /** * Set the shadow color with the given css color string. * - * @see exports.parseColor() * @api public */ Context2d.prototype.__defineSetter__('shadowColor', function(val){ - if ('string' == typeof val) { - var rgba; - if (rgba = parseColor(val)) { - this.lastShadowColor = rgba; - this.setShadowRGBA( - rgba[0] - , rgba[1] - , rgba[2] - , rgba[3]); - } - } + this.setShadowColor(val); }); -/** - * Get the current shadow color string. - * - * @api public - */ - -Context2d.prototype.__defineGetter__('shadowColor', getter('lastShadowColor')); - /** * Set font. * diff --git a/src/CanvasGradient.cc b/src/CanvasGradient.cc index cf99585..bd123f6 100644 --- a/src/CanvasGradient.cc +++ b/src/CanvasGradient.cc @@ -24,7 +24,7 @@ Gradient::Initialize(Handle target) { constructor->SetClassName(String::NewSymbol("CanvasGradient")); // Prototype - NODE_SET_PROTOTYPE_METHOD(constructor, "addColorStopRGBA", AddColorStopRGBA); + NODE_SET_PROTOTYPE_METHOD(constructor, "addColorStop", AddColorStop); target->Set(String::NewSymbol("CanvasGradient"), constructor->GetFunction()); } @@ -64,14 +64,16 @@ Gradient::New(const Arguments &args) { } /* - * Add RGBA color stop. + * Add color stop. */ Handle -Gradient::AddColorStopRGBA(const Arguments &args) { +Gradient::AddColorStop(const Arguments &args) { HandleScope scope; if (!args[0]->IsNumber()) return ThrowException(Exception::TypeError(String::New("offset required"))); + if (!args[1]->IsString()) + return ThrowException(Exception::TypeError(String::New("color string required"))); RGBA_ARGS(1); Gradient *grad = ObjectWrap::Unwrap(args.This()); cairo_pattern_add_color_stop_rgba( diff --git a/src/CanvasGradient.h b/src/CanvasGradient.h index adcf2bc..db17096 100644 --- a/src/CanvasGradient.h +++ b/src/CanvasGradient.h @@ -15,7 +15,7 @@ class Gradient: public node::ObjectWrap { static Persistent constructor; static void Initialize(Handle target); static Handle New(const Arguments &args); - static Handle AddColorStopRGBA(const Arguments &args); + static Handle AddColorStop(const Arguments &args); Gradient(double x0, double y0, double x1, double y1); Gradient(double x0, double y0, double r0, double x1, double y1, double r1); inline cairo_pattern_t *pattern(){ return _pattern; }