Skip to content

Commit

Permalink
Use fixupSVGString from scratch-svg-renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
adroitwhiz committed Jan 7, 2021
1 parent cdf0afc commit d606825
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/containers/paper-canvas.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import React from 'react';
import {connect} from 'react-redux';
import paper from '@scratch/paper';
import {fixupSvgString} from 'scratch-svg-renderer';
import Formats from '../lib/format';
import log from '../log/log';

Expand Down Expand Up @@ -194,15 +195,7 @@ class PaperCanvas extends React.Component {
importSvg (svg, rotationCenterX, rotationCenterY) {
const paperCanvas = this;
// Pre-process SVG to prevent parsing errors (discussion from #213)
// 1. Remove svg: namespace on elements.
svg = svg.split(/<\s*svg:/).join('<');
svg = svg.split(/<\/\s*svg:/).join('</');
// 2. Add root svg namespace if it does not exist.
const svgAttrs = svg.match(/<svg [^>]*>/);
if (svgAttrs && svgAttrs[0].indexOf('xmlns=') === -1) {
svg = svg.replace(
'<svg ', '<svg xmlns="http://www.w3.org/2000/svg" ');
}
svg = fixupSvgString(svg);

// Get the origin which the viewBox is defined relative to. During import, Paper will translate
// the viewBox to start at (0, 0), and we need to translate it back for some costumes to render
Expand Down

0 comments on commit d606825

Please sign in to comment.