mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Implement Item#isEmpty() for the various types.
And use it to tell #getBounds() when to ignore items.
This commit is contained in:
parent
adb2ddc615
commit
e17e94b50b
7 changed files with 29 additions and 1 deletions
|
@ -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) {
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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()));
|
||||
},
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -92,6 +92,10 @@ var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
|
|||
this._changed(Change.CONTENT);
|
||||
},
|
||||
|
||||
isEmpty: function() {
|
||||
return !!this._content;
|
||||
},
|
||||
|
||||
/**
|
||||
* {@grouptitle Style Properties}
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue