diff --git a/packages/svgcanvas/svg-exec.js b/packages/svgcanvas/svg-exec.js index 1a8fdd01..cb8156e5 100644 --- a/packages/svgcanvas/svg-exec.js +++ b/packages/svgcanvas/svg-exec.js @@ -617,6 +617,7 @@ const setSvgString = (xmlString, preventUndo) => { * `` to the current layer. * @function module:svgcanvas.SvgCanvas#importSvgString * @param {string} xmlString - The SVG as XML text. + * @param {boolean} preserveDimension - A boolean to force to preserve initial dimension of the imported svg (force svgEdit don't apply a transformation on the imported svg) * @fires module:svgcanvas.SvgCanvas#event:changed * @returns {null|Element} This function returns null if the import was unsuccessful, or the element otherwise. * @todo @@ -626,7 +627,7 @@ const setSvgString = (xmlString, preventUndo) => { * arbitrary transform lists, but makes some assumptions about how the transform list * was obtained */ -const importSvgString = (xmlString) => { +const importSvgString = (xmlString, preserveDimension) => { const dataStorage = svgCanvas.getDataStorage() let j let ts @@ -731,8 +732,10 @@ const importSvgString = (xmlString) => { batchCmd.addSubCommand(new InsertElementCommand(useEl)) svgCanvas.clearSelection() - useEl.setAttribute('transform', ts) - recalculateDimensions(useEl) + if (!preserveDimension) { + useEl.setAttribute('transform', ts) + recalculateDimensions(useEl) + } dataStorage.put(useEl, 'symbol', symbol) dataStorage.put(useEl, 'ref', symbol) svgCanvas.addToSelection([useEl]) diff --git a/src/editor/extensions/ext-opensave/ext-opensave.js b/src/editor/extensions/ext-opensave/ext-opensave.js index 3e15ef04..f7d5b388 100644 --- a/src/editor/extensions/ext-opensave/ext-opensave.js +++ b/src/editor/extensions/ext-opensave/ext-opensave.js @@ -63,7 +63,8 @@ export default { if (file.type.includes('svg')) { reader = new FileReader() reader.onloadend = (ev) => { - const newElement = this.svgCanvas.importSvgString(ev.target.result, true) + // imgImport.shiftKey (shift key pressed or not) will determine if import should preserve dimension) + const newElement = this.svgCanvas.importSvgString(ev.target.result, imgImport.shiftKey) this.svgCanvas.alignSelectedElements('m', 'page') this.svgCanvas.alignSelectedElements('c', 'page') // highlight imported element, otherwise we get strange empty selectbox @@ -263,7 +264,8 @@ export default { $click($id('tool_open'), clickOpen.bind(this)) $click($id('tool_save'), clickSave.bind(this, 'save')) $click($id('tool_save_as'), clickSave.bind(this, 'saveas')) - $click($id('tool_import'), () => imgImport.click()) + // tool_import pressed with shiftKey will not scale the SVG + $click($id('tool_import'), (ev) => { imgImport.shiftKey = ev.shiftKey; imgImport.click() }) } } }