Browse Source

removed old parseColor dependants

v1.x
Tj Holowaychuk 14 years ago
parent
commit
1f82f63890
  1. 107
      lib/context2d.js
  2. 8
      src/CanvasGradient.cc
  3. 2
      src/CanvasGradient.h

107
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.
*

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(

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; }

Loading…
Cancel
Save