Fix invisibility of objects with no widht/height but strokewidth (#5382)

* added test

* fixed ellipse test

* fixed ellipse lint
This commit is contained in:
Andrea Bogazzi 2018-11-12 01:20:28 +01:00 committed by GitHub
parent 3af833930f
commit cdb6b51385
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 8 deletions

View file

@ -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;
},
/**

View file

@ -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) {

View file

@ -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');
});
})();