mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -05:00
Fix a few edge cases in cloning and copying of attributes.
This commit is contained in:
parent
2fea40f86f
commit
83b53cb9e0
3 changed files with 18 additions and 8 deletions
|
@ -1432,9 +1432,18 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
|
|||
* }
|
||||
*/
|
||||
clone: function(insert) {
|
||||
var copy = new this.constructor(Item.NO_INSERT);
|
||||
copy.copyAttributes(this);
|
||||
var copy = new this.constructor(Item.NO_INSERT),
|
||||
children = this._children;
|
||||
// On items with children, for performance reasons due to the way that
|
||||
// styles are currently "flattened" into existing children, we need to
|
||||
// clone attributes first, then content.
|
||||
// For all other items, it's the other way around, since applying
|
||||
// attributes might have an impact on their content.
|
||||
if (children)
|
||||
copy.copyAttributes(this);
|
||||
copy.copyContent(this);
|
||||
if (!children)
|
||||
copy.copyAttributes(this);
|
||||
// Insert is true by default.
|
||||
if (insert || insert === undefined)
|
||||
copy.insertAbove(this);
|
||||
|
@ -1474,7 +1483,7 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
|
|||
*
|
||||
* @param {Item} source the item to copy the attributes from
|
||||
*/
|
||||
copyAttributes: function(source, _preConcatenate) {
|
||||
copyAttributes: function(source, excludeMatrix) {
|
||||
// Copy over style
|
||||
this.setStyle(source._style);
|
||||
// Only copy over these fields if they are actually defined in 'source',
|
||||
|
@ -1488,8 +1497,8 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
|
|||
this[key] = source[key];
|
||||
}
|
||||
// Use Matrix#initialize to easily copy over values.
|
||||
this._matrix[_preConcatenate ? 'preConcatenate' : 'initialize'](
|
||||
source._matrix);
|
||||
if (!excludeMatrix)
|
||||
this._matrix.initialize(source._matrix);
|
||||
// We can't just set _applyMatrix as many item types won't allow it,
|
||||
// e.g. creating a Shape in Path#toShape().
|
||||
// Using the setter instead takes care of it.
|
||||
|
|
|
@ -1500,8 +1500,9 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
radius: radius,
|
||||
insert: false
|
||||
});
|
||||
// Pass `true` to preconcatenate the matrix to the center-transform.
|
||||
// Pass `true` to exclude the matrix, so we can preconcatenate after
|
||||
shape.copyAttributes(this, true);
|
||||
shape._matrix.preConcatenate(this._matrix);
|
||||
// Determine and apply the shape's angle of rotation.
|
||||
shape.rotate(topCenter.subtract(center).getAngle() + 90);
|
||||
shape.insertAbove(this);
|
||||
|
|
|
@ -66,8 +66,8 @@ PathItem.inject(new function() {
|
|||
result.insertAbove(path2 && path1.isSibling(path2)
|
||||
&& path1.getIndex() < path2.getIndex()
|
||||
? path2 : path1);
|
||||
// Copy over the left-hand item's style and we're done.
|
||||
result.copyAttributes(path1);
|
||||
// Copy over the input path attributes, excluding matrix and we're done.
|
||||
result.copyAttributes(path1, true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue