From 2b5d648e96904b779c10a35df0834e617c166f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 21 May 2011 14:27:29 +0100 Subject: [PATCH 1/6] Change SegmentPoint.create() to copy over selected state from a provided other point or object. --- src/path/SegmentPoint.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/path/SegmentPoint.js b/src/path/SegmentPoint.js index 3f655fc0..c53bfc58 100644 --- a/src/path/SegmentPoint.js +++ b/src/path/SegmentPoint.js @@ -55,17 +55,20 @@ var SegmentPoint = Point.extend({ }, statics: { - create: function(segment, x, y) { + create: function(segment, x, y, selected) { if (y === undefined) { // Use the normal point constructor to read in point values - var tmp = new Point(x); - x = tmp.x; - y = tmp.y; + var pt = x instanceof Point ? x : new Point(x); + x = pt.x; + y = pt.y; + selected = pt.selected; } var point = new SegmentPoint(SegmentPoint.dont); point._x = x; point._y = y; point._owner = segment; + if (selected) + point.setSelected(true); return point; } } From a51957bf642116db9d517862e33f461c50baeeef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 21 May 2011 14:28:08 +0100 Subject: [PATCH 2/6] Change PathStyle to clone values in setters if they provide a clone function. This requires also using equals() wherevere they are checked to be the same or different. --- src/item/PathStyle.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/item/PathStyle.js b/src/item/PathStyle.js index 4677a02e..3ec98044 100644 --- a/src/item/PathStyle.js +++ b/src/item/PathStyle.js @@ -63,7 +63,7 @@ var PathStyle = this.PathStyle = Base.extend(new function() { } else { var old = this['_' + key]; if (old != value && !(old && old.equals && old.equals(value))) { - this['_' + key] = value; + this['_' + key] = value && value.clone ? value.clone() : value; if (this._item) { this._item._changed(ChangeFlags.STYLE | (strokeFlags[key] ? ChangeFlags.STROKE : 0)); @@ -83,7 +83,8 @@ var PathStyle = this.PathStyle = Base.extend(new function() { var childStyle = children[i]._style[get](); if (!style) { style = childStyle; - } else if (style != childStyle) { + } else if (style != childStyle && !(style && style.equals + && style.equals(childStyle))) { // If there is another item with a different style, // the style is not defined: // PORT: Change this in Sg (currently returns null) @@ -96,6 +97,7 @@ var PathStyle = this.PathStyle = Base.extend(new function() { } }; + // Style-getters and setters for Item: // 'this' = the Base.each() side-car = the object that is returned from // Base.each and injected into Item above: this[set] = function(value) { From eb44238f5362dce6b31fbe9572d1f707a4a9a688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 21 May 2011 14:28:20 +0100 Subject: [PATCH 3/6] Fix Layer nesting tests. --- test/tests/Layer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/tests/Layer.js b/test/tests/Layer.js index cd0322bc..28533867 100644 --- a/test/tests/Layer.js +++ b/test/tests/Layer.js @@ -95,7 +95,7 @@ test('appendTop / appendBottom / nesting', function() { return project.layers.length; }, 2); equals(function() { - return project.layers[0] == firstLayer - && project.layers[1] == secondLayer; + return project.layers[0] == secondLayer + && project.layers[1] == firstLayer; }, true); -); \ No newline at end of file +}); \ No newline at end of file From 8b9f9ea6db84465ee72ff5820046851037ef457a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 21 May 2011 14:28:31 +0100 Subject: [PATCH 4/6] Do not access internal properties from tests. --- test/tests/Item_Cloning.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests/Item_Cloning.js b/test/tests/Item_Cloning.js index c16b6670..aa8a357d 100644 --- a/test/tests/Item_Cloning.js +++ b/test/tests/Item_Cloning.js @@ -17,7 +17,7 @@ test('Path#clone()', function() { path.locked = true; path.visible = false; path.blendMode = 'blend'; - path._clipMask = true; + path.clipMask = true; path.selected = true; cloneAndCompare(path); }); From b3281806a31a91bc47eac398066dd5f35b3150e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 21 May 2011 14:29:00 +0100 Subject: [PATCH 5/6] No need to check if _style is defined now since even Layer (ineriting from Group) now has a style. --- src/item/Item.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index 42961f58..644d3672 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -36,9 +36,8 @@ var Item = this.Item = Base.extend({ }, _clone: function(copy) { - // If this item has a pathStyle, copy it: - if (this._style) - copy.setStyle(this._style); + // Copy over style + copy.setStyle(this._style); // If this item has children, clone and append each of them: if (this._children) { for (var i = 0, l = this._children.length; i < l; i++) From 456abcfda361d717c1332c34b3fffae22a6b188e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 21 May 2011 14:29:15 +0100 Subject: [PATCH 6/6] Clean up compareItems() test code. --- test/lib/helpers.js | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/test/lib/helpers.js b/test/lib/helpers.js index 7b4d5549..43990926 100644 --- a/test/lib/helpers.js +++ b/test/lib/helpers.js @@ -100,29 +100,31 @@ function compareItems(item, item2) { return item != item2; }, true); + equals(function() { + return item.id != item2.id; + }, true); + var itemProperties = ['opacity', 'locked', 'visible', 'blendMode', 'name', 'closed', 'selected']; Base.each(itemProperties, function(key) { equals(function() { return item[key] == item2[key]; - }, true, 'item[\'' + key + '\'] == item2[\'' + key + '\']'); + }, true); }); - - equals(function() { - return item.id != item2.id; - }, true); if (item._matrix) { equals(function() { return item._matrix != item2._matrix; }, true); - equals(item._matrix.toString(), item2._matrix.toString(), - 'item._matrix.toString() == item2._matrix.toString()'); + equals(function() { + return item._matrix.toString() == item2._matrix.toString() + }, true); } if (item2.segments) { - equals(item.segments.toString(), item2.segments.toString(), - 'item.segments.toString() == item2.segments.toString()'); + equals(function() { + return item.segments.toString() == item2.segments.toString() + }, true); } // Path specific @@ -157,20 +159,20 @@ function compareItems(item, item2) { // TextItem specific: if (item instanceof TextItem) { - equals(item.content, item2.content, 'item.content == item2.content'); + equals(function() { + return item.content == item2.content; + }, true); var characterStyleKeys = ['fontSize', 'font']; Base.each(characterStyleKeys, function(key) { equals(function() { - return item2.characterStyle[key]; - }, item.characterStyle[key], 'item.characterStyle[\'' + key - + '\'] == item2.characterStyle[\'' + key + '\']'); + return item.characterStyle[key] == item2.characterStyle[key]; + }, true); }); var paragraphStyleKeys = ['justification']; Base.each(paragraphStyleKeys, function(key) { equals(function() { - return item2.paragraphStyle[key]; - }, item.paragraphStyle[key], 'item.paragraphStyle[\'' + key - + '\'] == item2.paragraphStyle[\'' + key + '\']'); + return item.paragraphStyle[key] == item2.paragraphStyle[key]; + }, true); }); } @@ -209,13 +211,14 @@ function compareItems(item, item2) { if (item[key]) { equals(function() { return item[key] == item2[key]; - }, true, 'item[\'' + key + '\'] == item2[\'' + key + '\']'); + }, true); } }); if (item.dashArray) { - equals(item.dashArray.toString(), item2.dashArray.toString(), - 'item.dashArray.toString(), item2.dashArray.toString()'); + equals(function() { + return item.dashArray.toString() == item2.dashArray.toString(); + }, true); } }