mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-05 20:34:45 +00:00
Fix to allow path to be immediately positioned on creation
This commit is contained in:
parent
1633bce401
commit
a24e0e79fc
1 changed files with 14 additions and 8 deletions
|
|
@ -203,7 +203,9 @@
|
|||
*/
|
||||
_initializePath: function (options) {
|
||||
var isWidthSet = 'width' in options,
|
||||
isHeightSet = 'height' in options;
|
||||
isHeightSet = 'height' in options,
|
||||
isLeftSet = 'left' in options,
|
||||
isTopSet = 'top' in options;
|
||||
|
||||
if (!isWidthSet || !isHeightSet) {
|
||||
extend(this, this._parseDimensions());
|
||||
|
|
@ -214,21 +216,25 @@
|
|||
this.height = options.height;
|
||||
}
|
||||
}
|
||||
else { //Set center location relative to given height/width
|
||||
this.left = this.width / 2;
|
||||
this.top = this.height / 2;
|
||||
else { //Set center location relative to given height/width if not specified
|
||||
if (!isTopSet) {
|
||||
this.top = this.height / 2;
|
||||
}
|
||||
if (!isLeftSet) {
|
||||
this.left = this.width / 2;
|
||||
}
|
||||
}
|
||||
this.pathOffset = this._calculatePathOffset(); //Save top-left coords as offset
|
||||
this.pathOffset = this._calculatePathOffset(isTopSet || isLeftSet); //Save top-left coords as offset
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @method _calculatePathOffset
|
||||
*/
|
||||
_calculatePathOffset: function () {
|
||||
_calculatePathOffset: function (positionSet) {
|
||||
return {
|
||||
x: this.left - (this.width / 2),
|
||||
y: this.top - (this.height / 2)
|
||||
x: positionSet ? 0 : this.left - (this.width / 2),
|
||||
y: positionSet ? 0 : this.top - (this.height / 2)
|
||||
};
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue