From 598d9a3356ca4be1a62fbd880940f644ad5939de Mon Sep 17 00:00:00 2001 From: Samuel Asensi Date: Fri, 7 Jun 2019 15:06:46 +0200 Subject: [PATCH] Add SVG switch support (#1597) SVG is simply parsed as a group because conditional attributes cannot be evaluated in paper.js context. Relates to #1389 --- src/svg/SvgImport.js | 6 +++++- test/tests/SvgImport.js | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/svg/SvgImport.js b/src/svg/SvgImport.js index 829d7b19..2deb2b8c 100644 --- a/src/svg/SvgImport.js +++ b/src/svg/SvgImport.js @@ -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 diff --git a/test/tests/SvgImport.js b/test/tests/SvgImport.js index a0c3e261..fbd13ff2 100644 --- a/test/tests/SvgImport.js +++ b/test/tests/SvgImport.js @@ -143,6 +143,21 @@ test('Import SVG without insertion', function() { }, true); }); +test('Import SVG switch', function(assert) { + var done = assert.async(); + var 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, {