From d16155f4fe28165a3ae9ed52dac8484cb259ab30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 1 Dec 2012 11:31:03 -0800 Subject: [PATCH] Fix CompoundPath#clone() so that it does not alter the #clockwise state on its children. --- src/item/Item.js | 9 ++++++--- src/path/CompoundPath.js | 4 ++-- src/path/Path.js | 3 +++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index 48a4062b..d6bd9a28 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -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); }, /** diff --git a/src/path/CompoundPath.js b/src/path/CompoundPath.js index 974318d8..2e87d6f1 100644 --- a/src/path/CompoundPath.js +++ b/src/path/CompoundPath.js @@ -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; }, diff --git a/src/path/Path.js b/src/path/Path.js index dd9507e1..04446442 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -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; }, /**