Skip to content

Commit

Permalink
fix(viewer): Set default size on SVG images if parsing fails in IE11 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jstoffan authored and mergify[bot] committed Nov 22, 2019
1 parent c42e02c commit 4b08683
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/lib/viewers/image/ImageBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4b08683

Please sign in to comment.