From 575436bafe17612a4d918018a7e88d651b7f916a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 16 Jun 2015 12:21:19 +0200 Subject: [PATCH] Improve handling of SVG defs located in odd places. Relates to #702 --- src/svg/SVGImport.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/svg/SVGImport.js b/src/svg/SVGImport.js index 0c35905b..23bd178a 100644 --- a/src/svg/SVGImport.js +++ b/src/svg/SVGImport.js @@ -87,19 +87,20 @@ new function() { // items and avoid calling applyAttributes() again. project._currentStyle = item._style.clone(); } - // Put defs first, Affinity designer exports defs as last if (isRoot) { - var defsNodes = [], otherNodes = []; - for (var i = 0, l = nodes.length; i < l; i++) { - nodes[i].nodeName.toLowerCase() === 'defs' ? defsNodes.push(nodes[i]) : otherNodes.push(nodes[i]); + // Import all defs first, since in SVG they can be in any location. + // e.g. Affinity Designer exports defs as last. + var defs = node.querySelectorAll('defs'); + for (var i = 0, l = defs.length; i < l; i++) { + importSVG(defs[i], options, false); } - nodes = defsNodes.concat(otherNodes); } // Collect the children in an array and apply them all at once. for (var i = 0, l = nodes.length; i < l; i++) { var childNode = nodes[i], child; if (childNode.nodeType === 1 + && childNode.nodeName.toLowerCase() !== 'defs' && (child = importSVG(childNode, options, false)) && !(child instanceof Symbol)) children.push(child);