This is an automated email from the ASF dual-hosted git repository. wangzx pushed a commit to branch fix-svg-export in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit e281ee1043301f15e45427e913a35e727c76f25c Author: plainheart <[email protected]> AuthorDate: Sun Nov 22 21:10:08 2020 +0800 fix(toolbox): supprot for downloading exported svg file in IE9. --- src/component/toolbox/feature/SaveAsImage.ts | 29 +++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/component/toolbox/feature/SaveAsImage.ts b/src/component/toolbox/feature/SaveAsImage.ts index 86389da..b0a7b4b 100644 --- a/src/component/toolbox/feature/SaveAsImage.ts +++ b/src/component/toolbox/feature/SaveAsImage.ts @@ -73,7 +73,7 @@ class SaveAsImage extends ToolboxFeature<ToolboxSaveAsImageFeatureOption> { } // IE else { - if (window.navigator.msSaveOrOpenBlob) { + if (window.navigator.msSaveOrOpenBlob || isSvg) { const parts = url.split(','); // data:[<mime type>][;charset=<charset>][;base64],<encoded data> // see https://css-tricks.com/data-uris/ @@ -87,13 +87,28 @@ class SaveAsImage extends ToolboxFeature<ToolboxSaveAsImageFeatureOption> { // there will be an error, for it's not encoded with base64. // (just a url-encoded string through `encodeURIComponent`) base64Encoded && (bstr = atob(bstr)); - let n = bstr.length; - const u8arr = new Uint8Array(n); - while (n--) { - u8arr[n] = bstr.charCodeAt(n); + const filename = title + '.' + type; + if (window.navigator.msSaveOrOpenBlob) { + let n = bstr.length; + const u8arr = new Uint8Array(n); + while (n--) { + u8arr[n] = bstr.charCodeAt(n); + } + const blob = new Blob([u8arr]); + window.navigator.msSaveOrOpenBlob(blob, filename); + } + else { + const frame = document.createElement('iframe'); + document.body.appendChild(frame); + const cw = frame.contentWindow; + const doc = cw.document; + doc.open('image/svg+xml', 'replace'); + doc.write(bstr); + doc.close(); + cw.focus(); + doc.execCommand('SaveAs', true, filename); + document.body.removeChild(frame); } - const blob = new Blob([u8arr]); - window.navigator.msSaveOrOpenBlob(blob, title + '.' + type); } else { const lang = model.get('lang'); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
