Skip to content

Commit

Permalink
toSVG() excludeFromExport for backgroundImage and overlayImage (fabr…
Browse files Browse the repository at this point in the history
  • Loading branch information
durga598 authored and asturur committed Jul 9, 2018
1 parent af4a925 commit f3839bc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/static_canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
},
Expand Down
42 changes: 42 additions & 0 deletions test/unit/canvas_static.js
Original file line number Diff line number Diff line change
Expand Up @@ -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":[]}');
Expand Down

0 comments on commit f3839bc

Please sign in to comment.