2011-05-16 08:33:15 -04:00
|
|
|
|
/*
|
2013-01-28 21:03:27 -05:00
|
|
|
|
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
2011-05-16 08:33:15 -04:00
|
|
|
|
* http://paperjs.org/
|
2011-06-30 06:01:51 -04:00
|
|
|
|
*
|
2014-01-03 19:47:16 -05:00
|
|
|
|
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
|
|
|
|
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
2011-06-30 06:01:51 -04:00
|
|
|
|
*
|
2011-07-01 06:17:45 -04:00
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
|
*
|
2011-05-16 08:33:15 -04:00
|
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-06-30 06:01:51 -04:00
|
|
|
|
/**
|
2011-06-22 18:56:05 -04:00
|
|
|
|
* @name Project
|
2011-06-30 06:01:51 -04:00
|
|
|
|
*
|
2011-07-27 17:02:29 -04:00
|
|
|
|
* @class A Project object in Paper.js is what usually is referred to as the
|
2011-06-27 08:43:39 -04:00
|
|
|
|
* document: The top level object that holds all the items contained in the
|
|
|
|
|
* scene graph. As the term document is already taken in the browser context,
|
|
|
|
|
* it is called Project.
|
2011-06-30 06:01:51 -04:00
|
|
|
|
*
|
2014-03-18 10:25:25 -04:00
|
|
|
|
* Projects allow the manipulation of the styles that are applied to all newly
|
2011-06-27 08:43:39 -04:00
|
|
|
|
* created items, give access to the selected items, and will in future versions
|
|
|
|
|
* offer ways to query for items in the scene graph defining specific
|
|
|
|
|
* requirements, and means to persist and load from different formats, such as
|
|
|
|
|
* SVG and PDF.
|
2011-06-30 06:01:51 -04:00
|
|
|
|
*
|
2011-07-27 17:02:29 -04:00
|
|
|
|
* The currently active project can be accessed through the
|
|
|
|
|
* {@link PaperScope#project} variable.
|
2011-06-30 06:01:51 -04:00
|
|
|
|
*
|
2011-07-27 17:02:29 -04:00
|
|
|
|
* An array of all open projects is accessible through the
|
|
|
|
|
* {@link PaperScope#projects} variable.
|
2011-06-22 18:56:05 -04:00
|
|
|
|
*/
|
2013-05-27 15:48:58 -04:00
|
|
|
|
var Project = PaperScopeItem.extend(/** @lends Project# */{
|
2013-06-23 23:18:32 -04:00
|
|
|
|
_class: 'Project',
|
2011-08-02 05:08:08 -04:00
|
|
|
|
_list: 'projects',
|
|
|
|
|
_reference: 'project',
|
|
|
|
|
|
2011-05-17 08:25:46 -04:00
|
|
|
|
// TODO: Add arguments to define pages
|
2011-05-23 12:13:03 -04:00
|
|
|
|
/**
|
2013-11-24 10:25:13 -05:00
|
|
|
|
* Creates a Paper.js project containing one empty {@link Layer}, referenced
|
|
|
|
|
* by {@link Project#activeLayer}.
|
2011-06-30 06:01:51 -04:00
|
|
|
|
*
|
2013-11-24 10:25:13 -05:00
|
|
|
|
* Note that when working with PaperScript, a project is automatically
|
|
|
|
|
* created for us and the {@link PaperScope#project} variable points to it.
|
2011-11-12 10:56:23 -05:00
|
|
|
|
*
|
2014-03-17 11:41:57 -04:00
|
|
|
|
* @param {HTMLCanvasElement} element an HTML anvas element that should be
|
|
|
|
|
* used as the element for the view.
|
2011-05-23 12:13:03 -04:00
|
|
|
|
*/
|
2014-03-17 11:41:57 -04:00
|
|
|
|
initialize: function Project(element) {
|
2013-07-21 18:45:22 -04:00
|
|
|
|
// Activate straight away by passing true to PaperScopeItem constructor,
|
|
|
|
|
// so paper.project is set, as required by Layer and DoumentView
|
|
|
|
|
// constructors.
|
2013-05-27 12:11:50 -04:00
|
|
|
|
PaperScopeItem.call(this, true);
|
2011-05-16 08:33:15 -04:00
|
|
|
|
this.layers = [];
|
|
|
|
|
this.symbols = [];
|
2014-03-17 11:41:57 -04:00
|
|
|
|
this._currentStyle = new Style(null, null, this);
|
2011-05-16 08:33:15 -04:00
|
|
|
|
this.activeLayer = new Layer();
|
2014-03-17 11:41:57 -04:00
|
|
|
|
// If no view is provided, we create a 1x1 px canvas view just so we
|
|
|
|
|
// have something to do size calculations with.
|
|
|
|
|
// (e.g. PointText#_getBounds)
|
|
|
|
|
this._view = View.create(this,
|
|
|
|
|
element || CanvasProvider.getCanvas(1, 1));
|
2012-12-03 12:53:47 -05:00
|
|
|
|
this._selectedItems = {};
|
|
|
|
|
this._selectedItemCount = 0;
|
2013-12-09 01:51:28 -05:00
|
|
|
|
// See Item#draw() for an explanation of _updateVersion
|
|
|
|
|
this._updateVersion = 0;
|
2011-09-22 04:32:17 -04:00
|
|
|
|
// Change tracking, not in use for now. Activate once required:
|
|
|
|
|
// this._changes = [];
|
|
|
|
|
// this._changesById = {};
|
2011-05-16 08:33:15 -04:00
|
|
|
|
},
|
|
|
|
|
|
2013-02-12 17:57:54 -05:00
|
|
|
|
_serialize: function(options, dictionary) {
|
2013-02-11 19:43:31 -05:00
|
|
|
|
// Just serialize layers to an array for now, they will be unserialized
|
|
|
|
|
// into the active project automatically. We might want to add proper
|
|
|
|
|
// project serialization later, but deserialization of a layers array
|
|
|
|
|
// will always work.
|
2013-05-28 10:57:35 -04:00
|
|
|
|
// Pass true for compact, so 'Project' does not get added as the class
|
2013-05-28 10:42:38 -04:00
|
|
|
|
return Base.serialize(this.layers, options, true, dictionary);
|
2013-02-11 19:43:31 -05:00
|
|
|
|
},
|
|
|
|
|
|
2011-08-02 05:08:08 -04:00
|
|
|
|
/**
|
|
|
|
|
* Activates this project, so all newly created items will be placed
|
|
|
|
|
* in it.
|
|
|
|
|
*
|
|
|
|
|
* @name Project#activate
|
|
|
|
|
* @function
|
|
|
|
|
*/
|
|
|
|
|
|
2014-04-28 12:19:56 -04:00
|
|
|
|
/**
|
|
|
|
|
* Clears the project by removing all {@link Project#layers} and
|
|
|
|
|
* {@link Project#symbols}.
|
|
|
|
|
*/
|
2013-04-23 01:48:36 -04:00
|
|
|
|
clear: function() {
|
2013-06-20 22:14:47 -04:00
|
|
|
|
for (var i = this.layers.length - 1; i >= 0; i--)
|
2013-04-23 01:48:36 -04:00
|
|
|
|
this.layers[i].remove();
|
|
|
|
|
this.symbols = [];
|
|
|
|
|
},
|
|
|
|
|
|
2013-11-24 16:53:41 -05:00
|
|
|
|
/**
|
2014-04-28 12:20:22 -04:00
|
|
|
|
* Checks whether the project has any content or not. Note that since
|
2014-03-18 10:25:25 -04:00
|
|
|
|
* projects by default are created with one empty layer, this returns also
|
2013-11-24 16:53:41 -05:00
|
|
|
|
* {@code true} if that layer exists but is itself empty.
|
|
|
|
|
*
|
|
|
|
|
* @return Boolean
|
|
|
|
|
*/
|
|
|
|
|
isEmpty: function() {
|
|
|
|
|
return this.layers.length <= 1
|
|
|
|
|
&& (!this.activeLayer || this.activeLayer.isEmpty());
|
|
|
|
|
},
|
|
|
|
|
|
2011-08-02 05:08:08 -04:00
|
|
|
|
/**
|
2011-11-12 10:56:23 -05:00
|
|
|
|
* Removes this project from the {@link PaperScope#projects} list, and also
|
|
|
|
|
* removes its view, if one was defined.
|
|
|
|
|
*/
|
2013-05-27 13:04:05 -04:00
|
|
|
|
remove: function remove() {
|
|
|
|
|
if (!remove.base.call(this))
|
2011-11-12 10:56:23 -05:00
|
|
|
|
return false;
|
2014-03-17 11:41:57 -04:00
|
|
|
|
if (this._view)
|
|
|
|
|
this._view.remove();
|
2011-11-12 10:56:23 -05:00
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The reference to the project's view.
|
|
|
|
|
* @type View
|
2014-03-17 11:41:57 -04:00
|
|
|
|
* @bean
|
2011-08-02 05:08:08 -04:00
|
|
|
|
*/
|
2014-03-17 11:41:57 -04:00
|
|
|
|
getView: function() {
|
|
|
|
|
return this._view;
|
|
|
|
|
},
|
2011-08-02 05:08:08 -04:00
|
|
|
|
|
2011-05-23 12:13:03 -04:00
|
|
|
|
/**
|
|
|
|
|
* The currently active path style. All selected items and newly
|
|
|
|
|
* created items will be styled with this style.
|
2011-06-30 06:01:51 -04:00
|
|
|
|
*
|
2013-04-09 19:46:20 -04:00
|
|
|
|
* @type Style
|
2011-05-23 12:13:03 -04:00
|
|
|
|
* @bean
|
2011-06-30 06:01:51 -04:00
|
|
|
|
*
|
2011-06-10 07:44:30 -04:00
|
|
|
|
* @example {@paperscript}
|
2011-05-30 13:42:17 -04:00
|
|
|
|
* project.currentStyle = {
|
2014-04-02 15:03:35 -04:00
|
|
|
|
* fillColor: 'red',
|
|
|
|
|
* strokeColor: 'black',
|
|
|
|
|
* strokeWidth: 5
|
2011-05-30 13:42:17 -04:00
|
|
|
|
* }
|
2011-06-30 06:01:51 -04:00
|
|
|
|
*
|
2011-06-10 07:44:30 -04:00
|
|
|
|
* // The following paths will take over all style properties of
|
2011-05-30 13:42:17 -04:00
|
|
|
|
* // the current style:
|
2011-06-10 07:44:30 -04:00
|
|
|
|
* var path = new Path.Circle(new Point(75, 50), 30);
|
|
|
|
|
* var path2 = new Path.Circle(new Point(175, 50), 20);
|
2011-06-30 06:01:51 -04:00
|
|
|
|
*
|
2011-06-10 07:44:30 -04:00
|
|
|
|
* @example {@paperscript}
|
2011-05-30 13:42:17 -04:00
|
|
|
|
* project.currentStyle.fillColor = 'red';
|
2011-06-30 06:01:51 -04:00
|
|
|
|
*
|
2011-05-30 13:42:17 -04:00
|
|
|
|
* // The following path will take over the fill color we just set:
|
2011-06-10 07:44:30 -04:00
|
|
|
|
* var path = new Path.Circle(new Point(75, 50), 30);
|
|
|
|
|
* var path2 = new Path.Circle(new Point(175, 50), 20);
|
2011-05-23 12:13:03 -04:00
|
|
|
|
*/
|
2011-05-16 08:33:15 -04:00
|
|
|
|
getCurrentStyle: function() {
|
|
|
|
|
return this._currentStyle;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
setCurrentStyle: function(style) {
|
2011-06-01 05:49:43 -04:00
|
|
|
|
// TODO: Style selected items with the style:
|
2011-05-16 14:21:36 -04:00
|
|
|
|
this._currentStyle.initialize(style);
|
2011-05-16 08:33:15 -04:00
|
|
|
|
},
|
|
|
|
|
|
2011-05-23 12:13:03 -04:00
|
|
|
|
/**
|
2011-07-27 17:02:29 -04:00
|
|
|
|
* The index of the project in the {@link PaperScope#projects} list.
|
2011-06-30 06:01:51 -04:00
|
|
|
|
*
|
2011-05-27 14:15:15 -04:00
|
|
|
|
* @type Number
|
2011-05-23 12:13:03 -04:00
|
|
|
|
* @bean
|
|
|
|
|
*/
|
2011-05-16 08:33:15 -04:00
|
|
|
|
getIndex: function() {
|
|
|
|
|
return this._index;
|
|
|
|
|
},
|
|
|
|
|
|
2013-11-24 10:25:13 -05:00
|
|
|
|
// Helper function used in Item#copyTo and Layer#initialize
|
|
|
|
|
// It's called the same as Item#addChild so Item#copyTo does not need to
|
|
|
|
|
// make the distinction.
|
|
|
|
|
// TODO: Consider private function with alias in Item?
|
|
|
|
|
addChild: function(child) {
|
|
|
|
|
if (child instanceof Layer) {
|
|
|
|
|
Base.splice(this.layers, [child]);
|
|
|
|
|
// Also activate this layer if there was none before
|
|
|
|
|
if (!this.activeLayer)
|
|
|
|
|
this.activeLayer = child;
|
|
|
|
|
} else if (child instanceof Item) {
|
|
|
|
|
// Anything else than layers needs to be added to a layer first
|
|
|
|
|
(this.activeLayer
|
|
|
|
|
// NOTE: If there is no layer and this project is not the active
|
|
|
|
|
// one, passing insert: false and calling addChild on the
|
|
|
|
|
// project will handle it correctly.
|
2014-02-26 10:15:51 -05:00
|
|
|
|
|| this.addChild(new Layer(Item.NO_INSERT))).addChild(child);
|
2013-11-24 10:25:13 -05:00
|
|
|
|
} else {
|
|
|
|
|
child = null;
|
|
|
|
|
}
|
|
|
|
|
return child;
|
|
|
|
|
},
|
|
|
|
|
|
2011-05-23 12:13:03 -04:00
|
|
|
|
/**
|
|
|
|
|
* The selected items contained within the project.
|
2011-06-30 06:01:51 -04:00
|
|
|
|
*
|
2011-05-26 10:49:19 -04:00
|
|
|
|
* @type Item[]
|
2011-05-23 12:13:03 -04:00
|
|
|
|
* @bean
|
|
|
|
|
*/
|
2011-05-16 08:33:15 -04:00
|
|
|
|
getSelectedItems: function() {
|
2011-06-01 05:49:43 -04:00
|
|
|
|
// TODO: Return groups if their children are all selected,
|
2011-05-16 08:33:15 -04:00
|
|
|
|
// and filter out their children from the list.
|
2011-06-01 05:49:43 -04:00
|
|
|
|
// TODO: The order of these items should be that of their
|
2011-05-16 08:33:15 -04:00
|
|
|
|
// drawing order.
|
|
|
|
|
var items = [];
|
2013-01-20 17:01:27 -05:00
|
|
|
|
for (var id in this._selectedItems) {
|
|
|
|
|
var item = this._selectedItems[id];
|
2013-10-18 15:52:22 -04:00
|
|
|
|
if (item.isInserted())
|
2013-01-20 17:01:27 -05:00
|
|
|
|
items.push(item);
|
|
|
|
|
}
|
2011-05-16 08:33:15 -04:00
|
|
|
|
return items;
|
|
|
|
|
},
|
|
|
|
|
|
2013-03-01 23:24:26 -05:00
|
|
|
|
/**
|
2014-03-04 03:29:28 -05:00
|
|
|
|
* Gives access to the project's configurable options.
|
2013-10-29 14:25:10 -04:00
|
|
|
|
*
|
2013-03-01 23:24:26 -05:00
|
|
|
|
* @type Object
|
2014-03-04 03:29:28 -05:00
|
|
|
|
* @bean
|
|
|
|
|
* @deprecated use {@link PaperScope#settings} instead.
|
2013-03-01 23:24:26 -05:00
|
|
|
|
*/
|
2014-03-04 03:29:28 -05:00
|
|
|
|
getOptions: function() {
|
|
|
|
|
return this._scope.settings;
|
|
|
|
|
},
|
2013-03-01 23:24:26 -05:00
|
|
|
|
|
2011-06-01 05:49:43 -04:00
|
|
|
|
// TODO: Implement setSelectedItems?
|
2011-06-14 10:37:25 -04:00
|
|
|
|
_updateSelection: function(item) {
|
2013-10-18 15:52:22 -04:00
|
|
|
|
var id = item._id,
|
|
|
|
|
selectedItems = this._selectedItems;
|
2011-06-14 10:37:25 -04:00
|
|
|
|
if (item._selected) {
|
2013-10-18 15:52:22 -04:00
|
|
|
|
if (selectedItems[id] !== item) {
|
|
|
|
|
this._selectedItemCount++;
|
|
|
|
|
selectedItems[id] = item;
|
|
|
|
|
}
|
|
|
|
|
} else if (selectedItems[id] === item) {
|
2011-05-16 08:33:15 -04:00
|
|
|
|
this._selectedItemCount--;
|
2013-10-18 15:52:22 -04:00
|
|
|
|
delete selectedItems[id];
|
2011-05-16 08:33:15 -04:00
|
|
|
|
}
|
|
|
|
|
},
|
2011-06-30 06:01:51 -04:00
|
|
|
|
|
2011-05-16 08:33:15 -04:00
|
|
|
|
/**
|
|
|
|
|
* Selects all items in the project.
|
|
|
|
|
*/
|
|
|
|
|
selectAll: function() {
|
2013-10-19 06:27:13 -04:00
|
|
|
|
var layers = this.layers;
|
|
|
|
|
for (var i = 0, l = layers.length; i < l; i++)
|
|
|
|
|
layers[i].setFullySelected(true);
|
2011-05-16 08:33:15 -04:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Deselects all selected items in the project.
|
|
|
|
|
*/
|
|
|
|
|
deselectAll: function() {
|
2013-10-19 06:27:13 -04:00
|
|
|
|
var selectedItems = this._selectedItems;
|
|
|
|
|
for (var i in selectedItems)
|
|
|
|
|
selectedItems[i].setFullySelected(false);
|
2011-05-16 08:33:15 -04:00
|
|
|
|
},
|
2011-05-25 18:54:25 -04:00
|
|
|
|
|
2011-07-31 16:58:51 -04:00
|
|
|
|
/**
|
|
|
|
|
* Perform a hit test on the items contained within the project at the
|
|
|
|
|
* location of the specified point.
|
2014-04-06 07:48:03 -04:00
|
|
|
|
*
|
2013-10-30 11:18:15 -04:00
|
|
|
|
* The options object allows you to control the specifics of the hit test
|
|
|
|
|
* and may contain a combination of the following values:
|
|
|
|
|
* <b>options.tolerance:</b> {@code Number} – the tolerance of the hit test
|
|
|
|
|
* in points, can also be controlled through
|
|
|
|
|
* {@link Project#options}{@code .hitTolerance}.
|
2014-04-13 10:43:20 -04:00
|
|
|
|
* <b>options.class:</b> Only hit test again a certain item class and its
|
|
|
|
|
* sub-classes: {@code Group, Layer, Path, CompoundPath, Shape, Raster,
|
|
|
|
|
* PlacedSymbol, PointText}, etc.
|
2013-10-30 11:18:15 -04:00
|
|
|
|
* <b>options.fill:</b> {@code Boolean} – hit test the fill of items.
|
2014-04-11 08:57:58 -04:00
|
|
|
|
* <b>options.stroke:</b> {@code Boolean} – hit test the stroke of path
|
|
|
|
|
* items, taking into account the setting of stroke color and width.
|
2013-10-30 11:18:15 -04:00
|
|
|
|
* <b>options.segments:</b> {@code Boolean} – hit test for
|
2011-08-01 09:25:46 -04:00
|
|
|
|
* {@link Segment#point} of {@link Path} items.
|
2014-04-11 08:57:58 -04:00
|
|
|
|
* <b>options.curves:</b> {@code Boolean} – hit test the curves of path
|
|
|
|
|
* items, without taking the stroke color or width into account.
|
2013-10-30 11:18:15 -04:00
|
|
|
|
* <b>options.handles:</b> {@code Boolean} – hit test for the handles
|
2011-07-31 16:58:51 -04:00
|
|
|
|
* ({@link Segment#handleIn} / {@link Segment#handleOut}) of path segments.
|
2013-10-30 11:18:15 -04:00
|
|
|
|
* <b>options.ends:</b> {@code Boolean} – only hit test for the first or
|
2011-08-01 09:25:46 -04:00
|
|
|
|
* last segment points of open path items.
|
2013-10-30 11:18:15 -04:00
|
|
|
|
* <b>options.bounds:</b> {@code Boolean} – hit test the corners and
|
2011-08-01 09:25:46 -04:00
|
|
|
|
* side-centers of the bounding rectangle of items ({@link Item#bounds}).
|
2013-10-30 11:18:15 -04:00
|
|
|
|
* <b>options.center:</b> {@code Boolean} – hit test the
|
2011-08-01 09:25:46 -04:00
|
|
|
|
* {@link Rectangle#center} of the bounding rectangle of items
|
|
|
|
|
* ({@link Item#bounds}).
|
2013-10-30 11:18:15 -04:00
|
|
|
|
* <b>options.guides:</b> {@code Boolean} – hit test items that have
|
2011-07-31 16:58:51 -04:00
|
|
|
|
* {@link Item#guide} set to {@code true}.
|
2013-10-30 11:18:15 -04:00
|
|
|
|
* <b>options.selected:</b> {@code Boolean} – only hit selected items.
|
2011-07-31 16:58:51 -04:00
|
|
|
|
*
|
|
|
|
|
* @param {Point} point The point where the hit test should be performed
|
|
|
|
|
* @param {Object} [options={ fill: true, stroke: true, segments: true,
|
|
|
|
|
* tolerance: true }]
|
2013-08-23 22:45:28 -04:00
|
|
|
|
* @return {HitResult} a hit result object that contains more
|
2011-07-31 16:58:51 -04:00
|
|
|
|
* information about what exactly was hit or {@code null} if nothing was
|
2013-08-23 22:45:28 -04:00
|
|
|
|
* hit
|
2011-07-31 16:58:51 -04:00
|
|
|
|
*/
|
2013-12-17 17:28:55 -05:00
|
|
|
|
hitTest: function(/* point, options */) {
|
2012-11-23 15:41:00 -05:00
|
|
|
|
// We don't need to do this here, but it speeds up things since we won't
|
2014-03-18 10:25:25 -04:00
|
|
|
|
// repeatedly convert in Item#hitTest() then.
|
2013-12-17 17:28:55 -05:00
|
|
|
|
var point = Point.read(arguments),
|
|
|
|
|
options = HitResult.getOptions(Base.read(arguments));
|
2011-07-08 15:15:16 -04:00
|
|
|
|
// Loop backwards, so layers that get drawn last are tested first
|
|
|
|
|
for (var i = this.layers.length - 1; i >= 0; i--) {
|
2014-04-29 14:06:48 -04:00
|
|
|
|
var res = this.layers[i]._hitTest(point, options);
|
2011-07-08 17:26:50 -04:00
|
|
|
|
if (res) return res;
|
2011-07-07 16:14:58 -04:00
|
|
|
|
}
|
|
|
|
|
return null;
|
2014-03-18 06:47:50 -04:00
|
|
|
|
},
|
|
|
|
|
|
2014-04-25 11:00:48 -04:00
|
|
|
|
/**
|
|
|
|
|
* Fetch items contained within the project whose properties match the
|
|
|
|
|
* criteria in the specified object.
|
2014-04-27 17:08:42 -04:00
|
|
|
|
* Extended matching is possible by providing a compare function or
|
|
|
|
|
* regular expression. Matching points, colors only work as a comparison
|
|
|
|
|
* of the full object, not partial matching (e.g. only providing the x-
|
|
|
|
|
* coordinate to match all points with that x-value). Partial matching
|
|
|
|
|
* does work for {@link Item#data}.
|
2014-04-25 11:00:48 -04:00
|
|
|
|
*
|
|
|
|
|
* @example {@paperscript} // Fetch all selected path items:
|
|
|
|
|
* var path1 = new Path.Circle({
|
|
|
|
|
* center: [50, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* var path2 = new Path.Circle({
|
|
|
|
|
* center: [150, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Select path2:
|
|
|
|
|
* path2.selected = true;
|
|
|
|
|
*
|
|
|
|
|
* // Fetch all selected path items:
|
|
|
|
|
* var items = project.getItems({
|
|
|
|
|
* selected: true,
|
|
|
|
|
* class: Path
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Change the fill color of the selected path to red:
|
|
|
|
|
* items[0].fillColor = 'red';
|
|
|
|
|
*
|
2014-04-27 17:08:42 -04:00
|
|
|
|
* @example {@paperscript} // Fetch all items with a specific fill color:
|
|
|
|
|
* var path1 = new Path.Circle({
|
|
|
|
|
* center: [50, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* var path2 = new Path.Circle({
|
|
|
|
|
* center: [150, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'purple'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Fetch all items with a purple fill color:
|
|
|
|
|
* var items = project.getItems({
|
|
|
|
|
* fillColor: 'purple'
|
|
|
|
|
* });
|
|
|
|
|
*
|
2014-04-27 17:40:43 -04:00
|
|
|
|
* // Select the fetched item:
|
2014-04-27 17:08:42 -04:00
|
|
|
|
* items[0].selected = true;
|
|
|
|
|
*
|
2014-04-25 11:00:48 -04:00
|
|
|
|
* @example {@paperscript} // Fetch items at a specific position:
|
|
|
|
|
* var path1 = new Path.Circle({
|
|
|
|
|
* center: [50, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* var path2 = new Path.Circle({
|
|
|
|
|
* center: [150, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Fetch all path items positioned at {x: 150, y: 150}:
|
|
|
|
|
* var items = project.getItems({
|
|
|
|
|
* position: [150, 50]
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Select the fetched path:
|
|
|
|
|
* items[0].selected = true;
|
|
|
|
|
*
|
|
|
|
|
* @example {@paperscript} // Fetch items using a comparing function:
|
|
|
|
|
*
|
|
|
|
|
* // Create a circle shaped path:
|
|
|
|
|
* var path1 = new Path.Circle({
|
|
|
|
|
* center: [50, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Create a circle shaped path with 50% opacity:
|
|
|
|
|
* var path2 = new Path.Circle({
|
|
|
|
|
* center: [150, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black',
|
|
|
|
|
* opacity: 0.5
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Fetch all items whose opacity is smaller than 1
|
|
|
|
|
* var items = paper.project.getItems({
|
|
|
|
|
* opacity: function(value) {
|
|
|
|
|
* return value < 1;
|
|
|
|
|
* }
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Select the fetched item:
|
|
|
|
|
* items[0].selected = true;
|
|
|
|
|
*
|
|
|
|
|
* @example {@paperscript} // Fetch items using a comparing function (2):
|
|
|
|
|
*
|
|
|
|
|
* // Create a rectangle shaped path (4 segments):
|
|
|
|
|
* var path1 = new Path.Rectangle({
|
|
|
|
|
* from: [25, 25],
|
|
|
|
|
* to: [75, 75],
|
|
|
|
|
* strokeColor: 'black',
|
|
|
|
|
* strokeWidth: 10
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Create a line shaped path (2 segments):
|
|
|
|
|
* var path2 = new Path.Line({
|
|
|
|
|
* from: [125, 50],
|
|
|
|
|
* to: [175, 50],
|
|
|
|
|
* strokeColor: 'black',
|
|
|
|
|
* strokeWidth: 10
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Fetch all paths with 2 segments:
|
|
|
|
|
* var items = project.getItems({
|
|
|
|
|
* class: Path,
|
|
|
|
|
* segments: function(segments) {
|
|
|
|
|
* return segments.length == 2;
|
|
|
|
|
* }
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Select the fetched path:
|
|
|
|
|
* items[0].selected = true;
|
|
|
|
|
*
|
|
|
|
|
* @example {@paperscript} // Match (nested) properties of the data property:
|
|
|
|
|
*
|
|
|
|
|
* // Create a black circle shaped path:
|
|
|
|
|
* var path1 = new Path.Circle({
|
|
|
|
|
* center: [50, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black',
|
|
|
|
|
* data: {
|
|
|
|
|
* person: {
|
|
|
|
|
* name: 'john',
|
|
|
|
|
* length: 200,
|
|
|
|
|
* hair: true
|
|
|
|
|
* }
|
|
|
|
|
* }
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Create a red circle shaped path:
|
|
|
|
|
* var path2 = new Path.Circle({
|
|
|
|
|
* center: [150, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'red',
|
|
|
|
|
* data: {
|
|
|
|
|
* person: {
|
|
|
|
|
* name: 'john',
|
|
|
|
|
* length: 180,
|
|
|
|
|
* hair: false
|
|
|
|
|
* }
|
|
|
|
|
* }
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Fetch all items whose data object contains a person
|
|
|
|
|
* // object whose name is john and length is 180:
|
|
|
|
|
* var items = paper.project.getItems({
|
|
|
|
|
* data: {
|
|
|
|
|
* person: {
|
|
|
|
|
* name: 'john',
|
|
|
|
|
* length: 180
|
|
|
|
|
* }
|
|
|
|
|
* }
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Select the fetched item:
|
|
|
|
|
* items[0].selected = true;
|
|
|
|
|
*
|
|
|
|
|
* @example {@paperscript} // Match strings using regular expressions:
|
|
|
|
|
*
|
|
|
|
|
* // Create a path named 'aardvark':
|
|
|
|
|
* var path1 = new Path.Circle({
|
|
|
|
|
* center: [50, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black',
|
|
|
|
|
* name: 'aardvark'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Create a path named 'apple':
|
|
|
|
|
* var path2 = new Path.Circle({
|
|
|
|
|
* center: [150, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black',
|
|
|
|
|
* name: 'apple'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Create a path named 'banana':
|
|
|
|
|
* var path2 = new Path.Circle({
|
|
|
|
|
* center: [250, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black',
|
|
|
|
|
* name: 'banana'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Fetch all items that have a name starting with 'a':
|
|
|
|
|
* var items = project.getItems({
|
|
|
|
|
* name: /^a/
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Change the fill color of the matched items:
|
|
|
|
|
* for (var i = 0; i < items.length; i++) {
|
|
|
|
|
* items[i].fillColor = 'red';
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} match The criteria to match against.
|
2014-04-27 17:40:43 -04:00
|
|
|
|
* @return {Item[]}
|
2014-04-25 11:00:48 -04:00
|
|
|
|
*/
|
2014-03-18 06:47:50 -04:00
|
|
|
|
getItems: function(match) {
|
|
|
|
|
return Item._getItems(this.layers, match, true);
|
|
|
|
|
},
|
2011-07-07 16:14:58 -04:00
|
|
|
|
|
2014-04-27 17:40:43 -04:00
|
|
|
|
/**
|
|
|
|
|
* Fetch the first item contained within the project whose properties
|
|
|
|
|
* match the criteria in the specified object.
|
|
|
|
|
* Extended matching is possible by providing a compare function or
|
|
|
|
|
* regular expression. Matching points, colors only work as a comparison
|
|
|
|
|
* of the full object, not partial matching (e.g. only providing the x-
|
|
|
|
|
* coordinate to match all points with that x-value). Partial matching
|
|
|
|
|
* does work for {@link Item#data}.
|
|
|
|
|
*
|
|
|
|
|
* @example {@paperscript} // Fetch all selected path items:
|
|
|
|
|
* var path1 = new Path.Circle({
|
|
|
|
|
* center: [50, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* var path2 = new Path.Circle({
|
|
|
|
|
* center: [150, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Select path2:
|
|
|
|
|
* path2.selected = true;
|
|
|
|
|
*
|
|
|
|
|
* // Fetch first select path items:
|
|
|
|
|
* var item = project.getItem({
|
|
|
|
|
* selected: true,
|
|
|
|
|
* class: Path
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Change the fill color of the selected path to red:
|
|
|
|
|
* item.fillColor = 'red';
|
|
|
|
|
*
|
|
|
|
|
* @example {@paperscript} // Fetch item with a specific fill color:
|
|
|
|
|
* var path1 = new Path.Circle({
|
|
|
|
|
* center: [50, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* var path2 = new Path.Circle({
|
|
|
|
|
* center: [150, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'purple'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Fetch first item with a purple fill color:
|
|
|
|
|
* var item = project.getItem({
|
|
|
|
|
* fillColor: 'purple'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Select the fetched item:
|
|
|
|
|
* item.selected = true;
|
|
|
|
|
*
|
|
|
|
|
* @example {@paperscript} // Fetch item at a specific position:
|
|
|
|
|
* var path1 = new Path.Circle({
|
|
|
|
|
* center: [50, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* var path2 = new Path.Circle({
|
|
|
|
|
* center: [150, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Fetch path item positioned at {x: 150, y: 150}:
|
|
|
|
|
* var item = project.getItem({
|
|
|
|
|
* position: [150, 50]
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Select the fetched path:
|
|
|
|
|
* item.selected = true;
|
|
|
|
|
*
|
|
|
|
|
* @example {@paperscript} // Fetch item using a comparing function:
|
|
|
|
|
*
|
|
|
|
|
* // Create a circle shaped path:
|
|
|
|
|
* var path1 = new Path.Circle({
|
|
|
|
|
* center: [50, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Create a circle shaped path with 50% opacity:
|
|
|
|
|
* var path2 = new Path.Circle({
|
|
|
|
|
* center: [150, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black',
|
|
|
|
|
* opacity: 0.5
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Fetch first item whose opacity is smaller than 1
|
|
|
|
|
* var item = paper.project.getItem({
|
|
|
|
|
* opacity: function(value) {
|
|
|
|
|
* return value < 1;
|
|
|
|
|
* }
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Select the fetched item:
|
|
|
|
|
* item.selected = true;
|
|
|
|
|
*
|
|
|
|
|
* @example {@paperscript} // Fetch item using a comparing function (2):
|
|
|
|
|
*
|
|
|
|
|
* // Create a rectangle shaped path (4 segments):
|
|
|
|
|
* var path1 = new Path.Rectangle({
|
|
|
|
|
* from: [25, 25],
|
|
|
|
|
* to: [75, 75],
|
|
|
|
|
* strokeColor: 'black',
|
|
|
|
|
* strokeWidth: 10
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Create a line shaped path (2 segments):
|
|
|
|
|
* var path2 = new Path.Line({
|
|
|
|
|
* from: [125, 50],
|
|
|
|
|
* to: [175, 50],
|
|
|
|
|
* strokeColor: 'black',
|
|
|
|
|
* strokeWidth: 10
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Fetch first path with 2 segments:
|
|
|
|
|
* var item = project.getItem({
|
|
|
|
|
* class: Path,
|
|
|
|
|
* segments: function(segments) {
|
|
|
|
|
* return segments.length == 2;
|
|
|
|
|
* }
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Select the fetched path:
|
|
|
|
|
* item.selected = true;
|
|
|
|
|
*
|
|
|
|
|
* @example {@paperscript} // Match (nested) properties of the data property:
|
|
|
|
|
*
|
|
|
|
|
* // Create a black circle shaped path:
|
|
|
|
|
* var path1 = new Path.Circle({
|
|
|
|
|
* center: [50, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black',
|
|
|
|
|
* data: {
|
|
|
|
|
* person: {
|
|
|
|
|
* name: 'john',
|
|
|
|
|
* length: 200,
|
|
|
|
|
* hair: true
|
|
|
|
|
* }
|
|
|
|
|
* }
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Create a red circle shaped path:
|
|
|
|
|
* var path2 = new Path.Circle({
|
|
|
|
|
* center: [150, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'red',
|
|
|
|
|
* data: {
|
|
|
|
|
* person: {
|
|
|
|
|
* name: 'john',
|
|
|
|
|
* length: 180,
|
|
|
|
|
* hair: false
|
|
|
|
|
* }
|
|
|
|
|
* }
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Fetch item whose data object contains a person
|
|
|
|
|
* // object whose name is john and length is 180:
|
|
|
|
|
* var item = paper.project.getItem({
|
|
|
|
|
* data: {
|
|
|
|
|
* person: {
|
|
|
|
|
* name: 'john',
|
|
|
|
|
* length: 180
|
|
|
|
|
* }
|
|
|
|
|
* }
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Select the fetched item:
|
|
|
|
|
* item.selected = true;
|
|
|
|
|
*
|
|
|
|
|
* @example {@paperscript} // Match strings using regular expressions:
|
|
|
|
|
*
|
|
|
|
|
* // Create a path named 'aardvark':
|
|
|
|
|
* var path1 = new Path.Circle({
|
|
|
|
|
* center: [50, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black',
|
|
|
|
|
* name: 'aardvark'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Create a path named 'apple':
|
|
|
|
|
* var path2 = new Path.Circle({
|
|
|
|
|
* center: [150, 50],
|
|
|
|
|
* radius: 25,
|
|
|
|
|
* fillColor: 'black',
|
|
|
|
|
* name: 'apple'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Fetch the first item that has a name starting with 'a':
|
|
|
|
|
* var item = project.getItem({
|
|
|
|
|
* name: /^a/
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // Change the fill color of the matched item:
|
|
|
|
|
* item.fillColor = 'red';
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} match The criteria to match against.
|
|
|
|
|
* @return {Item}
|
|
|
|
|
*/
|
2014-03-18 06:47:50 -04:00
|
|
|
|
getItem: function(match) {
|
|
|
|
|
return Item._getItems(this.layers, match, false);
|
|
|
|
|
},
|
2013-10-19 07:02:53 -04:00
|
|
|
|
|
2013-06-27 21:03:49 -04:00
|
|
|
|
/**
|
2013-10-30 11:18:59 -04:00
|
|
|
|
* {@grouptitle Importing / Exporting JSON and SVG}
|
2013-06-27 21:03:49 -04:00
|
|
|
|
*
|
|
|
|
|
* Exports (serializes) the project with all its layers and child items to
|
|
|
|
|
* a JSON data string.
|
|
|
|
|
*
|
2013-10-30 11:18:59 -04:00
|
|
|
|
* The options object offers control over some aspects of the SVG export:
|
2014-03-18 10:25:25 -04:00
|
|
|
|
* <b>options.asString:</b> {@code Boolean} – whether the JSON is returned
|
|
|
|
|
* as a {@code Object} or a {@code String}.
|
2013-10-30 11:18:59 -04:00
|
|
|
|
* <b>options.precision:</b> {@code Number} – the amount of fractional
|
|
|
|
|
* digits in numbers used in JSON data.
|
|
|
|
|
*
|
2013-06-27 21:03:49 -04:00
|
|
|
|
* @name Project#exportJSON
|
|
|
|
|
* @function
|
2013-12-30 17:34:19 -05:00
|
|
|
|
* @param {Object} [options={ asString: true, precision: 5 }] the
|
|
|
|
|
* serialization options
|
2013-06-27 21:03:49 -04:00
|
|
|
|
* @return {String} the exported JSON data
|
|
|
|
|
*/
|
2013-02-25 19:17:33 -05:00
|
|
|
|
|
2013-06-27 21:03:49 -04:00
|
|
|
|
/**
|
2013-10-30 11:18:59 -04:00
|
|
|
|
* Imports (deserializes) the stored JSON data into the project.
|
|
|
|
|
* Note that the project is not cleared first. You can call
|
|
|
|
|
* {@link Project#clear()} to do so.
|
2013-06-27 21:03:49 -04:00
|
|
|
|
*
|
|
|
|
|
* @param {String} json the JSON data to import from.
|
|
|
|
|
*/
|
2013-04-23 10:13:51 -04:00
|
|
|
|
importJSON: function(json) {
|
2013-05-28 02:48:16 -04:00
|
|
|
|
this.activate();
|
2013-11-24 10:25:13 -05:00
|
|
|
|
// Provide the activeLayer as a possible target for layers, but only if
|
|
|
|
|
// it's empty.
|
|
|
|
|
var layer = this.activeLayer;
|
|
|
|
|
return Base.importJSON(json, layer && layer.isEmpty() && layer);
|
2013-02-25 19:17:33 -05:00
|
|
|
|
},
|
|
|
|
|
|
2013-06-27 21:03:49 -04:00
|
|
|
|
/**
|
|
|
|
|
* Exports the project with all its layers and child items as an SVG DOM,
|
|
|
|
|
* all contained in one top level SVG group node.
|
|
|
|
|
*
|
2013-10-30 11:18:59 -04:00
|
|
|
|
* The options object offers control over some aspects of the SVG export:
|
2014-03-18 10:25:25 -04:00
|
|
|
|
* <b>options.asString:</b> {@code Boolean} – whether a SVG node or a
|
2013-12-30 17:34:19 -05:00
|
|
|
|
* {@code String} is to be returned.
|
2013-10-30 11:18:59 -04:00
|
|
|
|
* <b>options.precision:</b> {@code Number} – the amount of fractional
|
|
|
|
|
* digits in numbers used in SVG data.
|
2014-03-18 10:25:25 -04:00
|
|
|
|
* <b>options.matchShapes:</b> {@code Boolean} – whether imported path
|
2013-10-30 11:18:59 -04:00
|
|
|
|
* items should tried to be converted to shape items, if their geometries
|
|
|
|
|
* match.
|
|
|
|
|
*
|
2013-06-27 21:03:49 -04:00
|
|
|
|
* @name Project#exportSVG
|
|
|
|
|
* @function
|
2013-10-30 11:18:59 -04:00
|
|
|
|
* @param {Object} [options={ asString: false, precision: 5,
|
|
|
|
|
* matchShapes: false }] the export options.
|
2014-04-28 12:23:14 -04:00
|
|
|
|
* @return {SVGElement} the project converted to an SVG node
|
2013-06-27 21:03:49 -04:00
|
|
|
|
*/
|
|
|
|
|
|
2014-02-12 03:39:34 -05:00
|
|
|
|
// DOCS: Document importSVG('file.svg', callback);
|
2013-06-27 21:03:49 -04:00
|
|
|
|
/**
|
2013-10-20 11:14:14 -04:00
|
|
|
|
* Converts the provided SVG content into Paper.js items and adds them to
|
|
|
|
|
* the active layer of this project.
|
2013-10-30 11:18:59 -04:00
|
|
|
|
* Note that the project is not cleared first. You can call
|
|
|
|
|
* {@link Project#clear()} to do so.
|
|
|
|
|
*
|
|
|
|
|
* The options object offers control over some aspects of the SVG import:
|
2014-03-18 10:25:25 -04:00
|
|
|
|
* <b>options.expandShapes:</b> {@code Boolean} – whether imported shape
|
2013-10-30 11:18:59 -04:00
|
|
|
|
* items should be expanded to path items.
|
2013-06-27 21:03:49 -04:00
|
|
|
|
*
|
|
|
|
|
* @name Project#importSVG
|
|
|
|
|
* @function
|
2014-04-28 12:23:14 -04:00
|
|
|
|
* @param {SVGElement|String} svg the SVG content to import
|
2013-10-30 11:18:59 -04:00
|
|
|
|
* @param {Object} [options={ expandShapes: false }] the import options
|
2013-06-27 21:03:49 -04:00
|
|
|
|
* @return {Item} the imported Paper.js parent item
|
|
|
|
|
*/
|
|
|
|
|
|
2011-05-25 18:54:25 -04:00
|
|
|
|
/**
|
|
|
|
|
* {@grouptitle Project Hierarchy}
|
2011-06-30 06:01:51 -04:00
|
|
|
|
*
|
2011-05-25 18:57:58 -04:00
|
|
|
|
* The layers contained within the project.
|
2011-06-30 06:01:51 -04:00
|
|
|
|
*
|
2011-05-25 18:54:25 -04:00
|
|
|
|
* @name Project#layers
|
2011-05-26 10:49:19 -04:00
|
|
|
|
* @type Layer[]
|
2011-05-25 18:54:25 -04:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2011-05-25 18:57:58 -04:00
|
|
|
|
* The layer which is currently active. New items will be created on this
|
2011-05-25 18:54:25 -04:00
|
|
|
|
* layer by default.
|
2011-06-30 06:01:51 -04:00
|
|
|
|
*
|
2011-05-25 18:54:25 -04:00
|
|
|
|
* @name Project#activeLayer
|
|
|
|
|
* @type Layer
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2011-05-25 18:57:58 -04:00
|
|
|
|
* The symbols contained within the project.
|
2011-06-30 06:01:51 -04:00
|
|
|
|
*
|
2011-05-25 18:54:25 -04:00
|
|
|
|
* @name Project#symbols
|
2011-05-26 10:49:19 -04:00
|
|
|
|
* @type Symbol[]
|
2011-05-25 18:54:25 -04:00
|
|
|
|
*/
|
|
|
|
|
|
2014-02-26 10:19:48 -05:00
|
|
|
|
draw: function(ctx, matrix, pixelRatio) {
|
2013-12-09 01:51:28 -05:00
|
|
|
|
// Increase the _updateVersion before the draw-loop. After that, items
|
|
|
|
|
// that are visible will have their _updateVersion set to the new value.
|
|
|
|
|
this._updateVersion++;
|
2011-05-16 08:33:15 -04:00
|
|
|
|
ctx.save();
|
2013-04-09 21:52:47 -04:00
|
|
|
|
matrix.applyToContext(ctx);
|
2013-11-28 16:20:00 -05:00
|
|
|
|
// Use new Base() so we can use param.extend() to easily override
|
2013-06-11 23:40:44 -04:00
|
|
|
|
// values
|
2013-11-28 16:20:00 -05:00
|
|
|
|
var param = new Base({
|
2013-04-09 21:52:47 -04:00
|
|
|
|
offset: new Point(0, 0),
|
2014-02-26 10:19:48 -05:00
|
|
|
|
pixelRatio: pixelRatio,
|
2014-04-07 11:35:17 -04:00
|
|
|
|
viewMatrix: matrix.isIdentity() ? null : matrix,
|
|
|
|
|
matrices: [new Matrix()], // Start with the identity matrix.
|
|
|
|
|
// Tell the drawing routine that we want to keep _globalMatrix up to
|
|
|
|
|
// date. Item#rasterize() and Raster#getAverageColor() should not
|
|
|
|
|
// set this.
|
|
|
|
|
updateMatrix: true
|
2013-06-11 23:40:44 -04:00
|
|
|
|
});
|
2014-04-10 16:28:21 -04:00
|
|
|
|
for (var i = 0, layers = this.layers, l = layers.length; i < l; i++)
|
|
|
|
|
layers[i].draw(ctx, param);
|
2011-05-16 08:33:15 -04:00
|
|
|
|
ctx.restore();
|
|
|
|
|
|
|
|
|
|
// Draw the selection of the selected items in the project:
|
|
|
|
|
if (this._selectedItemCount > 0) {
|
|
|
|
|
ctx.save();
|
|
|
|
|
ctx.strokeWidth = 1;
|
2014-04-29 12:52:10 -04:00
|
|
|
|
var items = this._selectedItems,
|
|
|
|
|
size = this._scope.settings.handleSize,
|
|
|
|
|
updateVersion = this._updateVersion;
|
|
|
|
|
for (var id in items)
|
|
|
|
|
items[id]._drawSelection(ctx, matrix, size, updateVersion);
|
2011-05-16 08:33:15 -04:00
|
|
|
|
ctx.restore();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|