Optimise handling and setting of fill and stroke styles.

Handle setting of fillColor and strokeColor in Item#_setStyles() instead of the various #draw() methods, directly access internal styles instead of using accessor calls and fix PointText#draw().
This commit is contained in:
Jürg Lehni 2011-12-19 22:40:14 +01:00
parent ea0eaf04ea
commit cc26fdc5d1
4 changed files with 66 additions and 68 deletions

View file

@ -85,27 +85,20 @@ var CompoundPath = this.CompoundPath = PathItem.extend(/** @lends CompoundPath#
},
draw: function(ctx, param) {
var l = this._children.length;
var children = this._children;
// Return early if the compound path doesn't have any children:
if (l == 0) {
if (children.length == 0)
return;
}
var firstChild = this._children[0];
var firstChild = children[0];
ctx.beginPath();
param.compound = true;
for (var i = 0; i < l; i++)
Item.draw(this._children[i], ctx, param);
for (var i = 0, l = children.length; i < l; i++)
Item.draw(children[i], ctx, param);
firstChild._setStyles(ctx);
var fillColor = firstChild.getFillColor(),
strokeColor = firstChild.getStrokeColor();
if (fillColor) {
ctx.fillStyle = fillColor.getCanvasStyle(ctx);
if (ctx.fillStyle)
ctx.fill();
}
if (strokeColor) {
ctx.strokeStyle = strokeColor.getCanvasStyle(ctx);
if (ctx.strokeStyle)
ctx.stroke();
}
param.compound = false;
}
}, new function() { // Injection scope for PostScript-like drawing functions