Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use fixupSVGString from scratch-svg-renderer #1346

Closed
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/containers/paint-editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,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 @@ -341,6 +342,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
16 changes: 6 additions & 10 deletions src/containers/paper-canvas.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,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.
// TODO: remove
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 @@ -354,6 +349,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