Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/containers/paper-canvas.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down