From e17e94b50b4314b29ec4df104a55f5d706448d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 10 Oct 2012 20:11:11 -0700 Subject: [PATCH] Implement Item#isEmpty() for the various types. And use it to tell #getBounds() when to ignore items. --- src/item/Group.js | 4 ++++ src/item/Item.js | 6 +++++- src/item/PlacedSymbol.js | 4 ++++ src/item/Raster.js | 4 ++++ src/path/CompoundPath.js | 4 ++++ src/path/Path.js | 4 ++++ src/text/TextItem.js | 4 ++++ 7 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/item/Group.js b/src/item/Group.js index ecf48d46..f1b235d6 100644 --- a/src/item/Group.js +++ b/src/item/Group.js @@ -118,6 +118,10 @@ var Group = this.Group = Item.extend(/** @lends Group# */{ return this; }, + isEmpty: function() { + return this._children.length == 0; + }, + draw: function(ctx, param) { var clipItem = this._getClipItem(); if (clipItem) { diff --git a/src/item/Item.js b/src/item/Item.js index 51c8688b..97b21162 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -665,7 +665,7 @@ function(name) { y2 = x2; for (var i = 0, l = children.length; i < l; i++) { var child = children[i]; - if (child._visible) { + if (child._visible && !child.isEmpty()) { var rect = child._getCachedBounds(type, matrix, cacheItem); x1 = Math.min(rect.x, x1); y1 = Math.min(rect.y, y1); @@ -676,6 +676,10 @@ function(name) { return Rectangle.create(x1, y1, x2 - x1, y2 - y1); }, + isEmpty: function() { + return true; + }, + setBounds: function(rect) { rect = Rectangle.read(arguments); var bounds = this.getBounds(), diff --git a/src/item/PlacedSymbol.js b/src/item/PlacedSymbol.js index 071b61f1..9e603052 100644 --- a/src/item/PlacedSymbol.js +++ b/src/item/PlacedSymbol.js @@ -85,6 +85,10 @@ var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol symbol._instances[this._id] = this; }, + isEmpty: function() { + return this._symbol._definition.isEmpty(); + }, + clone: function() { return this._clone(new PlacedSymbol(this.symbol, this._matrix.clone())); }, diff --git a/src/item/Raster.js b/src/item/Raster.js index f11c4a99..f52378c6 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -109,6 +109,10 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{ return this._size.height; }, + isEmpty: function() { + return this._size.width == 0 && this._size.height == 0; + }, + /** * Pixels per inch of the raster at its current size. * diff --git a/src/path/CompoundPath.js b/src/path/CompoundPath.js index 80c0da73..6aac8668 100644 --- a/src/path/CompoundPath.js +++ b/src/path/CompoundPath.js @@ -85,6 +85,10 @@ var CompoundPath = this.CompoundPath = PathItem.extend(/** @lends CompoundPath# this._children[i].smooth(); }, + isEmpty: function() { + return this._children.length == 0; + }, + draw: function(ctx, param) { var children = this._children; // Return early if the compound path doesn't have any children: diff --git a/src/path/Path.js b/src/path/Path.js index 68303c72..dfda51df 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -229,6 +229,10 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{ // Do nothing for the same reason as above. }, + isEmpty: function() { + return this._segments.length == 0; + }, + _apply: function(matrix) { var coords = new Array(6); for (var i = 0, l = this._segments.length; i < l; i++) { diff --git a/src/text/TextItem.js b/src/text/TextItem.js index eb1bfc38..8da7a5bb 100644 --- a/src/text/TextItem.js +++ b/src/text/TextItem.js @@ -92,6 +92,10 @@ var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{ this._changed(Change.CONTENT); }, + isEmpty: function() { + return !!this._content; + }, + /** * {@grouptitle Style Properties} *