Prebuilt module for commit 036f4f924e420d659e8b763e506df1594613a39f

This commit is contained in:
Paper.js Bot 2017-04-21 23:03:12 +00:00
parent 3945f012a5
commit f89cb03eb0
7 changed files with 327 additions and 183 deletions

View file

@ -51,17 +51,17 @@ generally not recommended to install Node.js through OS-supplied package
managers, as the its development cycles move fast and these versions are often managers, as the its development cycles move fast and these versions are often
out-of-date. out-of-date.
On macOS, [Homebrew](http://brew.sh/) is a good option if one version of
Node.js that is kept up to date with `brew upgrade` is enough:
<http://treehouse.github.io/installation-guides/mac/node-mac.html>
[NVM](https://github.com/creationix/nvm) can be used instead to install and [NVM](https://github.com/creationix/nvm) can be used instead to install and
maintain multiple versions of Node.js on the same platform, as often required by maintain multiple versions of Node.js on the same platform, as often required by
different projects: different projects:
<https://nodesource.com/blog/installing-node-js-tutorial-using-nvm-on-mac-os-x-and-ubuntu/> <https://nodesource.com/blog/installing-node-js-tutorial-using-nvm-on-mac-os-x-and-ubuntu/>
on OSX, [Homebrew](http://brew.sh/) is also a good option if one version of Homebrew is recommended on macOS also if you intend to install Paper.js with
Node.js that is kept up to date with `brew update` is enough: rendering to the Canvas on Node.js, as described in the next paragraph.
<http://treehouse.github.io/installation-guides/mac/node-mac.html>
Homebrew is recommended on OSX also if you intend to install Paper.js for
Node.js, as described in the next paragraph.
For Linux, see <http://nodejs.org/download/> to locate 32-bit and 64-bit Node.js For Linux, see <http://nodejs.org/download/> to locate 32-bit and 64-bit Node.js
binaries as well as sources, or use NVM, as described in the paragraph above. binaries as well as sources, or use NVM, as described in the paragraph above.
@ -83,14 +83,14 @@ different one:
In order to install `paper-jsdom-canvas`, you need the [Cairo Graphics In order to install `paper-jsdom-canvas`, you need the [Cairo Graphics
library](http://cairographics.org/) installed in your system: library](http://cairographics.org/) installed in your system:
##### Installing Cairo and Pango on OSX: ##### Installing Cairo and Pango on macOS:
The easiest way to install Cairo is through [Homebrew](http://brew.sh/), by The easiest way to install Cairo is through [Homebrew](http://brew.sh/), by
issuing the command: issuing the command:
brew install cairo pango brew install cairo pango
Note that currently there is an issue on OSX with Cairo. If the above causes Note that currently there is an issue on macOS with Cairo. If the above causes
errors, the following will most likely fix it: errors, the following will most likely fix it:
PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ npm install paper PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ npm install paper

View file

@ -9,7 +9,7 @@
* *
* All rights reserved. * All rights reserved.
* *
* Date: Fri Apr 21 12:54:40 2017 +0200 * Date: Sat Apr 22 00:58:54 2017 +0200
* *
*** ***
* *
@ -2262,7 +2262,7 @@ var Matrix = Base.extend({
return this.shear(shear, center); return this.shear(shear, center);
}, },
append: function(mx) { append: function(mx, _dontNotify) {
if (mx) { if (mx) {
var a1 = this._a, var a1 = this._a,
b1 = this._b, b1 = this._b,
@ -2280,12 +2280,13 @@ var Matrix = Base.extend({
this._d = b2 * b1 + d2 * d1; this._d = b2 * b1 + d2 * d1;
this._tx += tx2 * a1 + ty2 * c1; this._tx += tx2 * a1 + ty2 * c1;
this._ty += tx2 * b1 + ty2 * d1; this._ty += tx2 * b1 + ty2 * d1;
this._changed(); if (!_dontNotify)
this._changed();
} }
return this; return this;
}, },
prepend: function(mx) { prepend: function(mx, _dontNotify) {
if (mx) { if (mx) {
var a1 = this._a, var a1 = this._a,
b1 = this._b, b1 = this._b,
@ -2305,7 +2306,8 @@ var Matrix = Base.extend({
this._d = c2 * c1 + d2 * d1; this._d = c2 * c1 + d2 * d1;
this._tx = a2 * tx1 + b2 * ty1 + tx2; this._tx = a2 * tx1 + b2 * ty1 + tx2;
this._ty = c2 * tx1 + d2 * ty1 + ty2; this._ty = c2 * tx1 + d2 * ty1 + ty2;
this._changed(); if (!_dontNotify)
this._changed();
} }
return this; return this;
}, },
@ -3236,11 +3238,11 @@ new function() {
this._boundsOptions); this._boundsOptions);
if (!opts.stroke || this.getStrokeScaling()) if (!opts.stroke || this.getStrokeScaling())
opts.cacheItem = this; opts.cacheItem = this;
var bounds = this._getCachedBounds(hasMatrix && matrix, opts); var rect = this._getCachedBounds(hasMatrix && matrix, opts).rect;
return !arguments.length return !arguments.length
? new LinkedRectangle(bounds.x, bounds.y, bounds.width, ? new LinkedRectangle(rect.x, rect.y, rect.width, rect.height,
bounds.height, this, 'setBounds') this, 'setBounds')
: bounds; : rect;
}, },
setBounds: function() { setBounds: function() {
@ -3273,29 +3275,49 @@ new function() {
return Item._getBounds(children, matrix, options); return Item._getBounds(children, matrix, options);
}, },
_getBoundsCacheKey: function(options, internal) {
return [
options.stroke ? 1 : 0,
options.handle ? 1 : 0,
internal ? 1 : 0
].join('');
},
_getCachedBounds: function(matrix, options, noInternal) { _getCachedBounds: function(matrix, options, noInternal) {
matrix = matrix && matrix._orNullIfIdentity(); matrix = matrix && matrix._orNullIfIdentity();
var internal = options.internal && !noInternal, var internal = options.internal && !noInternal,
cacheItem = options.cacheItem, cacheItem = options.cacheItem,
_matrix = internal ? null : this._matrix._orNullIfIdentity(), _matrix = internal ? null : this._matrix._orNullIfIdentity(),
cacheKey = cacheItem && (!matrix || matrix.equals(_matrix)) && [ cacheKey = cacheItem && (!matrix || matrix.equals(_matrix))
options.stroke ? 1 : 0, && this._getBoundsCacheKey(options, internal),
options.handle ? 1 : 0, bounds = this._bounds;
internal ? 1 : 0
].join('');
Item._updateBoundsCache(this._parent || this._symbol, cacheItem); Item._updateBoundsCache(this._parent || this._symbol, cacheItem);
if (cacheKey && this._bounds && cacheKey in this._bounds) if (cacheKey && bounds && cacheKey in bounds) {
return this._bounds[cacheKey].rect.clone(); var cached = bounds[cacheKey];
var bounds = this._getBounds(matrix || _matrix, options); return {
rect: cached.rect.clone(),
nonscaling: cached.nonscaling
};
}
var res = this._getBounds(matrix || _matrix, options),
rect = res.rect || res,
style = this._style,
nonscaling = res.nonscaling || style.hasStroke()
&& !style.getStrokeScaling();
if (cacheKey) { if (cacheKey) {
if (!this._bounds) if (!bounds) {
this._bounds = {}; this._bounds = bounds = {};
var cached = this._bounds[cacheKey] = { }
rect: bounds.clone(), var cached = bounds[cacheKey] = {
rect: rect.clone(),
nonscaling: nonscaling,
internal: internal internal: internal
}; };
} }
return bounds; return {
rect: rect,
nonscaling: nonscaling
};
}, },
_getStrokeMatrix: function(matrix, options) { _getStrokeMatrix: function(matrix, options) {
@ -3340,22 +3362,29 @@ new function() {
var x1 = Infinity, var x1 = Infinity,
x2 = -x1, x2 = -x1,
y1 = x1, y1 = x1,
y2 = x2; y2 = x2,
nonscaling = false;
options = options || {}; options = options || {};
for (var i = 0, l = items.length; i < l; i++) { for (var i = 0, l = items.length; i < l; i++) {
var item = items[i]; var item = items[i];
if (item._visible && !item.isEmpty()) { if (item._visible && !item.isEmpty()) {
var rect = item._getCachedBounds( var bounds = item._getCachedBounds(
matrix && matrix.appended(item._matrix), options, true); matrix && matrix.appended(item._matrix), options, true),
rect = bounds.rect;
x1 = Math.min(rect.x, x1); x1 = Math.min(rect.x, x1);
y1 = Math.min(rect.y, y1); y1 = Math.min(rect.y, y1);
x2 = Math.max(rect.x + rect.width, x2); x2 = Math.max(rect.x + rect.width, x2);
y2 = Math.max(rect.y + rect.height, y2); y2 = Math.max(rect.y + rect.height, y2);
if (bounds.nonscaling)
nonscaling = true;
} }
} }
return isFinite(x1) return {
rect: isFinite(x1)
? new Rectangle(x1, y1, x2 - x1, y2 - y1) ? new Rectangle(x1, y1, x2 - x1, y2 - y1)
: new Rectangle(); : new Rectangle(),
nonscaling: nonscaling
};
} }
} }
@ -4218,8 +4247,6 @@ new function() {
transform: function(matrix, _applyMatrix, _applyRecursively, transform: function(matrix, _applyMatrix, _applyRecursively,
_setApplyMatrix) { _setApplyMatrix) {
if (matrix && matrix.isIdentity())
matrix = null;
var _matrix = this._matrix, var _matrix = this._matrix,
transform = matrix && !matrix.isIdentity(), transform = matrix && !matrix.isIdentity(),
applyMatrix = (_applyMatrix || this._applyMatrix) applyMatrix = (_applyMatrix || this._applyMatrix)
@ -4230,7 +4257,14 @@ new function() {
if (transform) { if (transform) {
if (!matrix.isInvertible() && _matrix.isInvertible()) if (!matrix.isInvertible() && _matrix.isInvertible())
_matrix._backup = _matrix.getValues(); _matrix._backup = _matrix.getValues();
_matrix.prepend(matrix); _matrix.prepend(matrix, true);
var style = this._style,
fillColor = style.getFillColor(true),
strokeColor = style.getStrokeColor(true);
if (fillColor)
fillColor.transform(matrix);
if (strokeColor)
strokeColor.transform(matrix);
} }
if (applyMatrix) { if (applyMatrix) {
if (this._transformContent(_matrix, _applyRecursively, if (this._transformContent(_matrix, _applyRecursively,
@ -4245,33 +4279,46 @@ new function() {
applyMatrix = transform = false; applyMatrix = transform = false;
} }
} }
if (transform) {
var style = this._style,
fillColor = style.getFillColor(true),
strokeColor = style.getStrokeColor(true);
if (fillColor)
fillColor.transform(matrix);
if (strokeColor)
strokeColor.transform(matrix);
}
var bounds = this._bounds, var bounds = this._bounds,
position = this._position; position = this._position,
this._changed(9); decomposed = this._decomposed;
var decomp = bounds && matrix && matrix.decompose(); if (transform || applyMatrix) {
if (decomp && !decomp.shearing && decomp.rotation % 90 === 0) { this._changed(9);
}
var decomp = transform && (bounds || decomposed) && matrix.decompose();
if (decomposed && decomp) {
decomposed.translation = decomposed.translation.add(
decomp.translation);
decomposed.rotation += decomp.rotation;
decomposed.scaling = decomposed.scaling.multiply(decomp.scaling);
decomposed.skewing = decomposed.skewing.add(decomp.skewing);
}
if (decomp || !transform) {
this._decomposed = decomposed;
}
if (!transform) {
if (!applyMatrix) {
this._bounds = bounds;
}
this._position = position;
} else if (bounds && decomp && decomp.skewing.isZero()
&& decomp.rotation % 90 === 0) {
for (var key in bounds) { for (var key in bounds) {
var cache = bounds[key]; var cache = bounds[key];
if (applyMatrix || !cache.internal) { if (true || cache.nonscaling) {
delete bounds[key];
} else if (applyMatrix || !cache.internal) {
var rect = cache.rect; var rect = cache.rect;
matrix._transformBounds(rect, rect); matrix._transformBounds(rect, rect);
} }
} }
var getter = this._boundsGetter,
rect = bounds[getter && getter.getBounds || getter || 'getBounds'];
if (rect)
this._position = rect.getCenter(true);
this._bounds = bounds; this._bounds = bounds;
} else if (matrix && position) { var cached = bounds[this._getBoundsCacheKey(
this._boundsOptions || {})];
if (cached) {
this._position = cached.rect.getCenter(true);
}
} else if (position && this._pivot) {
this._position = matrix._transformPoint(position, position); this._position = matrix._transformPoint(position, position);
} }
return this; return this;
@ -11016,10 +11063,10 @@ var PointText = TextItem.extend({
x = 0; x = 0;
if (justification !== 'left') if (justification !== 'left')
x -= width / (justification === 'center' ? 2: 1); x -= width / (justification === 'center' ? 2: 1);
var bounds = new Rectangle(x, var rect = new Rectangle(x,
numLines ? - 0.75 * leading : 0, numLines ? - 0.75 * leading : 0,
width, numLines * leading); width, numLines * leading);
return matrix ? matrix._transformBounds(bounds, bounds) : bounds; return matrix ? matrix._transformBounds(rect, rect) : rect;
} }
}); });
@ -13807,9 +13854,9 @@ new function() {
if (!Numerical.isZero(scale.x - 1) if (!Numerical.isZero(scale.x - 1)
|| !Numerical.isZero(scale.y - 1)) || !Numerical.isZero(scale.y - 1))
parts.push('scale(' + formatter.point(scale) +')'); parts.push('scale(' + formatter.point(scale) +')');
if (skew && skew.x) if (skew.x)
parts.push('skewX(' + formatter.number(skew.x) + ')'); parts.push('skewX(' + formatter.number(skew.x) + ')');
if (skew && skew.y) if (skew.y)
parts.push('skewY(' + formatter.number(skew.y) + ')'); parts.push('skewY(' + formatter.number(skew.y) + ')');
attrs.transform = parts.join(' '); attrs.transform = parts.join(' ');
} else { } else {
@ -14142,6 +14189,7 @@ new function() {
? new Rectangle([0, 0], view.getViewSize()) ? new Rectangle([0, 0], view.getViewSize())
: bounds === 'content' : bounds === 'content'
? Item._getBounds(children, matrix, { stroke: true }) ? Item._getBounds(children, matrix, { stroke: true })
.rect
: Rectangle.read([bounds], 0, { readNull: true }), : Rectangle.read([bounds], 0, { readNull: true }),
attrs = { attrs = {
version: '1.1', version: '1.1',

View file

@ -1641,7 +1641,7 @@ Array of <tt>Number</tt>s
</div> </div>
<div class="member-description hidden"> <div class="member-description hidden">
<div class="member-text"> <div class="member-text">
<p>Attempts to decompose the affine transformation described by this matrix into <code>scaling</code>, <code>rotation</code> and <code>shearing</code>, and returns an object with these properties if it succeeded, <code>null</code> otherwise.</p> <p>Attempts to decompose the affine transformation described by this matrix into <code>scaling</code>, <code>rotation</code> and <code>skewing</code>, and returns an object with these properties if it succeeded, <code>null</code> otherwise.</p>

154
dist/paper-core.js vendored
View file

@ -9,7 +9,7 @@
* *
* All rights reserved. * All rights reserved.
* *
* Date: Fri Apr 21 12:54:40 2017 +0200 * Date: Sat Apr 22 00:58:54 2017 +0200
* *
*** ***
* *
@ -2262,7 +2262,7 @@ var Matrix = Base.extend({
return this.shear(shear, center); return this.shear(shear, center);
}, },
append: function(mx) { append: function(mx, _dontNotify) {
if (mx) { if (mx) {
var a1 = this._a, var a1 = this._a,
b1 = this._b, b1 = this._b,
@ -2280,12 +2280,13 @@ var Matrix = Base.extend({
this._d = b2 * b1 + d2 * d1; this._d = b2 * b1 + d2 * d1;
this._tx += tx2 * a1 + ty2 * c1; this._tx += tx2 * a1 + ty2 * c1;
this._ty += tx2 * b1 + ty2 * d1; this._ty += tx2 * b1 + ty2 * d1;
this._changed(); if (!_dontNotify)
this._changed();
} }
return this; return this;
}, },
prepend: function(mx) { prepend: function(mx, _dontNotify) {
if (mx) { if (mx) {
var a1 = this._a, var a1 = this._a,
b1 = this._b, b1 = this._b,
@ -2305,7 +2306,8 @@ var Matrix = Base.extend({
this._d = c2 * c1 + d2 * d1; this._d = c2 * c1 + d2 * d1;
this._tx = a2 * tx1 + b2 * ty1 + tx2; this._tx = a2 * tx1 + b2 * ty1 + tx2;
this._ty = c2 * tx1 + d2 * ty1 + ty2; this._ty = c2 * tx1 + d2 * ty1 + ty2;
this._changed(); if (!_dontNotify)
this._changed();
} }
return this; return this;
}, },
@ -3236,11 +3238,11 @@ new function() {
this._boundsOptions); this._boundsOptions);
if (!opts.stroke || this.getStrokeScaling()) if (!opts.stroke || this.getStrokeScaling())
opts.cacheItem = this; opts.cacheItem = this;
var bounds = this._getCachedBounds(hasMatrix && matrix, opts); var rect = this._getCachedBounds(hasMatrix && matrix, opts).rect;
return !arguments.length return !arguments.length
? new LinkedRectangle(bounds.x, bounds.y, bounds.width, ? new LinkedRectangle(rect.x, rect.y, rect.width, rect.height,
bounds.height, this, 'setBounds') this, 'setBounds')
: bounds; : rect;
}, },
setBounds: function() { setBounds: function() {
@ -3273,29 +3275,49 @@ new function() {
return Item._getBounds(children, matrix, options); return Item._getBounds(children, matrix, options);
}, },
_getBoundsCacheKey: function(options, internal) {
return [
options.stroke ? 1 : 0,
options.handle ? 1 : 0,
internal ? 1 : 0
].join('');
},
_getCachedBounds: function(matrix, options, noInternal) { _getCachedBounds: function(matrix, options, noInternal) {
matrix = matrix && matrix._orNullIfIdentity(); matrix = matrix && matrix._orNullIfIdentity();
var internal = options.internal && !noInternal, var internal = options.internal && !noInternal,
cacheItem = options.cacheItem, cacheItem = options.cacheItem,
_matrix = internal ? null : this._matrix._orNullIfIdentity(), _matrix = internal ? null : this._matrix._orNullIfIdentity(),
cacheKey = cacheItem && (!matrix || matrix.equals(_matrix)) && [ cacheKey = cacheItem && (!matrix || matrix.equals(_matrix))
options.stroke ? 1 : 0, && this._getBoundsCacheKey(options, internal),
options.handle ? 1 : 0, bounds = this._bounds;
internal ? 1 : 0
].join('');
Item._updateBoundsCache(this._parent || this._symbol, cacheItem); Item._updateBoundsCache(this._parent || this._symbol, cacheItem);
if (cacheKey && this._bounds && cacheKey in this._bounds) if (cacheKey && bounds && cacheKey in bounds) {
return this._bounds[cacheKey].rect.clone(); var cached = bounds[cacheKey];
var bounds = this._getBounds(matrix || _matrix, options); return {
rect: cached.rect.clone(),
nonscaling: cached.nonscaling
};
}
var res = this._getBounds(matrix || _matrix, options),
rect = res.rect || res,
style = this._style,
nonscaling = res.nonscaling || style.hasStroke()
&& !style.getStrokeScaling();
if (cacheKey) { if (cacheKey) {
if (!this._bounds) if (!bounds) {
this._bounds = {}; this._bounds = bounds = {};
var cached = this._bounds[cacheKey] = { }
rect: bounds.clone(), var cached = bounds[cacheKey] = {
rect: rect.clone(),
nonscaling: nonscaling,
internal: internal internal: internal
}; };
} }
return bounds; return {
rect: rect,
nonscaling: nonscaling
};
}, },
_getStrokeMatrix: function(matrix, options) { _getStrokeMatrix: function(matrix, options) {
@ -3340,22 +3362,29 @@ new function() {
var x1 = Infinity, var x1 = Infinity,
x2 = -x1, x2 = -x1,
y1 = x1, y1 = x1,
y2 = x2; y2 = x2,
nonscaling = false;
options = options || {}; options = options || {};
for (var i = 0, l = items.length; i < l; i++) { for (var i = 0, l = items.length; i < l; i++) {
var item = items[i]; var item = items[i];
if (item._visible && !item.isEmpty()) { if (item._visible && !item.isEmpty()) {
var rect = item._getCachedBounds( var bounds = item._getCachedBounds(
matrix && matrix.appended(item._matrix), options, true); matrix && matrix.appended(item._matrix), options, true),
rect = bounds.rect;
x1 = Math.min(rect.x, x1); x1 = Math.min(rect.x, x1);
y1 = Math.min(rect.y, y1); y1 = Math.min(rect.y, y1);
x2 = Math.max(rect.x + rect.width, x2); x2 = Math.max(rect.x + rect.width, x2);
y2 = Math.max(rect.y + rect.height, y2); y2 = Math.max(rect.y + rect.height, y2);
if (bounds.nonscaling)
nonscaling = true;
} }
} }
return isFinite(x1) return {
rect: isFinite(x1)
? new Rectangle(x1, y1, x2 - x1, y2 - y1) ? new Rectangle(x1, y1, x2 - x1, y2 - y1)
: new Rectangle(); : new Rectangle(),
nonscaling: nonscaling
};
} }
} }
@ -4218,8 +4247,6 @@ new function() {
transform: function(matrix, _applyMatrix, _applyRecursively, transform: function(matrix, _applyMatrix, _applyRecursively,
_setApplyMatrix) { _setApplyMatrix) {
if (matrix && matrix.isIdentity())
matrix = null;
var _matrix = this._matrix, var _matrix = this._matrix,
transform = matrix && !matrix.isIdentity(), transform = matrix && !matrix.isIdentity(),
applyMatrix = (_applyMatrix || this._applyMatrix) applyMatrix = (_applyMatrix || this._applyMatrix)
@ -4230,7 +4257,14 @@ new function() {
if (transform) { if (transform) {
if (!matrix.isInvertible() && _matrix.isInvertible()) if (!matrix.isInvertible() && _matrix.isInvertible())
_matrix._backup = _matrix.getValues(); _matrix._backup = _matrix.getValues();
_matrix.prepend(matrix); _matrix.prepend(matrix, true);
var style = this._style,
fillColor = style.getFillColor(true),
strokeColor = style.getStrokeColor(true);
if (fillColor)
fillColor.transform(matrix);
if (strokeColor)
strokeColor.transform(matrix);
} }
if (applyMatrix) { if (applyMatrix) {
if (this._transformContent(_matrix, _applyRecursively, if (this._transformContent(_matrix, _applyRecursively,
@ -4245,33 +4279,46 @@ new function() {
applyMatrix = transform = false; applyMatrix = transform = false;
} }
} }
if (transform) {
var style = this._style,
fillColor = style.getFillColor(true),
strokeColor = style.getStrokeColor(true);
if (fillColor)
fillColor.transform(matrix);
if (strokeColor)
strokeColor.transform(matrix);
}
var bounds = this._bounds, var bounds = this._bounds,
position = this._position; position = this._position,
this._changed(9); decomposed = this._decomposed;
var decomp = bounds && matrix && matrix.decompose(); if (transform || applyMatrix) {
if (decomp && !decomp.shearing && decomp.rotation % 90 === 0) { this._changed(9);
}
var decomp = transform && (bounds || decomposed) && matrix.decompose();
if (decomposed && decomp) {
decomposed.translation = decomposed.translation.add(
decomp.translation);
decomposed.rotation += decomp.rotation;
decomposed.scaling = decomposed.scaling.multiply(decomp.scaling);
decomposed.skewing = decomposed.skewing.add(decomp.skewing);
}
if (decomp || !transform) {
this._decomposed = decomposed;
}
if (!transform) {
if (!applyMatrix) {
this._bounds = bounds;
}
this._position = position;
} else if (bounds && decomp && decomp.skewing.isZero()
&& decomp.rotation % 90 === 0) {
for (var key in bounds) { for (var key in bounds) {
var cache = bounds[key]; var cache = bounds[key];
if (applyMatrix || !cache.internal) { if (true || cache.nonscaling) {
delete bounds[key];
} else if (applyMatrix || !cache.internal) {
var rect = cache.rect; var rect = cache.rect;
matrix._transformBounds(rect, rect); matrix._transformBounds(rect, rect);
} }
} }
var getter = this._boundsGetter,
rect = bounds[getter && getter.getBounds || getter || 'getBounds'];
if (rect)
this._position = rect.getCenter(true);
this._bounds = bounds; this._bounds = bounds;
} else if (matrix && position) { var cached = bounds[this._getBoundsCacheKey(
this._boundsOptions || {})];
if (cached) {
this._position = cached.rect.getCenter(true);
}
} else if (position && this._pivot) {
this._position = matrix._transformPoint(position, position); this._position = matrix._transformPoint(position, position);
} }
return this; return this;
@ -11016,10 +11063,10 @@ var PointText = TextItem.extend({
x = 0; x = 0;
if (justification !== 'left') if (justification !== 'left')
x -= width / (justification === 'center' ? 2: 1); x -= width / (justification === 'center' ? 2: 1);
var bounds = new Rectangle(x, var rect = new Rectangle(x,
numLines ? - 0.75 * leading : 0, numLines ? - 0.75 * leading : 0,
width, numLines * leading); width, numLines * leading);
return matrix ? matrix._transformBounds(bounds, bounds) : bounds; return matrix ? matrix._transformBounds(rect, rect) : rect;
} }
}); });
@ -13807,9 +13854,9 @@ new function() {
if (!Numerical.isZero(scale.x - 1) if (!Numerical.isZero(scale.x - 1)
|| !Numerical.isZero(scale.y - 1)) || !Numerical.isZero(scale.y - 1))
parts.push('scale(' + formatter.point(scale) +')'); parts.push('scale(' + formatter.point(scale) +')');
if (skew && skew.x) if (skew.x)
parts.push('skewX(' + formatter.number(skew.x) + ')'); parts.push('skewX(' + formatter.number(skew.x) + ')');
if (skew && skew.y) if (skew.y)
parts.push('skewY(' + formatter.number(skew.y) + ')'); parts.push('skewY(' + formatter.number(skew.y) + ')');
attrs.transform = parts.join(' '); attrs.transform = parts.join(' ');
} else { } else {
@ -14142,6 +14189,7 @@ new function() {
? new Rectangle([0, 0], view.getViewSize()) ? new Rectangle([0, 0], view.getViewSize())
: bounds === 'content' : bounds === 'content'
? Item._getBounds(children, matrix, { stroke: true }) ? Item._getBounds(children, matrix, { stroke: true })
.rect
: Rectangle.read([bounds], 0, { readNull: true }), : Rectangle.read([bounds], 0, { readNull: true }),
attrs = { attrs = {
version: '1.1', version: '1.1',

File diff suppressed because one or more lines are too long

154
dist/paper-full.js vendored
View file

@ -9,7 +9,7 @@
* *
* All rights reserved. * All rights reserved.
* *
* Date: Fri Apr 21 12:54:40 2017 +0200 * Date: Sat Apr 22 00:58:54 2017 +0200
* *
*** ***
* *
@ -2262,7 +2262,7 @@ var Matrix = Base.extend({
return this.shear(shear, center); return this.shear(shear, center);
}, },
append: function(mx) { append: function(mx, _dontNotify) {
if (mx) { if (mx) {
var a1 = this._a, var a1 = this._a,
b1 = this._b, b1 = this._b,
@ -2280,12 +2280,13 @@ var Matrix = Base.extend({
this._d = b2 * b1 + d2 * d1; this._d = b2 * b1 + d2 * d1;
this._tx += tx2 * a1 + ty2 * c1; this._tx += tx2 * a1 + ty2 * c1;
this._ty += tx2 * b1 + ty2 * d1; this._ty += tx2 * b1 + ty2 * d1;
this._changed(); if (!_dontNotify)
this._changed();
} }
return this; return this;
}, },
prepend: function(mx) { prepend: function(mx, _dontNotify) {
if (mx) { if (mx) {
var a1 = this._a, var a1 = this._a,
b1 = this._b, b1 = this._b,
@ -2305,7 +2306,8 @@ var Matrix = Base.extend({
this._d = c2 * c1 + d2 * d1; this._d = c2 * c1 + d2 * d1;
this._tx = a2 * tx1 + b2 * ty1 + tx2; this._tx = a2 * tx1 + b2 * ty1 + tx2;
this._ty = c2 * tx1 + d2 * ty1 + ty2; this._ty = c2 * tx1 + d2 * ty1 + ty2;
this._changed(); if (!_dontNotify)
this._changed();
} }
return this; return this;
}, },
@ -3236,11 +3238,11 @@ new function() {
this._boundsOptions); this._boundsOptions);
if (!opts.stroke || this.getStrokeScaling()) if (!opts.stroke || this.getStrokeScaling())
opts.cacheItem = this; opts.cacheItem = this;
var bounds = this._getCachedBounds(hasMatrix && matrix, opts); var rect = this._getCachedBounds(hasMatrix && matrix, opts).rect;
return !arguments.length return !arguments.length
? new LinkedRectangle(bounds.x, bounds.y, bounds.width, ? new LinkedRectangle(rect.x, rect.y, rect.width, rect.height,
bounds.height, this, 'setBounds') this, 'setBounds')
: bounds; : rect;
}, },
setBounds: function() { setBounds: function() {
@ -3273,29 +3275,49 @@ new function() {
return Item._getBounds(children, matrix, options); return Item._getBounds(children, matrix, options);
}, },
_getBoundsCacheKey: function(options, internal) {
return [
options.stroke ? 1 : 0,
options.handle ? 1 : 0,
internal ? 1 : 0
].join('');
},
_getCachedBounds: function(matrix, options, noInternal) { _getCachedBounds: function(matrix, options, noInternal) {
matrix = matrix && matrix._orNullIfIdentity(); matrix = matrix && matrix._orNullIfIdentity();
var internal = options.internal && !noInternal, var internal = options.internal && !noInternal,
cacheItem = options.cacheItem, cacheItem = options.cacheItem,
_matrix = internal ? null : this._matrix._orNullIfIdentity(), _matrix = internal ? null : this._matrix._orNullIfIdentity(),
cacheKey = cacheItem && (!matrix || matrix.equals(_matrix)) && [ cacheKey = cacheItem && (!matrix || matrix.equals(_matrix))
options.stroke ? 1 : 0, && this._getBoundsCacheKey(options, internal),
options.handle ? 1 : 0, bounds = this._bounds;
internal ? 1 : 0
].join('');
Item._updateBoundsCache(this._parent || this._symbol, cacheItem); Item._updateBoundsCache(this._parent || this._symbol, cacheItem);
if (cacheKey && this._bounds && cacheKey in this._bounds) if (cacheKey && bounds && cacheKey in bounds) {
return this._bounds[cacheKey].rect.clone(); var cached = bounds[cacheKey];
var bounds = this._getBounds(matrix || _matrix, options); return {
rect: cached.rect.clone(),
nonscaling: cached.nonscaling
};
}
var res = this._getBounds(matrix || _matrix, options),
rect = res.rect || res,
style = this._style,
nonscaling = res.nonscaling || style.hasStroke()
&& !style.getStrokeScaling();
if (cacheKey) { if (cacheKey) {
if (!this._bounds) if (!bounds) {
this._bounds = {}; this._bounds = bounds = {};
var cached = this._bounds[cacheKey] = { }
rect: bounds.clone(), var cached = bounds[cacheKey] = {
rect: rect.clone(),
nonscaling: nonscaling,
internal: internal internal: internal
}; };
} }
return bounds; return {
rect: rect,
nonscaling: nonscaling
};
}, },
_getStrokeMatrix: function(matrix, options) { _getStrokeMatrix: function(matrix, options) {
@ -3340,22 +3362,29 @@ new function() {
var x1 = Infinity, var x1 = Infinity,
x2 = -x1, x2 = -x1,
y1 = x1, y1 = x1,
y2 = x2; y2 = x2,
nonscaling = false;
options = options || {}; options = options || {};
for (var i = 0, l = items.length; i < l; i++) { for (var i = 0, l = items.length; i < l; i++) {
var item = items[i]; var item = items[i];
if (item._visible && !item.isEmpty()) { if (item._visible && !item.isEmpty()) {
var rect = item._getCachedBounds( var bounds = item._getCachedBounds(
matrix && matrix.appended(item._matrix), options, true); matrix && matrix.appended(item._matrix), options, true),
rect = bounds.rect;
x1 = Math.min(rect.x, x1); x1 = Math.min(rect.x, x1);
y1 = Math.min(rect.y, y1); y1 = Math.min(rect.y, y1);
x2 = Math.max(rect.x + rect.width, x2); x2 = Math.max(rect.x + rect.width, x2);
y2 = Math.max(rect.y + rect.height, y2); y2 = Math.max(rect.y + rect.height, y2);
if (bounds.nonscaling)
nonscaling = true;
} }
} }
return isFinite(x1) return {
rect: isFinite(x1)
? new Rectangle(x1, y1, x2 - x1, y2 - y1) ? new Rectangle(x1, y1, x2 - x1, y2 - y1)
: new Rectangle(); : new Rectangle(),
nonscaling: nonscaling
};
} }
} }
@ -4218,8 +4247,6 @@ new function() {
transform: function(matrix, _applyMatrix, _applyRecursively, transform: function(matrix, _applyMatrix, _applyRecursively,
_setApplyMatrix) { _setApplyMatrix) {
if (matrix && matrix.isIdentity())
matrix = null;
var _matrix = this._matrix, var _matrix = this._matrix,
transform = matrix && !matrix.isIdentity(), transform = matrix && !matrix.isIdentity(),
applyMatrix = (_applyMatrix || this._applyMatrix) applyMatrix = (_applyMatrix || this._applyMatrix)
@ -4230,7 +4257,14 @@ new function() {
if (transform) { if (transform) {
if (!matrix.isInvertible() && _matrix.isInvertible()) if (!matrix.isInvertible() && _matrix.isInvertible())
_matrix._backup = _matrix.getValues(); _matrix._backup = _matrix.getValues();
_matrix.prepend(matrix); _matrix.prepend(matrix, true);
var style = this._style,
fillColor = style.getFillColor(true),
strokeColor = style.getStrokeColor(true);
if (fillColor)
fillColor.transform(matrix);
if (strokeColor)
strokeColor.transform(matrix);
} }
if (applyMatrix) { if (applyMatrix) {
if (this._transformContent(_matrix, _applyRecursively, if (this._transformContent(_matrix, _applyRecursively,
@ -4245,33 +4279,46 @@ new function() {
applyMatrix = transform = false; applyMatrix = transform = false;
} }
} }
if (transform) {
var style = this._style,
fillColor = style.getFillColor(true),
strokeColor = style.getStrokeColor(true);
if (fillColor)
fillColor.transform(matrix);
if (strokeColor)
strokeColor.transform(matrix);
}
var bounds = this._bounds, var bounds = this._bounds,
position = this._position; position = this._position,
this._changed(9); decomposed = this._decomposed;
var decomp = bounds && matrix && matrix.decompose(); if (transform || applyMatrix) {
if (decomp && !decomp.shearing && decomp.rotation % 90 === 0) { this._changed(9);
}
var decomp = transform && (bounds || decomposed) && matrix.decompose();
if (decomposed && decomp) {
decomposed.translation = decomposed.translation.add(
decomp.translation);
decomposed.rotation += decomp.rotation;
decomposed.scaling = decomposed.scaling.multiply(decomp.scaling);
decomposed.skewing = decomposed.skewing.add(decomp.skewing);
}
if (decomp || !transform) {
this._decomposed = decomposed;
}
if (!transform) {
if (!applyMatrix) {
this._bounds = bounds;
}
this._position = position;
} else if (bounds && decomp && decomp.skewing.isZero()
&& decomp.rotation % 90 === 0) {
for (var key in bounds) { for (var key in bounds) {
var cache = bounds[key]; var cache = bounds[key];
if (applyMatrix || !cache.internal) { if (true || cache.nonscaling) {
delete bounds[key];
} else if (applyMatrix || !cache.internal) {
var rect = cache.rect; var rect = cache.rect;
matrix._transformBounds(rect, rect); matrix._transformBounds(rect, rect);
} }
} }
var getter = this._boundsGetter,
rect = bounds[getter && getter.getBounds || getter || 'getBounds'];
if (rect)
this._position = rect.getCenter(true);
this._bounds = bounds; this._bounds = bounds;
} else if (matrix && position) { var cached = bounds[this._getBoundsCacheKey(
this._boundsOptions || {})];
if (cached) {
this._position = cached.rect.getCenter(true);
}
} else if (position && this._pivot) {
this._position = matrix._transformPoint(position, position); this._position = matrix._transformPoint(position, position);
} }
return this; return this;
@ -11016,10 +11063,10 @@ var PointText = TextItem.extend({
x = 0; x = 0;
if (justification !== 'left') if (justification !== 'left')
x -= width / (justification === 'center' ? 2: 1); x -= width / (justification === 'center' ? 2: 1);
var bounds = new Rectangle(x, var rect = new Rectangle(x,
numLines ? - 0.75 * leading : 0, numLines ? - 0.75 * leading : 0,
width, numLines * leading); width, numLines * leading);
return matrix ? matrix._transformBounds(bounds, bounds) : bounds; return matrix ? matrix._transformBounds(rect, rect) : rect;
} }
}); });
@ -13807,9 +13854,9 @@ new function() {
if (!Numerical.isZero(scale.x - 1) if (!Numerical.isZero(scale.x - 1)
|| !Numerical.isZero(scale.y - 1)) || !Numerical.isZero(scale.y - 1))
parts.push('scale(' + formatter.point(scale) +')'); parts.push('scale(' + formatter.point(scale) +')');
if (skew && skew.x) if (skew.x)
parts.push('skewX(' + formatter.number(skew.x) + ')'); parts.push('skewX(' + formatter.number(skew.x) + ')');
if (skew && skew.y) if (skew.y)
parts.push('skewY(' + formatter.number(skew.y) + ')'); parts.push('skewY(' + formatter.number(skew.y) + ')');
attrs.transform = parts.join(' '); attrs.transform = parts.join(' ');
} else { } else {
@ -14142,6 +14189,7 @@ new function() {
? new Rectangle([0, 0], view.getViewSize()) ? new Rectangle([0, 0], view.getViewSize())
: bounds === 'content' : bounds === 'content'
? Item._getBounds(children, matrix, { stroke: true }) ? Item._getBounds(children, matrix, { stroke: true })
.rect
: Rectangle.read([bounds], 0, { readNull: true }), : Rectangle.read([bounds], 0, { readNull: true }),
attrs = { attrs = {
version: '1.1', version: '1.1',

File diff suppressed because one or more lines are too long