paper.js/src/item/PathStyle.js

64 lines
1.5 KiB
JavaScript
Raw Normal View History

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;
if(style) {
for (var i = 0, l = keys.length; i < l; i++) {
var key = keys[i];
if(style[key])
this[key] = style[key];
}
}
}
}
2011-02-16 16:15:19 -05:00
var itemFields = { beans: true };
2011-02-16 16:15:19 -05:00
Base.each(keys, function(key) {
fields['set' + key.capitalize()] = function(value) {
if(this.item && this.item.children) {
for (var i = 0, l = this.item.children.length; i < l; i++) {
this.item.children[i].style[key] = value;
}
} else {
this['_' + key] = value;
}
};
fields['get' + key.capitalize()] = function() {
if(this.item && this.item.children) {
var style;
for (var i = 0, l = this.item.children.length; i < l; i++) {
if(!style) {
style = this.item.children[i].style[key];
} else if(style != this.item.children[i].style[key]) {
// If there is another item with a different style:
return null;
}
}
return style;
} else {
return this['_' + key];
}
};
2011-02-16 16:15:19 -05:00
itemFields['set' + key.capitalize()] = function(value) {
this.style[key] = value;
};
itemFields['get' + key.capitalize()] = function() {
return this.style[key];
};
});
2011-02-16 16:15:19 -05:00
Item.inject(itemFields);
return fields;
});