Add SVG switch support (#1597)

SVG <switch> is simply parsed as a group because conditional attributes
cannot be evaluated in paper.js context.
Relates to #1389
This commit is contained in:
Samuel Asensi 2019-06-07 15:06:46 +02:00 committed by Jürg Lehni
parent 33a5625936
commit 598d9a3356
2 changed files with 20 additions and 1 deletions

View file

@ -303,7 +303,11 @@ new function() {
getPoint(node, 'dx', 'dy')));
text.setContent(node.textContent.trim() || '');
return text;
}
},
// https://www.w3.org/TR/SVG/struct.html#SwitchElement
// Conditional attributes are ignored and all children are rendered.
switch: importGroup
};
// Attributes and Styles

View file

@ -143,6 +143,21 @@ test('Import SVG without insertion', function() {
}, true);
});
test('Import SVG switch', function(assert) {
var done = assert.async();
var svg = '<svg xmlns="http://www.w3.org/2000/svg"><switch><line x1="0" x2="10" y1="0" y2="10" fill="none"></line></switch></svg>';
paper.project.importSVG(svg, {
onLoad: function(item) {
equals(item.className, 'Group');
equals(item.children.length, 1);
equals(item.firstChild.className, 'Group');
equals(item.firstChild.children.length, 1);
equals(item.firstChild.firstChild, new Path([new Point(0, 0), new Point(10, 10)]));
done();
}
});
});
function importSVG(assert, url, message, options) {
var done = assert.async();
project.importSVG(url, {