Skip to content

Commit 451ec18

Browse files
committed
Use fixupSVGString from scratch-svg-renderer
1 parent a896190 commit 451ec18

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/containers/paint-editor.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ class PaintEditor extends React.Component {
312312
canUndo={this.props.shouldShowUndo}
313313
canvas={this.state.canvas}
314314
colorInfo={this.state.colorInfo}
315+
fixupSvgStringFn={this.props.fixupSvgStringFn}
315316
format={this.props.format}
316317
image={this.props.image}
317318
imageFormat={this.props.imageFormat}
@@ -343,6 +344,7 @@ PaintEditor.propTypes = {
343344
changeColorToEyeDropper: PropTypes.func,
344345
changeMode: PropTypes.func.isRequired,
345346
clearSelectedItems: PropTypes.func.isRequired,
347+
fixupSvgStringFn: PropTypes.func,
346348
format: PropTypes.oneOf(Object.keys(Formats)), // Internal, up-to-date data format
347349
fontInlineFn: PropTypes.func,
348350
handleSwitchToBitmap: PropTypes.func.isRequired,

src/containers/paper-canvas.jsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,11 @@ class PaperCanvas extends React.Component {
193193
}
194194
importSvg (svg, rotationCenterX, rotationCenterY) {
195195
const paperCanvas = this;
196-
// Pre-process SVG to prevent parsing errors (discussion from #213)
197-
// 1. Remove svg: namespace on elements.
198-
svg = svg.split(/<\s*svg:/).join('<');
199-
svg = svg.split(/<\/\s*svg:/).join('</');
200-
// 2. Add root svg namespace if it does not exist.
201-
const svgAttrs = svg.match(/<svg [^>]*>/);
202-
if (svgAttrs && svgAttrs[0].indexOf('xmlns=') === -1) {
203-
svg = svg.replace(
204-
'<svg ', '<svg xmlns="http://www.w3.org/2000/svg" ');
196+
if (this.props.fixupSvgStringFn) {
197+
// Pre-process SVG to prevent parsing errors (discussion from #213)
198+
svg = this.props.fixupSvgStringFn(svg);
199+
} else {
200+
log.error('Some SVGs may crash the paint editor if fixupSvgStringFn prop is not set on PaintEditor.');
205201
}
206202

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

0 commit comments

Comments
 (0)