Fix CompoundPath#clone() so that it does not alter the #clockwise state on its children.

This commit is contained in:
Jürg Lehni 2012-12-01 11:31:03 -08:00
parent f14b685c1d
commit d16155f4fe
3 changed files with 11 additions and 5 deletions

View file

@ -946,8 +946,10 @@ function(name) {
copy.setStyle(this._style);
// If this item has children, clone and append each of them:
if (this._children) {
// Clone all children and add them to the copy. tell #addChild we're
// cloning, as needed by CompoundPath#insertChild().
for (var i = 0, l = this._children.length; i < l; i++)
copy.addChild(this._children[i].clone());
copy.addChild(this._children[i].clone(), true);
}
// Only copy over these fields if they are actually defined in 'this'
// TODO: Consider moving this to Base once it's useful in more than one
@ -1128,8 +1130,9 @@ function(name) {
*
* @param {Item} item The item to be added as a child
*/
addChild: function(item) {
return this.insertChild(undefined, item);
addChild: function(item, _cloning) {
// Pass on internal _cloning boolean, for CompoundPath#insertChild
return this.insertChild(undefined, item, _cloning);
},
/**

View file

@ -51,7 +51,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend(/** @lends CompoundPath#
this.addChildren(Array.isArray(paths) ? paths : arguments);
},
insertChild: function(index, item) {
insertChild: function(index, item, _cloning) {
// Only allow the insertion of paths
if (item._type !== 'path')
return null;
@ -60,7 +60,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend(/** @lends CompoundPath#
// to anti-clockwise orientation, so that they appear as holes, but
// only if their orientation was not already specified before
// (= _clockwise is defined).
if (res && item._clockwise === undefined)
if (!_cloning && res && item._clockwise === undefined)
item.setClockwise(item._index == 0);
return res;
},

View file

@ -835,6 +835,9 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
// as what it is now demanded to be.
this.reverse();
}
// Reverse only flips _clockwise state if it was already set, so let's
// always set this here now.
this._clockwise = clockwise;
},
/**