mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-18 18:41:08 +00:00
Merge pull request #168 from garg/master
Fix `fabric.Object#toDataURL` to take bounding rectangle dimensions into consideration. Add `fabric.Object#getBoundingRectWidth`, `fabric.Object#getBoundingRectHeight`.
This commit is contained in:
commit
a239bdd2a8
2 changed files with 54 additions and 10 deletions
34
dist/all.js
vendored
34
dist/all.js
vendored
|
|
@ -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');
|
||||
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue