Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toSVG() excludeFromExport for backgroundImage and overlayImage #5075

Merged
merged 10 commits into from
Jul 9, 2018
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