mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-24 21:23:44 +00:00
simpler test (#5093)
This commit is contained in:
parent
65a219e56c
commit
750c7c26db
1 changed files with 15 additions and 36 deletions
|
|
@ -867,44 +867,23 @@
|
|||
});
|
||||
|
||||
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});
|
||||
var image = fabric.document.createElement('img'),
|
||||
imageBG = new fabric.Image(image, {width: 0, height: 0}),
|
||||
imageOL = new fabric.Image(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.backgroundImage = imageBG;
|
||||
canvas.overlayImage = imageOL;
|
||||
var expectedSVG = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="600" height="600" viewBox="0 0 600 600" xml:space="preserve">\n<desc>Created with Fabric.js 2.3.3</desc>\n<defs>\n</defs>\n<g transform="translate(0 0)">\n\t<image xlink:href="" x="0" y="0" style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" width="0" height="0"></image>\n</g>\n<g transform="translate(0 0)">\n\t<image xlink:href="" x="0" y="0" style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" width="0" height="0"></image>\n</g>\n</svg>';
|
||||
var svg1 = canvas.toSVG();
|
||||
assert.equal(svg1, expectedSVG, 'svg with bg and overlay do not match')
|
||||
imageBG.excludeFromExport = true;
|
||||
imageOL.excludeFromExport = true;
|
||||
var expectedSVG2 = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="600" height="600" viewBox="0 0 600 600" xml:space="preserve">\n<desc>Created with Fabric.js 2.3.3</desc>\n<defs>\n</defs>\n</svg>';
|
||||
var svg2 = canvas.toSVG();
|
||||
assert.equal(svg2, expectedSVG2, 'svg without bg and overlay do not match')
|
||||
canvas.backgroundImage = null;
|
||||
canvas.overlayImage = null;
|
||||
canvas.renderOnAddRemove = true;
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue