mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-23 14:02:50 -05:00
Merge pull request #213 from paulkaplan/strip-svg-namespace
Remove "svg:" namespace from svg before importing.
This commit is contained in:
commit
6a7daa83a5
1 changed files with 13 additions and 0 deletions
|
@ -82,6 +82,19 @@ class PaperCanvas extends React.Component {
|
||||||
}
|
}
|
||||||
importSvg (svg, rotationCenterX, rotationCenterY) {
|
importSvg (svg, rotationCenterX, rotationCenterY) {
|
||||||
const paperCanvas = this;
|
const paperCanvas = this;
|
||||||
|
// Pre-process SVG to prevent parsing errors (discussion from #213)
|
||||||
|
// 1. Remove newlines and tab characters, chrome will not load urls with them.
|
||||||
|
// https://www.chromestatus.com/feature/5735596811091968
|
||||||
|
svg = svg.split(/[\n|\r|\t]/).join('');
|
||||||
|
// 2. Remove svg: namespace on elements.
|
||||||
|
svg = svg.split(/<\s*svg:/).join('<');
|
||||||
|
svg = svg.split(/<\/\s*svg:/).join('</');
|
||||||
|
// 3. 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" ');
|
||||||
|
}
|
||||||
paper.project.importSVG(svg, {
|
paper.project.importSVG(svg, {
|
||||||
expandShapes: true,
|
expandShapes: true,
|
||||||
onLoad: function (item) {
|
onLoad: function (item) {
|
||||||
|
|
Loading…
Reference in a new issue