From 60d7495608c013dd7ca44898c38e269c3a206c8d Mon Sep 17 00:00:00 2001 From: sapics Date: Thu, 16 Apr 2015 17:01:06 +0900 Subject: [PATCH 1/4] unit test for detect path initialize bug --- test/unit/path.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/unit/path.js b/test/unit/path.js index 9bbf5b6c497..74335d1ba15 100644 --- a/test/unit/path.js +++ b/test/unit/path.js @@ -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'); From 05316fc0f9fb33f81ec7ecf9c572a6e192eaf7bb Mon Sep 17 00:00:00 2001 From: sapics Date: Thu, 16 Apr 2015 17:11:06 +0900 Subject: [PATCH 2/4] fix path initialize function for option left=0 or top=0 --- src/shapes/path.class.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/shapes/path.class.js b/src/shapes/path.class.js index 71c02828cb4..4473225329a 100644 --- a/src/shapes/path.class.js +++ b/src/shapes/path.class.js @@ -96,6 +96,13 @@ this.path = this._parsePath(); } + if (typeof options.top === 'undefined') { + this.top = null; + } + if (typeof options.left === 'undefined') { + this.left = null; + } + this._setPositionDimensions(); if (options.sourcePath) { @@ -114,20 +121,21 @@ 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 (this.left === null) { + 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 (this.top === null) { + 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, From 64529b456262a87fad5ac7bfe8c5080aac72035e Mon Sep 17 00:00:00 2001 From: sapics Date: Thu, 16 Apr 2015 18:31:52 +0900 Subject: [PATCH 3/4] fix of @asturur suggestion --- src/shapes/path.class.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/shapes/path.class.js b/src/shapes/path.class.js index 4473225329a..bca9be38fe3 100644 --- a/src/shapes/path.class.js +++ b/src/shapes/path.class.js @@ -96,14 +96,7 @@ this.path = this._parsePath(); } - if (typeof options.top === 'undefined') { - this.top = null; - } - if (typeof options.left === 'undefined') { - this.left = null; - } - - this._setPositionDimensions(); + this._setPositionDimensions(options); if (options.sourcePath) { this.setSourcePath(options.sourcePath); @@ -113,7 +106,7 @@ /** * @private */ - _setPositionDimensions: function() { + _setPositionDimensions: function(options) { var calcDim = this._parseDimensions(); this.minX = calcDim.left; @@ -121,7 +114,7 @@ this.width = calcDim.width; this.height = calcDim.height; - if (this.left === null) { + if (typeof options.left === 'undefined') { this.left = calcDim.left + (this.originX === 'center' ? this.width / 2 : this.originX === 'right' @@ -129,7 +122,7 @@ : 0); } - if (this.top === null) { + if (typeof options.top === 'undefined') { this.top = calcDim.top + (this.originY === 'center' ? this.height / 2 : this.originY === 'bottom' From d92277191559814a4e6165123941d44d0dfb4095 Mon Sep 17 00:00:00 2001 From: sapics Date: Thu, 16 Apr 2015 18:47:04 +0900 Subject: [PATCH 4/4] Add @param comment --- src/shapes/path.class.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/shapes/path.class.js b/src/shapes/path.class.js index bca9be38fe3..cac505e1c0a 100644 --- a/src/shapes/path.class.js +++ b/src/shapes/path.class.js @@ -105,6 +105,7 @@ /** * @private + * @param {Object} options Options object */ _setPositionDimensions: function(options) { var calcDim = this._parseDimensions();