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().
This commit is contained in:
Jürg Lehni 2011-12-19 23:07:14 +01:00
parent e30a0ae26d
commit 4a46c8ac98
4 changed files with 14 additions and 12 deletions

View file

@ -2386,10 +2386,8 @@ function(name) {
if (join) ctx.lineJoin = join; if (join) ctx.lineJoin = join;
if (cap) ctx.lineCap = cap; if (cap) ctx.lineCap = cap;
if (limit) ctx.miterLimit = limit; if (limit) ctx.miterLimit = limit;
// Always set fillStyle and strokeStyle, so the code calling if (fillColor) ctx.fillStyle = fillColor.getCanvasStyle(ctx);
// #_setStyles() can check them to see if we need to stroke / fill. if (strokeColor) ctx.strokeStyle = strokeColor.getCanvasStyle(ctx);
ctx.fillStyle = fillColor ? fillColor.getCanvasStyle(ctx) : null;
ctx.strokeStyle = strokeColor ? strokeColor.getCanvasStyle(ctx) : null;
// If the item only defines a strokeColor or a fillColor, draw it // If the item only defines a strokeColor or a fillColor, draw it
// directly with the globalAlpha set, otherwise we will do it later when // directly with the globalAlpha set, otherwise we will do it later when
// we composite the temporary canvas. // we composite the temporary canvas.

View file

@ -89,15 +89,16 @@ var CompoundPath = this.CompoundPath = PathItem.extend(/** @lends CompoundPath#
// Return early if the compound path doesn't have any children: // Return early if the compound path doesn't have any children:
if (children.length == 0) if (children.length == 0)
return; return;
var firstChild = children[0]; var firstChild = children[0],
style = firstChild._style;
ctx.beginPath(); ctx.beginPath();
param.compound = true; param.compound = true;
for (var i = 0, l = children.length; i < l; i++) for (var i = 0, l = children.length; i < l; i++)
Item.draw(children[i], ctx, param); Item.draw(children[i], ctx, param);
firstChild._setStyles(ctx); firstChild._setStyles(ctx);
if (ctx.fillStyle) if (style._fillColor)
ctx.fill(); ctx.fill();
if (ctx.strokeStyle) if (style._strokeColor)
ctx.stroke(); ctx.stroke();
param.compound = false; param.compound = false;
} }

View file

@ -72,14 +72,16 @@ var PointText = this.PointText = TextItem.extend(/** @lends PointText# */{
if (!this._content) if (!this._content)
return; return;
this._setStyles(ctx); this._setStyles(ctx);
var style = this._style,
leading = this.getLeading(),
lines = this._lines;
ctx.font = style.getFontStyle(); ctx.font = style.getFontStyle();
ctx.textAlign = this.getJustification(); ctx.textAlign = this.getJustification();
var leading = this.getLeading(); for (var i = 0, l = lines.length; i < l; i++) {
for (var i = 0, l = this._lines.length; i < l; i++) { var line = lines[i];
var line = this._lines[i]; if (style._fillColor)
if (ctx.fillStyle)
ctx.fillText(line, 0, 0); ctx.fillText(line, 0, 0);
if (ctx.strokeStyle) if (style._strokeColor)
ctx.strokeText(line, 0, 0); ctx.strokeText(line, 0, 0);
ctx.translate(0, leading); ctx.translate(0, leading);
} }

View file

@ -37,6 +37,7 @@ var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
this._style = CharacterStyle.create(this); this._style = CharacterStyle.create(this);
this._paragraphStyle = ParagraphStyle.create(this); this._paragraphStyle = ParagraphStyle.create(this);
this.base(); this.base();
// No need to call setStyle(), since base() handles this already.
// Call with no parameter to initalize defaults now. // Call with no parameter to initalize defaults now.
this.setParagraphStyle(); this.setParagraphStyle();
this._content = ''; this._content = '';