From 519898357f78aba3bc7a73b6f1ecc70483fb49db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 1 Feb 2016 12:36:42 +0100 Subject: [PATCH] SVG: Fix issue with invalid default stroke-width on IE. Closes #467 --- src/svg/SVGImport.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/svg/SVGImport.js b/src/svg/SVGImport.js index 8559ba76..b43921c3 100644 --- a/src/svg/SVGImport.js +++ b/src/svg/SVGImport.js @@ -175,21 +175,31 @@ new function() { // nodeNames still. var importers = { '#document': function (node, type, options, isRoot) { - var nodes = node.childNodes, - move = !paper.agent.node; + var nodes = node.childNodes; for (var i = 0, l = nodes.length; i < l; i++) { var child = nodes[i], next; if (child.nodeType === 1) { - if (move) { - // NOTE: We need to move the svg node into our current - // document, so default styles apply! + // NOTE: We need to move the SVG node to the current + // document, so default styles apply! For this we create and + // insert a temporary SVG parent node which is removed again + // at the end. This parent node also helps fix a bug on IE. + var body = document.body, + // No need to inherit styles on Node.js + parent = !paper.agent.node && SVGNode.create('svg'); + if (parent) { + body.appendChild(parent); + // If no stroke-width is set, IE/Edge appears to have a + // default of 0.01px. We can set a default style on the + // parent container as a more sensible fall-back. + parent.style.strokeWidth = '1px'; next = child.nextSibling; - document.body.appendChild(child); + parent.appendChild(child); } var item = importSVG(child, options, isRoot); - if (move) { - // After import, we move it back to where it was: + if (parent) { + // After import, move things back to how they were: + body.removeChild(parent); if (next) { node.insertBefore(child, next); } else {