Skip to content

Commit 95e9c0e

Browse files
committed
rx or ry single fix
1 parent 1303d66 commit 95e9c0e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/containers/paper-canvas.jsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ class PaperCanvas extends React.Component {
222222
// the viewBox to start at (0, 0), and we need to translate it back for some costumes to render
223223
// correctly.
224224
const parser = new DOMParser();
225+
const serializer = new XMLSerializer();
225226
const svgDom = parser.parseFromString(svg, 'text/xml');
226227
const viewBox = svgDom.documentElement.attributes.viewBox ?
227228
svgDom.documentElement.attributes.viewBox.value.match(/\S+/g) : null;
@@ -231,7 +232,23 @@ class PaperCanvas extends React.Component {
231232
}
232233
}
233234

234-
paper.project.importSVG(svg, {
235+
// pm: Currently paper.js doesn't parse rx or ry attributes if the other isn't present.
236+
const elements = svgDom.querySelectorAll('[rx], [ry]');
237+
238+
elements.forEach(el => {
239+
if (!el.hasAttribute('ry') && el.hasAttribute('rx')) {
240+
const rxValue = el.getAttribute('rx');
241+
el.setAttribute('ry', rxValue);
242+
} else if (!el.hasAttribute('rx') && el.hasAttribute('ry')) {
243+
const ryValue = el.getAttribute('ry');
244+
el.setAttribute('rx', ryValue);
245+
}
246+
});
247+
248+
// pm: We modified the svg, unlike TW
249+
const modifiedSvg = serializer.serializeToString(svgDom);
250+
251+
paper.project.importSVG(modifiedSvg, {
235252
expandShapes: true,
236253
insert: false,
237254
onLoad: function (item) {

0 commit comments

Comments
 (0)