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 9, 2021
1 parent a896190 commit 451ec18
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/containers/paint-editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ class PaintEditor extends React.Component {
canUndo={this.props.shouldShowUndo}
canvas={this.state.canvas}
colorInfo={this.state.colorInfo}
fixupSvgStringFn={this.props.fixupSvgStringFn}
format={this.props.format}
image={this.props.image}
imageFormat={this.props.imageFormat}
Expand Down Expand Up @@ -343,6 +344,7 @@ PaintEditor.propTypes = {
changeColorToEyeDropper: PropTypes.func,
changeMode: PropTypes.func.isRequired,
clearSelectedItems: PropTypes.func.isRequired,
fixupSvgStringFn: PropTypes.func,
format: PropTypes.oneOf(Object.keys(Formats)), // Internal, up-to-date data format
fontInlineFn: PropTypes.func,
handleSwitchToBitmap: PropTypes.func.isRequired,
Expand Down
15 changes: 6 additions & 9 deletions src/containers/paper-canvas.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,11 @@ 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" ');
if (this.props.fixupSvgStringFn) {
// Pre-process SVG to prevent parsing errors (discussion from #213)
svg = this.props.fixupSvgStringFn(svg);
} else {
log.error('Some SVGs may crash the paint editor if fixupSvgStringFn prop is not set on PaintEditor.');
}

// Get the origin which the viewBox is defined relative to. During import, Paper will translate
Expand Down Expand Up @@ -351,6 +347,7 @@ PaperCanvas.propTypes = {
clearSelectedItems: PropTypes.func.isRequired,
clearUndo: PropTypes.func.isRequired,
cursor: PropTypes.string,
fixupSvgStringFn: PropTypes.func,
format: PropTypes.oneOf(Object.keys(Formats)),
image: PropTypes.oneOfType([
PropTypes.string,
Expand Down

0 comments on commit 451ec18

Please sign in to comment.