|
|
@ -53,27 +53,29 @@ var fontre = new RegExp('^ *' |
|
|
|
); |
|
|
|
|
|
|
|
/** |
|
|
|
* Return a function used to normalize an RGBA color `prop`. |
|
|
|
* Return a function used to normalize an RGBA color `prop` |
|
|
|
* or the pattern previously set. |
|
|
|
* |
|
|
|
* @param {String} prop |
|
|
|
* @return {Function} |
|
|
|
* @api private |
|
|
|
*/ |
|
|
|
|
|
|
|
function normalizedColor(prop) { |
|
|
|
function getter(prop) { |
|
|
|
return function(){ |
|
|
|
var rgba = this[prop]; |
|
|
|
if (1 == rgba[3]) { |
|
|
|
var val = this[prop]; |
|
|
|
if (val instanceof CanvasGradient) return val; |
|
|
|
if (1 == val[3]) { |
|
|
|
return '#' |
|
|
|
+ rgba[0].toString(16) |
|
|
|
+ rgba[1].toString(16) |
|
|
|
+ rgba[2].toString(16); |
|
|
|
+ val[0].toString(16) |
|
|
|
+ val[1].toString(16) |
|
|
|
+ val[2].toString(16); |
|
|
|
} else { |
|
|
|
return 'rgba(' |
|
|
|
+ rgba[0] + ', ' |
|
|
|
+ rgba[1] + ', ' |
|
|
|
+ rgba[2] + ', ' |
|
|
|
+ rgba[3] + ')'; |
|
|
|
+ val[0] + ', ' |
|
|
|
+ val[1] + ', ' |
|
|
|
+ val[2] + ', ' |
|
|
|
+ val[3] + ')'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -250,6 +252,7 @@ Context2d.prototype.setTransform = function(){ |
|
|
|
|
|
|
|
Context2d.prototype.__defineSetter__('fillStyle', function(val){ |
|
|
|
if (val instanceof CanvasGradient) { |
|
|
|
this.lastFillStyle = val; |
|
|
|
this.setFillPattern(val); |
|
|
|
} else if ('string' == typeof val) { |
|
|
|
var rgba; |
|
|
@ -270,7 +273,7 @@ Context2d.prototype.__defineSetter__('fillStyle', function(val){ |
|
|
|
* @api public |
|
|
|
*/ |
|
|
|
|
|
|
|
Context2d.prototype.__defineGetter__('fillStyle', normalizedColor('lastFillStyle')); |
|
|
|
Context2d.prototype.__defineGetter__('fillStyle', getter('lastFillStyle')); |
|
|
|
|
|
|
|
/** |
|
|
|
* Set the stroke style with the given css color string. |
|
|
@ -281,6 +284,7 @@ Context2d.prototype.__defineGetter__('fillStyle', normalizedColor('lastFillStyle |
|
|
|
|
|
|
|
Context2d.prototype.__defineSetter__('strokeStyle', function(val){ |
|
|
|
if (val instanceof CanvasGradient) { |
|
|
|
this.lastStrokeStyle = val; |
|
|
|
this.setStrokePattern(val); |
|
|
|
} else if ('string' == typeof val) { |
|
|
|
var rgba; |
|
|
@ -301,7 +305,7 @@ Context2d.prototype.__defineSetter__('strokeStyle', function(val){ |
|
|
|
* @api public |
|
|
|
*/ |
|
|
|
|
|
|
|
Context2d.prototype.__defineGetter__('strokeStyle', normalizedColor('lastStrokeStyle')); |
|
|
|
Context2d.prototype.__defineGetter__('strokeStyle', getter('lastStrokeStyle')); |
|
|
|
|
|
|
|
/** |
|
|
|
* Set the shadow color with the given css color string. |
|
|
@ -330,7 +334,7 @@ Context2d.prototype.__defineSetter__('shadowColor', function(val){ |
|
|
|
* @api public |
|
|
|
*/ |
|
|
|
|
|
|
|
Context2d.prototype.__defineGetter__('shadowColor', normalizedColor('lastShadowColor')); |
|
|
|
Context2d.prototype.__defineGetter__('shadowColor', getter('lastShadowColor')); |
|
|
|
|
|
|
|
/** |
|
|
|
* Set font. |
|
|
|