From cdb6b513857881b33d689c75df4a2962c5ec4b17 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Mon, 12 Nov 2018 01:20:28 +0100 Subject: [PATCH] Fix invisibility of objects with no widht/height but strokewidth (#5382) * added test * fixed ellipse test * fixed ellipse lint --- src/shapes/object.class.js | 4 +++- test/unit/ellipse.js | 12 +++++------- test/unit/object.js | 12 ++++++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index ffd55ecc..e307b1cd 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -1031,7 +1031,9 @@ * @return {Boolean} */ isNotVisible: function() { - return this.opacity === 0 || (this.width === 0 && this.height === 0) || !this.visible; + return this.opacity === 0 || + (this.width === 0 && this.height === 0 && this.strokeWidth === 0) || + !this.visible; }, /** diff --git a/test/unit/ellipse.js b/test/unit/ellipse.js index 03c8d6ce..63b0031e 100644 --- a/test/unit/ellipse.js +++ b/test/unit/ellipse.js @@ -83,18 +83,16 @@ assert.deepEqual(ellipse.getRx(), ellipse.rx * ellipse.scaleX); }); - QUnit.test('render', function(assert) { + QUnit.test('isNotVisible', function(assert) { var ellipse = new fabric.Ellipse(); ellipse.set('rx', 0).set('ry', 0); - var wasRenderCalled = false; + assert.equal(ellipse.isNotVisible(), false, 'isNotVisible false when rx/ry are 0 because strokeWidth is > 0'); - ellipse._render = function(){ - wasRenderCalled = true; - }; - ellipse.render({}); + ellipse.set('strokeWidth', 0); + + assert.equal(ellipse.isNotVisible(), true, 'should not render anymore with also strokeWidth 0'); - assert.equal(wasRenderCalled, false, 'should not render when rx/ry are 0'); }); QUnit.test('toSVG', function(assert) { diff --git a/test/unit/object.js b/test/unit/object.js index 28b9c47a..6bfd19f6 100644 --- a/test/unit/object.js +++ b/test/unit/object.js @@ -1249,4 +1249,16 @@ object._set('fill', 'blue'); assert.equal(object.dirty, false, 'dirty is not rised'); }); + QUnit.test('isNotVisible', function(assert) { + var object = new fabric.Object({ fill: 'blue', width: 100, height: 100 }); + assert.equal(object.isNotVisible(), false, 'object is default visilbe'); + object = new fabric.Object({ fill: 'blue', width: 0, height: 0, strokeWidth: 1 }); + assert.equal(object.isNotVisible(), false, 'object is visilbe with width and height equal 0, but strokeWidth 1'); + object = new fabric.Object({ opacity: 0, fill: 'blue' }); + assert.equal(object.isNotVisible(), true, 'object is not visilbe with opacity 0'); + object = new fabric.Object({ fill: 'blue', visible: false }); + assert.equal(object.isNotVisible(), true, 'object is not visilbe with visible false'); + object = new fabric.Object({ fill: 'blue', width: 0, height: 0, strokeWidth: 0 }); + assert.equal(object.isNotVisible(), true, 'object is not visilbe with also strokeWidth equal 0'); + }); })();