mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Remove more beans access, this time related to various PathStyle getters / setters.
This commit is contained in:
parent
c313e702c9
commit
ce74516228
4 changed files with 30 additions and 25 deletions
|
@ -142,8 +142,8 @@ var Item = this.Item = Base.extend({
|
|||
setClipMask: function(clipMask) {
|
||||
this._clipMask = clipMask;
|
||||
if (this._clipMask) {
|
||||
this.fillColor = null;
|
||||
this.strokeColor = null;
|
||||
this.setFillColor(null);
|
||||
this.setStrokeColor(null);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -723,8 +723,8 @@ var Item = this.Item = Base.extend({
|
|||
// since otherwise their stroke is drawn half transparent over their
|
||||
// fill.
|
||||
if (item.blendMode !== 'normal'
|
||||
|| item.opacity < 1
|
||||
&& !(item.segments && (!item.fillColor || !item.strokeColor))) {
|
||||
|| item.opacity < 1
|
||||
&& !(item.segments && (!item.getFillColor() || !item.getStrokeColor()))) {
|
||||
var bounds = item.getStrokeBounds() || item.getBounds();
|
||||
if (!bounds.width || !bounds.height)
|
||||
return;
|
||||
|
|
|
@ -26,7 +26,7 @@ var PathStyle = this.PathStyle = Base.extend(new function() {
|
|||
fields[set] = function(value) {
|
||||
if (this.item && this.item.children) {
|
||||
for (var i = 0, l = this.item.children.length; i < l; i++) {
|
||||
this.item.children[i].getStyle()[set](value);
|
||||
this.item.children[i]._style[set](value);
|
||||
}
|
||||
} else {
|
||||
this['_' + key] = isColor ? Color.read(arguments) : value;
|
||||
|
@ -37,7 +37,7 @@ var PathStyle = this.PathStyle = Base.extend(new function() {
|
|||
if (this.item && this.item.children) {
|
||||
var style;
|
||||
for (var i = 0, l = this.item.children.length; i < l; i++) {
|
||||
var childStyle = this.item.children[i].getStyle()[get]();
|
||||
var childStyle = this.item.children[i]._style[get]();
|
||||
if (!style) {
|
||||
style = childStyle;
|
||||
} else if (style != childStyle) {
|
||||
|
|
|
@ -66,12 +66,14 @@ var CompoundPath = this.CompoundPath = PathItem.extend({
|
|||
Item.draw(this.children[i], ctx, param);
|
||||
}
|
||||
firstChild.setCtxStyles(ctx);
|
||||
if (firstChild.fillColor) {
|
||||
ctx.fillStyle = firstChild.fillColor.toCssString();
|
||||
var fillColor = firstChild.getFillColor(),
|
||||
strokeColor = firstChild.getStrokeColor();
|
||||
if (fillColor) {
|
||||
ctx.fillStyle = fillColor.toCssString();
|
||||
ctx.fill();
|
||||
}
|
||||
if (firstChild.strokeColor) {
|
||||
ctx.strokeStyle = firstChild.strokeColor.toCssString();
|
||||
if (strokeColor) {
|
||||
ctx.strokeStyle = strokeColor.toCssString();
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -393,20 +393,22 @@ var Path = this.Path = PathItem.extend({
|
|||
}
|
||||
// If the path is part of a compound path or doesn't have a fill or
|
||||
// stroke, there is no need to continue.
|
||||
if (!param.compound && (this.fillColor || this.strokeColor)) {
|
||||
var fillColor = this.getFillColor(),
|
||||
strokeColor = this.getStrokeColor();
|
||||
if (!param.compound && (fillColor || strokeColor)) {
|
||||
this.setCtxStyles(ctx);
|
||||
ctx.save();
|
||||
// If the path 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.
|
||||
if (!this.fillColor || !this.strokeColor)
|
||||
if (!fillColor || !strokeColor)
|
||||
ctx.globalAlpha = this.opacity;
|
||||
if (this.fillColor) {
|
||||
ctx.fillStyle = this.fillColor.getCanvasStyle(ctx);
|
||||
if (fillColor) {
|
||||
ctx.fillStyle = fillColor.getCanvasStyle(ctx);
|
||||
ctx.fill();
|
||||
}
|
||||
if (this.strokeColor) {
|
||||
ctx.strokeStyle = this.strokeColor.getCanvasStyle(ctx);
|
||||
if (strokeColor) {
|
||||
ctx.strokeStyle = strokeColor.getCanvasStyle(ctx);
|
||||
ctx.stroke();
|
||||
}
|
||||
ctx.restore();
|
||||
|
@ -515,11 +517,11 @@ var Path = this.Path = PathItem.extend({
|
|||
return x;
|
||||
};
|
||||
|
||||
var styleNames = {
|
||||
strokeWidth: 'lineWidth',
|
||||
strokeJoin: 'lineJoin',
|
||||
strokeCap: 'lineCap',
|
||||
miterLimit: 'miterLimit'
|
||||
var styles = {
|
||||
getStrokeWidth: 'lineWidth',
|
||||
getStrokeJoin: 'lineJoin',
|
||||
getStrokeCap: 'lineCap',
|
||||
getMiterLimit: 'miterLimit'
|
||||
};
|
||||
|
||||
return {
|
||||
|
@ -645,11 +647,12 @@ var Path = this.Path = PathItem.extend({
|
|||
}
|
||||
},
|
||||
|
||||
setCtxStyles: function(ctx) {
|
||||
for (var i in styleNames) {
|
||||
setCtxStyles: function(context) {
|
||||
for (var i in styles) {
|
||||
var style;
|
||||
if (style = this[i])
|
||||
ctx[styleNames[i]] = style;
|
||||
if (style = this[i]()) {
|
||||
context[styles[i]] = style;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue