Skip to content

Commit

Permalink
Merge pull request #2117 from sapics/fix_path_initialize
Browse files Browse the repository at this point in the history
Fix path initialize
  • Loading branch information
kangax committed Apr 19, 2015
2 parents 186628c + d922771 commit a5baf7a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/shapes/path.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
this.path = this._parsePath();
}

this._setPositionDimensions();
this._setPositionDimensions(options);

if (options.sourcePath) {
this.setSourcePath(options.sourcePath);
Expand All @@ -105,29 +105,31 @@

/**
* @private
* @param {Object} options Options object
*/
_setPositionDimensions: function() {
_setPositionDimensions: function(options) {
var calcDim = this._parseDimensions();

this.minX = calcDim.left;
this.minY = calcDim.top;
this.width = calcDim.width;
this.height = calcDim.height;

calcDim.left += this.originX === 'center'
? this.width / 2
: this.originX === 'right'
? this.width
: 0;

calcDim.top += this.originY === 'center'
? this.height / 2
: this.originY === 'bottom'
? this.height
: 0;
if (typeof options.left === 'undefined') {
this.left = calcDim.left + (this.originX === 'center'
? this.width / 2
: this.originX === 'right'
? this.width
: 0);
}

this.top = this.top || calcDim.top;
this.left = this.left || calcDim.left;
if (typeof options.top === 'undefined') {
this.top = calcDim.top + (this.originY === 'center'
? this.height / 2
: this.originY === 'bottom'
? this.height
: 0);
}

this.pathOffset = this.pathOffset || {
x: this.minX + this.width / 2,
Expand Down
8 changes: 8 additions & 0 deletions test/unit/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@
});
});

asyncTest('initialize', function() {
var path = new fabric.Path('M 100 100 L 200 100 L 170 200 z', { top: 0 });

equal(path.left, 100);
equal(path.top, 0);
start();
});

asyncTest('toString', function() {
makePathObject(function(path) {
ok(typeof path.toString == 'function');
Expand Down

0 comments on commit a5baf7a

Please sign in to comment.