Merge remote branch 'origin/master'

This commit is contained in:
Jonathan Puckey 2011-06-20 15:59:19 +02:00
commit ce2ef52f60
9 changed files with 88 additions and 90 deletions

View file

@ -178,7 +178,6 @@
vectorItem = null; vectorItem = null;
} }
processVector(event, true); processVector(event, true);
// document.redraw();
} }
function onMouseDrag(event) { function onMouseDrag(event) {

View file

@ -15,15 +15,21 @@
*/ */
var PathStyle = this.PathStyle = Style.extend(new function() { var PathStyle = this.PathStyle = Style.extend(new function() {
/** @lends PathStyle# */
// windingRule / resolution / fillOverprint / strokeOverprint are currently // windingRule / resolution / fillOverprint / strokeOverprint are currently
// not supported. The full list of properties would be: // not supported. The full list of properties would be:
// ['windingRule', 'resolution', 'strokeColor', 'strokeWidth', // ['windingRule', 'resolution', 'strokeColor', 'strokeWidth',
// 'strokeCap', 'strokeJoin', 'miterLimit', 'dashOffset','dashArray', // 'strokeCap', 'strokeJoin', 'miterLimit', 'dashOffset','dashArray',
// 'strokeOverprint', 'fillColor', 'fillOverprint'], // 'strokeOverprint', 'fillColor', 'fillOverprint'],
var keys = ['strokeColor', 'strokeWidth', 'strokeCap', 'strokeJoin', var defaults = {
'miterLimit', 'dashOffset','dashArray', 'fillColor']; fillColor: undefined,
strokeColor: undefined,
strokeWidth: 1,
strokeCap: 'butt',
strokeJoin: 'miter',
miterLimit: 10,
dashOffset: 0,
dashArray: []
};
var strokeFlags = { var strokeFlags = {
strokeWidth: true, strokeWidth: true,
@ -32,64 +38,13 @@ var PathStyle = this.PathStyle = Style.extend(new function() {
miterLimit: true miterLimit: true
}; };
var fields = { return Base.each(defaults, function(value, key) {
// DOCS: why isn't the example code showing up?
/**
* PathStyle objects don't need to be created directly. Just pass an
* object to {@link Item#style} or {@link Project#currentStyle}, it will
* be converted to a PathStyle object internally.
*
* @constructs PathStyle
* @param {object} style
*
* @class PathStyle is used for changing the visual styles of items
* contained within a Paper.js project and is returned by
* {@link Item#style} and {@link Project#currentStyle}.
*
* All properties of PathStyle are also reflected directly in {@link Item},
* i.e.: {@link Item#fillColor}.
*
* To set multiple style properties in one go, you can pass an object to
* {@link Item#style}. This is a convenient way to define a style once and
* apply it to a series of items:
*
* @classexample {@paperscript}
* var circleStyle = {
* fillColor: new RGBColor(1, 0, 0),
* strokeColor: 'black',
* strokeWidth: 5
* };
*
* var path = new Path.Circle(new Point(80, 50), 30);
* path.style = circleStyle;
*/
initialize: function(style) {
// If the passed style object is a PathStyle, clone its clonable
// fields rather than simply copying them.
var clone = style instanceof PathStyle;
// Note: This relies on bean getters and setters that get implicetly
// called when getting from style[key] and setting on this[key].
for (var i = 0, l = style && keys.length; i < l; i++) {
var key = keys[i],
value = style[key];
if (value !== undefined) {
this[key] = value && clone && value.clone
? value.clone() : value;
}
}
// Let Style#initialize handle the defaults:
if (this._defaults)
this.base(style);
}
};
Item.inject(Base.each(keys, function(key) {
var isColor = !!key.match(/Color$/), var isColor = !!key.match(/Color$/),
part = Base.capitalize(key), part = Base.capitalize(key),
set = 'set' + part, set = 'set' + part,
get = 'get' + part; get = 'get' + part;
fields[set] = function(value) { this[set] = function(value) {
var children = this._item && this._item._children; var children = this._item && this._item._children;
value = isColor ? Color.read(arguments) : value; value = isColor ? Color.read(arguments) : value;
if (children) { if (children) {
@ -114,7 +69,7 @@ var PathStyle = this.PathStyle = Style.extend(new function() {
return this; return this;
}; };
fields[get] = function() { this[get] = function() {
var children = this._item && this._item._children, var children = this._item && this._item._children,
style; style;
// If this item has children, walk through all of them and see if // If this item has children, walk through all of them and see if
@ -138,23 +93,44 @@ var PathStyle = this.PathStyle = Style.extend(new function() {
return this['_' + key]; return this['_' + key];
} }
}; };
}, {
// Style-getters and setters for Item: _defaults: defaults,
// 'this' = the Base.each() side-car = the object that is returned from _owner: Item,
// Base.each and injected into Item above: _style: '_style'
this[set] = function(value) { });
this._style[set](value);
return this;
};
this[get] = function() {
return this._style[get]();
};
}, {}));
return fields;
}); });
// TODO: See if these still show up?
// DOCS: why isn't the example code showing up?
/**
* PathStyle objects don't need to be created directly. Just pass an
* object to {@link Item#style} or {@link Project#currentStyle}, it will
* be converted to a PathStyle object internally.
*
* @constructs PathStyle
* @param {object} style
*
* @class PathStyle is used for changing the visual styles of items
* contained within a Paper.js project and is returned by
* {@link Item#style} and {@link Project#currentStyle}.
*
* All properties of PathStyle are also reflected directly in {@link Item},
* i.e.: {@link Item#fillColor}.
*
* To set multiple style properties in one go, you can pass an object to
* {@link Item#style}. This is a convenient way to define a style once and
* apply it to a series of items:
*
* @classexample {@paperscript}
* var circleStyle = {
* fillColor: new RGBColor(1, 0, 0),
* strokeColor: 'black',
* strokeWidth: 5
* };
*
* var path = new Path.Circle(new Point(80, 50), 30);
* path.style = circleStyle;
*/
/** /**
* {@grouptitle Stroke Style} * {@grouptitle Stroke Style}
* *

View file

@ -21,8 +21,15 @@
var Style = Item.extend({ var Style = Item.extend({
initialize: function(style) { initialize: function(style) {
return Base.each(this._defaults || {}, function(value, key) { // If the passed style object is also a Style, clone its clonable
this[key] = style && style[key] || value; // 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;
}, this); }, this);
}, },
@ -31,6 +38,26 @@ var Style = Item.extend({
var style = new this(this.dont); var style = new this(this.dont);
style._item = item; style._item = item;
return style; return style;
},
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);
} }
} }
}); });

View file

@ -59,10 +59,10 @@ var sources = [
'src/path/PathFlattener.js', 'src/path/PathFlattener.js',
'src/path/PathFitter.js', 'src/path/PathFitter.js',
'src/text/ParagraphStyle.js',
'src/text/CharacterStyle.js',
'src/text/TextItem.js', 'src/text/TextItem.js',
'src/text/PointText.js', 'src/text/PointText.js',
'src/text/ParagraphStyle.js',
'src/text/CharacterStyle.js',
'src/color/Color.js', 'src/color/Color.js',
'src/color/GradientColor.js', 'src/color/GradientColor.js',

View file

@ -79,10 +79,10 @@ var paper = new function() {
//#include "path/PathFlattener.js" //#include "path/PathFlattener.js"
//#include "path/PathFitter.js" //#include "path/PathFitter.js"
//#include "text/ParagraphStyle.js"
//#include "text/CharacterStyle.js"
//#include "text/TextItem.js" //#include "text/TextItem.js"
//#include "text/PointText.js" //#include "text/PointText.js"
//#include "text/ParagraphStyle.js"
//#include "text/CharacterStyle.js"
//#include "color/Color.js" //#include "color/Color.js"
//#include "color/GradientColor.js" //#include "color/GradientColor.js"

View file

@ -21,7 +21,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend({
* Creates a new compound path item and places it in the active layer. * Creates a new compound path item and places it in the active layer.
* *
* @constructs CompoundPath * @constructs CompoundPath
* @param {Array} [paths] the paths to place within the compound path. * @param {Path[]} [paths] the paths to place within the compound path.
* *
* @example {@paperscript} * @example {@paperscript}
* // Create a circle shaped path with a hole in it: * // Create a circle shaped path with a hole in it:

View file

@ -38,15 +38,7 @@ var Project = this.Project = Base.extend({
this._scope = paper; this._scope = paper;
// Push it onto this._scope.projects and set index: // Push it onto this._scope.projects and set index:
this._index = this._scope.projects.push(this) - 1; this._index = this._scope.projects.push(this) - 1;
this._currentStyle = PathStyle.create(null); this._currentStyle = new PathStyle();
this.setCurrentStyle({
strokeWidth: 1,
strokeCap: 'butt',
strokeJoin: 'miter',
miterLimit: 10,
dashOffset: 0,
dashArray: []
});
this._selectedItems = {}; this._selectedItems = {};
this._selectedItemCount = 0; this._selectedItemCount = 0;
// Activate straight away so paper.project is set, as required by // Activate straight away so paper.project is set, as required by

View file

@ -21,6 +21,8 @@ var CharacterStyle = this.CharacterStyle = PathStyle.extend({
fontSize: 10, fontSize: 10,
font: 'sans-serif' font: 'sans-serif'
}, },
_owner: TextItem,
_style: '_characterStyle'
/** /**
* CharacterStyle objects don't need to be created directly. Just pass an * CharacterStyle objects don't need to be created directly. Just pass an

View file

@ -20,6 +20,8 @@ var ParagraphStyle = this.ParagraphStyle = Style.extend({
_defaults: { _defaults: {
justification: 'left' justification: 'left'
}, },
_owner: TextItem,
_style: '_paragraphStyle'
/** /**
* ParagraphStyle objects don't need to be created directly. Just pass an * ParagraphStyle objects don't need to be created directly. Just pass an