From 72d7bfe9b98c0eed64040d0345bc056de92b008b Mon Sep 17 00:00:00 2001 From: Jared Stoffan Date: Thu, 21 Nov 2019 14:28:32 -0800 Subject: [PATCH] fix(viewer): Set default size on SVG images if parsing fails in IE11 --- src/lib/viewers/image/ImageBaseViewer.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lib/viewers/image/ImageBaseViewer.js b/src/lib/viewers/image/ImageBaseViewer.js index fc2a96f11..5100f8aeb 100644 --- a/src/lib/viewers/image/ImageBaseViewer.js +++ b/src/lib/viewers/image/ImageBaseViewer.js @@ -219,18 +219,15 @@ class ImageBaseViewer extends BaseViewer { imageEl.setAttribute('originalHeight', imageEl.naturalHeight); resolve(); } else { - // Case when natural dimensions are not assigned + // Case when natural dimensions are not assigned, such as with SVGs // By default, assigned width and height in Chrome/Safari/Firefox will be 300x150. // IE11 workaround. Dimensions only displayed if the image is attached to the document. this.api .get(imageEl.src, { type: 'text' }) .then(imageAsText => { - const parser = new DOMParser(); - const svgEl = parser.parseFromString(imageAsText, 'image/svg+xml'); - try { - // Assume svgEl is an instanceof an SVG with a viewBox and preserveAspectRatio of meet - // where the height is the limiting axis + const parser = new DOMParser(); + const svgEl = parser.parseFromString(imageAsText, 'image/svg+xml'); // Can throw in IE11 const viewBox = svgEl.documentElement.getAttribute('viewBox'); const [, , w, h] = viewBox.split(' '); const aspectRatio = h ? w / h : w;