diff --git a/dist/all.js b/dist/all.js index 26660389..cc22d37d 100644 --- a/dist/all.js +++ b/dist/all.js @@ -2004,7 +2004,7 @@ fabric.Observable = { } }; } - + if (!Array.prototype.map) { Array.prototype.map = function(fn, context) { var result = [ ]; @@ -7746,6 +7746,30 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { return this; }, + + /** + * Returns width of an object's bounding rectangle + * @method getBoundingRectWidth + * @return {Number} width value + */ + getBoundingRectWidth: function() { + var xCoords = [this.oCoords.tl.x, this.oCoords.tr.x, this.oCoords.br.x, this.oCoords.bl.x]; + var minX = fabric.util.array.min(xCoords); + var maxX = fabric.util.array.max(xCoords); + return Math.abs(minX - maxX); + }, + + /** + * Returns height of an object's bounding rectangle + * @method getBoundingRectHeight + * @return {Number} height value + */ + getBoundingRectHeight: function() { + var yCoords = [this.oCoords.tl.y, this.oCoords.tr.y, this.oCoords.br.y, this.oCoords.bl.y]; + var minY = fabric.util.array.min(yCoords); + var maxY = fabric.util.array.max(yCoords); + return Math.abs(minY - maxY); + }, /** * Draws borders of an object's bounding box. @@ -7948,11 +7972,9 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { if (!el.getContext && typeof G_vmlCanvasManager != 'undefined') { G_vmlCanvasManager.initElement(el); } - - // TODO: should probably use bounding rectangle dimensions instead - - el.width = this.getWidth(); - el.height = this.getHeight(); + + el.width = this.getBoundingRectWidth(); + el.height = this.getBoundingRectHeight(); fabric.util.wrapElement(el, 'div'); diff --git a/src/object.class.js b/src/object.class.js index e38bfb52..6ef6c6ef 100644 --- a/src/object.class.js +++ b/src/object.class.js @@ -562,7 +562,31 @@ return this; }, + + /** + * Returns width of an object's bounding rectangle + * @method getBoundingRectWidth + * @return {Number} width value + */ + getBoundingRectWidth: function() { + var xCoords = [this.oCoords.tl.x, this.oCoords.tr.x, this.oCoords.br.x, this.oCoords.bl.x]; + var minX = fabric.util.array.min(xCoords); + var maxX = fabric.util.array.max(xCoords); + return Math.abs(minX - maxX); + }, + /** + * Returns height of an object's bounding rectangle + * @method getBoundingRectHeight + * @return {Number} height value + */ + getBoundingRectHeight: function() { + var yCoords = [this.oCoords.tl.y, this.oCoords.tr.y, this.oCoords.br.y, this.oCoords.bl.y]; + var minY = fabric.util.array.min(yCoords); + var maxY = fabric.util.array.max(yCoords); + return Math.abs(minY - maxY); + }, + /** * Draws borders of an object's bounding box. * Requires public properties: width, height @@ -765,10 +789,8 @@ G_vmlCanvasManager.initElement(el); } - // TODO: should probably use bounding rectangle dimensions instead - - el.width = this.getWidth(); - el.height = this.getHeight(); + el.width = this.getBoundingRectWidth(); + el.height = this.getBoundingRectHeight(); fabric.util.wrapElement(el, 'div');