diff --git a/.travis.yml b/.travis.yml index d62ea0e57db..326f3a74406 100644 --- a/.travis.yml +++ b/.travis.yml @@ -75,10 +75,7 @@ jobs: - stage: Unit Tests env: CANVAS=canvas-prebuilt node_js: "8" - cache: - directories: - - '' - install: npm install && npm remove canvas && npm install canvas-prebuilt@^1.6.11 + install: npm install && npm remove canvas && npm install canvas-prebuilt@^1.6.11 qunit@2.6.1 addons: apt: packages: # avoid installing packages diff --git a/package.json b/package.json index 4a3c24e5501..6912f4325a7 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "testem:ci": "testem ci" }, "optionalDependencies": { - "canvas": "^1.6.12", + "canvas": "^1.6.13", "jsdom": "^9.12.0", "xmldom": "0.1.x" }, diff --git a/src/canvas.class.js b/src/canvas.class.js index 94f7fd904e8..c82e7f6bef1 100644 --- a/src/canvas.class.js +++ b/src/canvas.class.js @@ -896,12 +896,10 @@ */ _setObjectScale: function(localMouse, transform, lockScalingX, lockScalingY, by, lockScalingFlip, _dim) { var target = transform.target, forbidScalingX = false, forbidScalingY = false, scaled = false, - changeX, changeY, scaleX, scaleY; - - scaleX = localMouse.x * target.scaleX / _dim.x; - scaleY = localMouse.y * target.scaleY / _dim.y; - changeX = target.scaleX !== scaleX; - changeY = target.scaleY !== scaleY; + scaleX = localMouse.x * target.scaleX / _dim.x, + scaleY = localMouse.y * target.scaleY / _dim.y, + changeX = target.scaleX !== scaleX, + changeY = target.scaleY !== scaleY; if (lockScalingFlip && scaleX <= 0 && scaleX < target.scaleX) { forbidScalingX = true; @@ -921,10 +919,10 @@ forbidScalingY || lockScalingY || (target.set('scaleY', scaleY) && (scaled = scaled || changeY)); } else if (by === 'x' && !target.get('lockUniScaling')) { - forbidScalingX || lockScalingX || (target.set('scaleX', scaleX) && (scaled = scaled || changeX)); + forbidScalingX || lockScalingX || (target.set('scaleX', scaleX) && (scaled = changeX)); } else if (by === 'y' && !target.get('lockUniScaling')) { - forbidScalingY || lockScalingY || (target.set('scaleY', scaleY) && (scaled = scaled || changeY)); + forbidScalingY || lockScalingY || (target.set('scaleY', scaleY) && (scaled = changeY)); } transform.newScaleX = scaleX; transform.newScaleY = scaleY; @@ -942,15 +940,15 @@ lastDist = _dim.y * transform.original.scaleY / target.scaleY + _dim.x * transform.original.scaleX / target.scaleX, scaled, signX = localMouse.x < 0 ? -1 : 1, - signY = localMouse.y < 0 ? -1 : 1; + signY = localMouse.y < 0 ? -1 : 1, newScaleX, newScaleY; // We use transform.scaleX/Y instead of target.scaleX/Y // because the object may have a min scale and we'll loose the proportions - transform.newScaleX = signX * Math.abs(transform.original.scaleX * dist / lastDist); - transform.newScaleY = signY * Math.abs(transform.original.scaleY * dist / lastDist); - scaled = transform.newScaleX !== target.scaleX || transform.newScaleY !== target.scaleY; - target.set('scaleX', transform.newScaleX); - target.set('scaleY', transform.newScaleY); + newScaleX = signX * Math.abs(transform.original.scaleX * dist / lastDist); + newScaleY = signY * Math.abs(transform.original.scaleY * dist / lastDist); + scaled = newScaleX !== target.scaleX || newScaleY !== target.scaleY; + target.set('scaleX', newScaleX); + target.set('scaleY', newScaleY); return scaled; }, diff --git a/src/mixins/textbox_behavior.mixin.js b/src/mixins/textbox_behavior.mixin.js index 4d0fe12612f..230aca855ad 100644 --- a/src/mixins/textbox_behavior.mixin.js +++ b/src/mixins/textbox_behavior.mixin.js @@ -9,13 +9,18 @@ fabric.Canvas.prototype._setObjectScale = function(localMouse, transform, lockScalingX, lockScalingY, by, lockScalingFlip, _dim) { - var t = transform.target; + var t = transform.target, scaled, + scaleX = localMouse.x * t.scaleX / _dim.x, + scaleY = localMouse.y * t.scaleY / _dim.y; if (by === 'x' && t instanceof fabric.Textbox) { var tw = t._getTransformedDimensions().x; var w = t.width * (localMouse.x / tw); + transform.newScaleX = scaleX; + transform.newScaleY = scaleY; if (w >= t.getMinWidth()) { + scaled = w !== t.width; t.set('width', w); - return true; + return scaled; } } else { diff --git a/test/unit/textbox.js b/test/unit/textbox.js index ce21891e2d3..96319083cc2 100644 --- a/test/unit/textbox.js +++ b/test/unit/textbox.js @@ -154,4 +154,20 @@ assert.deepEqual(line2, expected2, 'wrapping without reserved'); assert.deepEqual(textbox.dynamicMinWidth, 90, 'wrapping without reserved'); }); + QUnit.test('_scaleObject with textbox', function(assert) { + var text = new fabric.Textbox('xa xb xc xd xe ya yb id', { strokeWidth: 0 }); + canvas.add(text); + var canvasEl = canvas.getElement(), + canvasOffset = fabric.util.getElementOffset(canvasEl); + var eventStub = { + clientX: canvasOffset.left + text.width, + clientY: canvasOffset.top + text.oCoords.mr.corner.tl.y + 1, + }; + var originalWidth = text.width; + canvas._setupCurrentTransform(eventStub, text, true); + var scaled = canvas._scaleObject(eventStub.clientX + 20, eventStub.clientY, 'x'); + assert.equal(scaled, true, 'return true if textbox scaled'); + assert.equal(text.width, originalWidth + 20, 'width increased'); + assert.equal(canvas._currentTransform.newScaleX, text.width / originalWidth, 'newScaleX is not undefined'); + }); })();