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 (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.

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

View file

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

View file

@ -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 = '';