paper.js/src/item/PathStyle.js

65 lines
1.6 KiB
JavaScript
Raw Normal View History

var PathStyle = this.PathStyle = Base.extend(new function() {
var keys = ['windingRule', 'resolution', 'strokeColor', 'strokeWidth',
'strokeCap', 'strokeJoin', 'dashOffset','dashArray', 'miterLimit',
'strokeOverprint', 'fillColor', 'fillOverprint'];
var fields = {
beans: true,
initialize: function(item, style) {
this.item = item;
2011-02-20 21:32:39 -05:00
if (style) {
for (var i = 0, l = keys.length; i < l; i++) {
var key = keys[i];
2011-02-20 21:32:39 -05:00
if (style[key] !== undefined)
this[key] = style[key];
}
}
}
};
2011-02-16 16:15:19 -05:00
Item.inject(Base.each(keys, function(key) {
2011-03-04 19:23:16 -05:00
var isColor = !!(key.match(/Color$/)),
set = 'set' + Base.capitalize(key),
get = 'get' + Base.capitalize(key);
2011-03-04 19:23:16 -05:00
fields[set] = function(value) {
2011-02-20 21:32:39 -05:00
if (this.item && this.item.children) {
for (var i = 0, l = this.item.children.length; i < l; i++) {
2011-03-04 19:23:16 -05:00
this.item.children[i].getStyle()[set](value);
}
} else {
this['_' + key] = isColor ? Color.read(arguments) : value;
}
};
2011-03-04 19:23:16 -05:00
fields[get] = function() {
2011-02-20 21:32:39 -05:00
if (this.item && this.item.children) {
var style;
for (var i = 0, l = this.item.children.length; i < l; i++) {
2011-03-04 19:24:32 -05:00
var childStyle = this.item.children[i].getStyle()[get]();
2011-02-20 21:32:39 -05:00
if (!style) {
2011-03-04 19:24:32 -05:00
style = childStyle;
} else if (style != childStyle) {
// If there is another item with a different style:
2011-03-04 19:23:16 -05:00
return undefined;
}
}
return style;
} else {
return this['_' + key];
}
};
2011-02-16 16:15:19 -05:00
2011-03-04 19:23:16 -05:00
this[set] = function(value) {
this.getStyle()[set](value);
};
2011-03-04 19:23:16 -05:00
this[get] = function() {
return this.getStyle()[get]();
};
}, { beans: true }));
return fields;
2011-03-03 11:32:55 -05:00
});