Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

removed old parseColor dependants

  • Loading branch information...
commit 1f82f638900c2e7141be324f259960cbfee23f5a 1 parent ddf5c99
@tj tj authored
Showing with 9 additions and 108 deletions.
  1. +3 −104 lib/context2d.js
  2. +5 −3 src/CanvasGradient.cc
  3. +1 −1  src/CanvasGradient.h
View
107 lib/context2d.js
@@ -54,34 +54,6 @@ var fontre = new RegExp('^ *'
);
/**
- * 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`.
*
* @param {String} str
@@ -107,26 +79,6 @@ var parseFont = exports.parseFont = function(str){
};
/**
- * 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)`.
*
* @param {Number} x0
@@ -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,56 +149,21 @@ 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.
*
* @see exports.parseFont()
View
8 src/CanvasGradient.cc
@@ -24,7 +24,7 @@ Gradient::Initialize(Handle<Object> 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<Value>
-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<Gradient>(args.This());
cairo_pattern_add_color_stop_rgba(
View
2  src/CanvasGradient.h
@@ -15,7 +15,7 @@ class Gradient: public node::ObjectWrap {
static Persistent<FunctionTemplate> constructor;
static void Initialize(Handle<Object> target);
static Handle<Value> New(const Arguments &args);
- static Handle<Value> AddColorStopRGBA(const Arguments &args);
+ static Handle<Value> 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; }
Please sign in to comment.
Something went wrong with that request. Please try again.