From eec221786be7a1348602621c219a1656c593affb Mon Sep 17 00:00:00 2001 From: Cubester Date: Sat, 13 Jul 2024 18:43:30 -0400 Subject: [PATCH] Fix rx and ry problems --- src/containers/paper-canvas.jsx | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/containers/paper-canvas.jsx b/src/containers/paper-canvas.jsx index 233285a447..798190d5d2 100644 --- a/src/containers/paper-canvas.jsx +++ b/src/containers/paper-canvas.jsx @@ -222,6 +222,7 @@ class PaperCanvas extends React.Component { // the viewBox to start at (0, 0), and we need to translate it back for some costumes to render // correctly. const parser = new DOMParser(); + const serializer = new XMLSerializer(); const svgDom = parser.parseFromString(svg, 'text/xml'); const viewBox = svgDom.documentElement.attributes.viewBox ? svgDom.documentElement.attributes.viewBox.value.match(/\S+/g) : null; @@ -231,7 +232,28 @@ class PaperCanvas extends React.Component { } } - paper.project.importSVG(svg, { + // TW: paper.js for some reason ignores rx or ry values if it's missing the other. + svgDom.querySelectorAll('[rx], [ry]').forEach(element => { + if ( + element.hasAttribute('rx') && + !element.hasAttribute('ry') + ) { + element.setAttribute( + element.getAttribute('rx'), + 'ry' + ); + } else if ( + !element.hasAttribute('rx') && + element.hasAttribute('ry') + ) { + element.setAttribute( + 'rx', + element.getAttribute('ry') + ); + } + }); + + paper.project.importSVG(serializer.serializeToString(svgDom), { expandShapes: true, insert: false, onLoad: function (item) {