From c2849b3692ec1c47746243bcaec2962d3b0f374e Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Sat, 19 Feb 2011 17:25:16 +0100 Subject: [PATCH] Change PathStyle, CompoundPath and Path to work with new Color classes. --- src/item/PathStyle.js | 5 +++-- src/path/CompoundPath.js | 10 ++++++++-- src/path/Path.js | 16 ++++++++++------ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/item/PathStyle.js b/src/item/PathStyle.js index dfa42b1b..a367761d 100644 --- a/src/item/PathStyle.js +++ b/src/item/PathStyle.js @@ -16,17 +16,18 @@ PathStyle = Base.extend(new function() { } } } - } + }; Item.inject(Base.each(keys, function(key) { + var isColor = !!(key.match(/Color$/)); fields['set' + key.capitalize()] = function(value) { if(this.item && this.item.children) { for (var i = 0, l = this.item.children.length; i < l; i++) { this.item.children[i].style[key] = value; } } else { - this['_' + key] = value; + this['_' + key] = isColor ? Color.read(arguments) : value; } }; diff --git a/src/path/CompoundPath.js b/src/path/CompoundPath.js index a1872120..90739482 100644 --- a/src/path/CompoundPath.js +++ b/src/path/CompoundPath.js @@ -29,8 +29,14 @@ CompoundPath = PathItem.extend(new function() { child.draw(ctx, true); } firstChild.setCtxStyles(ctx); - if (firstChild.fillColor) ctx.fill(); - if (firstChild.strokeColor) ctx.stroke(); + if (firstChild.fillColor) { + ctx.fillStyle = firstChild.fillColor.getCssString(); + ctx.fill(); + } + if (firstChild.strokeColor) { + ctx.strokeStyle = firstChild.strokeColor.getCssString(); + ctx.stroke(); + } } }, diff --git a/src/path/Path.js b/src/path/Path.js index e5445239..403b9970 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -45,7 +45,7 @@ Path = PathItem.extend({ var max = { x: p0.x, y: p0.y - } + }; var coords = ['x', 'y']; function processSegment(segment) { var p1 = p0.add(prev.handleOut); @@ -367,8 +367,14 @@ Path = PathItem.extend({ } if(!compound) { this.setCtxStyles(ctx); - if (this.fillColor) ctx.fill(); - if (this.strokeColor) ctx.stroke(); + if (this.fillColor) { + ctx.fillStyle = this.fillColor.getCssString(); + ctx.fill(); + } + if (this.strokeColor) { + ctx.strokeStyle = this.strokeColor.getCssString(); + ctx.stroke(); + } } } }, new function() { // inject methods that require scoped privates @@ -399,8 +405,6 @@ Path = PathItem.extend({ }; var styleNames = { - fillColor: 'fillStyle', - strokeColor: 'strokeStyle', strokeWidth: 'lineWidth', strokeJoin: 'lineJoin', strokeCap: 'lineCap', @@ -514,5 +518,5 @@ Path = PathItem.extend({ ctx[styleNames[i]] = style; } } - } + }; });