Browse Source

Use blobs to set the svg source of an image in the image viewer.

This avoids errors that apparently are typical with using the built in btoa() with unicode text.

Fixes #10014
Jason Grout 4 years ago
parent
commit
6e81317a42
1 changed files with 7 additions and 3 deletions
  1. 7 3
      packages/imageviewer/src/widget.ts

+ 7 - 3
packages/imageviewer/src/widget.ts

@@ -178,11 +178,15 @@ export class ImageViewer extends Widget implements Printing.IPrintable {
     if (!cm) {
       return;
     }
+    const oldurl = this._img.src || '';
     let content = context.model.toString();
-    if (cm.format !== 'base64') {
-      content = btoa(content);
+    if (cm.format === 'base64') {
+      this._img.src = `data:${this._mimeType};base64,${content}`;
+    } else {
+      const a = new Blob([content], {type: this._mimeType});
+      this._img.src = URL.createObjectURL(a);
     }
-    this._img.src = `data:${this._mimeType};base64,${content}`;
+    URL.revokeObjectURL(oldurl);
   }
 
   /**