From 4a46c8ac9873f72a183c85c2274b8e604b6aef48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 19 Dec 2011 23:07:14 +0100 Subject: [PATCH] Fix recently introduced error with stroke/fillColor handling Since CanvasContext#stroke/fillStyle cannot be set to null, we have to keep checking Style#fill/strokeColor even after calling #_setStyles(). --- src/item/Item.js | 6 ++---- src/path/CompoundPath.js | 7 ++++--- src/text/PointText.js | 12 +++++++----- src/text/TextItem.js | 1 + 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index 99df373a..780ee6f9 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -2386,10 +2386,8 @@ function(name) { if (join) ctx.lineJoin = join; if (cap) ctx.lineCap = cap; if (limit) ctx.miterLimit = limit; - // Always set fillStyle and strokeStyle, so the code calling - // #_setStyles() can check them to see if we need to stroke / fill. - ctx.fillStyle = fillColor ? fillColor.getCanvasStyle(ctx) : null; - ctx.strokeStyle = strokeColor ? strokeColor.getCanvasStyle(ctx) : null; + if (fillColor) ctx.fillStyle = fillColor.getCanvasStyle(ctx); + if (strokeColor) ctx.strokeStyle = strokeColor.getCanvasStyle(ctx); // If the item only defines a strokeColor or a fillColor, draw it // directly with the globalAlpha set, otherwise we will do it later when // we composite the temporary canvas. diff --git a/src/path/CompoundPath.js b/src/path/CompoundPath.js index a047c0b6..548d918f 100644 --- a/src/path/CompoundPath.js +++ b/src/path/CompoundPath.js @@ -89,15 +89,16 @@ var CompoundPath = this.CompoundPath = PathItem.extend(/** @lends CompoundPath# // Return early if the compound path doesn't have any children: if (children.length == 0) return; - var firstChild = children[0]; + var firstChild = children[0], + style = firstChild._style; ctx.beginPath(); param.compound = true; for (var i = 0, l = children.length; i < l; i++) Item.draw(children[i], ctx, param); firstChild._setStyles(ctx); - if (ctx.fillStyle) + if (style._fillColor) ctx.fill(); - if (ctx.strokeStyle) + if (style._strokeColor) ctx.stroke(); param.compound = false; } diff --git a/src/text/PointText.js b/src/text/PointText.js index d31089c9..56df8d20 100644 --- a/src/text/PointText.js +++ b/src/text/PointText.js @@ -72,14 +72,16 @@ var PointText = this.PointText = TextItem.extend(/** @lends PointText# */{ if (!this._content) return; this._setStyles(ctx); + var style = this._style, + leading = this.getLeading(), + lines = this._lines; ctx.font = style.getFontStyle(); ctx.textAlign = this.getJustification(); - var leading = this.getLeading(); - for (var i = 0, l = this._lines.length; i < l; i++) { - var line = this._lines[i]; - if (ctx.fillStyle) + for (var i = 0, l = lines.length; i < l; i++) { + var line = lines[i]; + if (style._fillColor) ctx.fillText(line, 0, 0); - if (ctx.strokeStyle) + if (style._strokeColor) ctx.strokeText(line, 0, 0); ctx.translate(0, leading); } diff --git a/src/text/TextItem.js b/src/text/TextItem.js index dca88707..f4dd0fa4 100644 --- a/src/text/TextItem.js +++ b/src/text/TextItem.js @@ -37,6 +37,7 @@ var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{ this._style = CharacterStyle.create(this); this._paragraphStyle = ParagraphStyle.create(this); this.base(); + // No need to call setStyle(), since base() handles this already. // Call with no parameter to initalize defaults now. this.setParagraphStyle(); this._content = '';