diff --git a/src/static_canvas.class.js b/src/static_canvas.class.js index 68f75bb9b66..1eb459d2c7d 100644 --- a/src/static_canvas.class.js +++ b/src/static_canvas.class.js @@ -1400,7 +1400,7 @@ * @private */ _setSVGBgOverlayImage: function(markup, property, reviver) { - if (this[property] && this[property].toSVG) { + if (this[property] && !this[property].excludeFromExport && this[property].toSVG) { markup.push(this[property].toSVG(reviver)); } }, diff --git a/test/unit/canvas_static.js b/test/unit/canvas_static.js index d55895da5bd..c78c0e02518 100644 --- a/test/unit/canvas_static.js +++ b/test/unit/canvas_static.js @@ -866,6 +866,48 @@ canvas.renderOnAddRemove = true; }); + QUnit.test('toSVG with exclude from export background', function(assert) { + assert.ok(typeof canvas.toSVG === 'function'); + canvas.clear(); + + var circle = new fabric.Circle({excludeFromExport: true}), + rect = new fabric.Rect(), + imageBG = new fabric.Image({width: 0, height: 0}), + imageOL = new fabric.Image({width: 0, height: 0}); + + canvas.renderOnAddRemove = false; + canvas.add(circle, rect); + + canvas.setBackgroundImage(imageBG); + canvas.setOverlayImage(imageOL); + + var reviverCount = 0, + len = canvas.size(); + + function reviver(svg) { + reviverCount++; + return svg; + } + + canvas.toSVG(null, reviver); + assert.equal(reviverCount, len + 1 , 'reviver should include backgroundImage and overlayImage'); + + reviverCount = 0; + + canvas.setBackgroundImage(imageBG,canvas.renderAll.bind(canvas),{ + excludeFromExport: true + }); + canvas.setOverlayImage(imageOL,canvas.renderAll.bind(canvas),{ + excludeFromExport: true + }); + canvas.toSVG(null, reviver); + assert.equal(reviverCount, len - 1 , 'reviver should not include objects with excludeFromExport and backgroundImage & overlayImage'); + + canvas.setBackgroundImage(null); + canvas.setOverlayImage(null); + canvas.renderOnAddRemove = true; + }); + QUnit.test('toJSON', function(assert) { assert.ok(typeof canvas.toJSON === 'function'); assert.equal(JSON.stringify(canvas.toJSON()), '{"version":"' + fabric.version + '","objects":[]}');