mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-04-16 20:30:58 +00:00
Merge pull request #326 from sjpemberton09/pathFix
Fix path bounding box.
This commit is contained in:
commit
3c40230ec0
3 changed files with 60 additions and 26 deletions
43
dist/all.js
vendored
43
dist/all.js
vendored
|
|
@ -10980,8 +10980,9 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, {
|
|||
if (!this.path) return;
|
||||
|
||||
if (!fromArray) {
|
||||
this._initializeFromString(options);
|
||||
this.path = this._parsePath();
|
||||
}
|
||||
this._initializePath(options);
|
||||
|
||||
if (options.sourcePath) {
|
||||
this.setSourcePath(options.sourcePath);
|
||||
|
|
@ -10990,14 +10991,12 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, {
|
|||
|
||||
/**
|
||||
* @private
|
||||
* @method _initializeFromString
|
||||
* @method _initializePath
|
||||
*/
|
||||
_initializeFromString: function(options) {
|
||||
_initializePath: function (options) {
|
||||
var isWidthSet = 'width' in options,
|
||||
isHeightSet = 'height' in options;
|
||||
|
||||
this.path = this._parsePath();
|
||||
|
||||
if (!isWidthSet || !isHeightSet) {
|
||||
extend(this, this._parseDimensions());
|
||||
if (isWidthSet) {
|
||||
|
|
@ -11007,6 +11006,22 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, {
|
|||
this.height = options.height;
|
||||
}
|
||||
}
|
||||
else { //Set center location relative to given height/width
|
||||
this.left = this.width / 2;
|
||||
this.top = this.height / 2;
|
||||
}
|
||||
this.pathOffset = this._calculatePathOffset(); //Save top-left coords as offset
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @method _calculatePathOffset
|
||||
*/
|
||||
_calculatePathOffset: function () {
|
||||
return {
|
||||
x: this.left - (this.width / 2),
|
||||
y: this.top - (this.height / 2)
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -11024,8 +11039,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, {
|
|||
tempY,
|
||||
tempControlX,
|
||||
tempControlY,
|
||||
l = -(this.width / 2),
|
||||
t = -(this.height / 2);
|
||||
l = -((this.width / 2) + this.pathOffset.x),
|
||||
t = -((this.height / 2) + this.pathOffset.y);
|
||||
|
||||
for (var i = 0, len = this.path.length; i < len; ++i) {
|
||||
|
||||
|
|
@ -11505,18 +11520,20 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, {
|
|||
|
||||
var minX = min(aX),
|
||||
minY = min(aY),
|
||||
deltaX = 0,
|
||||
deltaY = 0;
|
||||
maxX = max(aX),
|
||||
maxY = max(aY),
|
||||
deltaX = maxX - minX,
|
||||
deltaY = maxY - minY;
|
||||
|
||||
var o = {
|
||||
top: minY - deltaY,
|
||||
left: minX - deltaX,
|
||||
top: minY + deltaY / 2,
|
||||
left: minX + deltaX / 2,
|
||||
bottom: max(aY) - deltaY,
|
||||
right: max(aX) - deltaX
|
||||
};
|
||||
|
||||
o.width = o.right - o.left;
|
||||
o.height = o.bottom - o.top;
|
||||
o.width = deltaX;
|
||||
o.height = deltaY;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
|
|
|||
BIN
dist/all.min.js.gz
vendored
BIN
dist/all.min.js.gz
vendored
Binary file not shown.
|
|
@ -188,8 +188,9 @@
|
|||
if (!this.path) return;
|
||||
|
||||
if (!fromArray) {
|
||||
this._initializeFromString(options);
|
||||
this.path = this._parsePath();
|
||||
}
|
||||
this._initializePath(options);
|
||||
|
||||
if (options.sourcePath) {
|
||||
this.setSourcePath(options.sourcePath);
|
||||
|
|
@ -198,14 +199,12 @@
|
|||
|
||||
/**
|
||||
* @private
|
||||
* @method _initializeFromString
|
||||
* @method _initializePath
|
||||
*/
|
||||
_initializeFromString: function(options) {
|
||||
_initializePath: function (options) {
|
||||
var isWidthSet = 'width' in options,
|
||||
isHeightSet = 'height' in options;
|
||||
|
||||
this.path = this._parsePath();
|
||||
|
||||
if (!isWidthSet || !isHeightSet) {
|
||||
extend(this, this._parseDimensions());
|
||||
if (isWidthSet) {
|
||||
|
|
@ -215,6 +214,22 @@
|
|||
this.height = options.height;
|
||||
}
|
||||
}
|
||||
else { //Set center location relative to given height/width
|
||||
this.left = this.width / 2;
|
||||
this.top = this.height / 2;
|
||||
}
|
||||
this.pathOffset = this._calculatePathOffset(); //Save top-left coords as offset
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @method _calculatePathOffset
|
||||
*/
|
||||
_calculatePathOffset: function () {
|
||||
return {
|
||||
x: this.left - (this.width / 2),
|
||||
y: this.top - (this.height / 2)
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -232,8 +247,8 @@
|
|||
tempY,
|
||||
tempControlX,
|
||||
tempControlY,
|
||||
l = -(this.width / 2),
|
||||
t = -(this.height / 2);
|
||||
l = -((this.width / 2) + this.pathOffset.x),
|
||||
t = -((this.height / 2) + this.pathOffset.y);
|
||||
|
||||
for (var i = 0, len = this.path.length; i < len; ++i) {
|
||||
|
||||
|
|
@ -713,18 +728,20 @@
|
|||
|
||||
var minX = min(aX),
|
||||
minY = min(aY),
|
||||
deltaX = 0,
|
||||
deltaY = 0;
|
||||
maxX = max(aX),
|
||||
maxY = max(aY),
|
||||
deltaX = maxX - minX,
|
||||
deltaY = maxY - minY;
|
||||
|
||||
var o = {
|
||||
top: minY - deltaY,
|
||||
left: minX - deltaX,
|
||||
top: minY + deltaY / 2,
|
||||
left: minX + deltaX / 2,
|
||||
bottom: max(aY) - deltaY,
|
||||
right: max(aX) - deltaX
|
||||
};
|
||||
|
||||
o.width = o.right - o.left;
|
||||
o.height = o.bottom - o.top;
|
||||
o.width = deltaX;
|
||||
o.height = deltaY;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue