2011-06-20 08:56:49 -04:00
|
|
|
/*
|
|
|
|
* Paper.js
|
|
|
|
*
|
|
|
|
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
|
|
|
|
* based on Scriptographer.org and designed to be largely API compatible.
|
|
|
|
* http://paperjs.org/
|
|
|
|
* http://scriptographer.org/
|
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
|
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal base-class for all style objects, e.g. PathStyle, CharacterStyle,
|
|
|
|
* PargraphStyle.
|
|
|
|
*/
|
|
|
|
var Style = Item.extend({
|
2011-06-20 09:10:37 -04:00
|
|
|
|
|
|
|
initialize: function(style) {
|
2011-06-20 09:58:48 -04:00
|
|
|
// If the passed style object is also a Style, clone its clonable
|
|
|
|
// fields rather than simply copying them.
|
|
|
|
var clone = style instanceof Style;
|
|
|
|
// Note: This relies on bean getters and setters that get implicetly
|
|
|
|
// called when getting from style[key] and setting on this[key].
|
|
|
|
return Base.each(this._defaults, function(value, key) {
|
|
|
|
value = style && style[key] || value;
|
|
|
|
this[key] = value && clone && value.clone
|
|
|
|
? value.clone() : value;
|
2011-06-20 09:10:37 -04:00
|
|
|
}, this);
|
|
|
|
},
|
|
|
|
|
2011-06-20 08:56:49 -04:00
|
|
|
statics: {
|
|
|
|
create: function(item) {
|
|
|
|
var style = new this(this.dont);
|
|
|
|
style._item = item;
|
|
|
|
return style;
|
2011-06-20 09:58:48 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
extend: function(src) {
|
|
|
|
// Inject style getters and setters into the 'owning' class, which
|
|
|
|
// redirect calls to the linked style objects through their internal
|
|
|
|
// property on the instances of that class, as defined by _style.
|
|
|
|
var style = src._style;
|
|
|
|
src._owner.inject(Base.each(src._defaults, function(value, key) {
|
|
|
|
var part = Base.capitalize(key),
|
|
|
|
set = 'set' + part,
|
|
|
|
get = 'get' + part;
|
|
|
|
this[set] = function(value) {
|
|
|
|
this[style][set](value);
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
this[get] = function() {
|
|
|
|
return this[style][get]();
|
|
|
|
};
|
|
|
|
}, {}));
|
|
|
|
return this.base(src);
|
2011-06-20 08:56:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|