From c9edcbe41d6f3e100561ce21273ae5a81c1d0537 Mon Sep 17 00:00:00 2001 From: Justin Harrell Date: Tue, 19 Sep 2017 15:49:38 -0400 Subject: [PATCH] IE11 svg image fixes --- lib/network/CachedImage.js | 25 ++++++++++++++++++------- lib/network/Images.js | 1 + 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/network/CachedImage.js b/lib/network/CachedImage.js index fde6cb054..675f352b7 100644 --- a/lib/network/CachedImage.js +++ b/lib/network/CachedImage.js @@ -31,17 +31,28 @@ class CachedImage { this.width = w; this.height = h; + var h2 = Math.floor(h/2); + var h4 = Math.floor(h/4); + var h8 = Math.floor(h/8); + var h16 = Math.floor(h/16); + + var w2 = Math.floor(w/2); + var w4 = Math.floor(w/4); + var w8 = Math.floor(w/8); + var w16 = Math.floor(w/16); + // Make canvas as small as possible - this.canvas.width = 3*w/4; - this.canvas.height = h/2; + this.canvas.width = 3*w4; + this.canvas.height = h2; // Coordinates and sizes of images contained in the canvas // Values per row: [top x, left y, width, height] + this.coordinates = [ - [ 0 , 0 , w/2 , h/2], - [ w/2 , 0 , w/4 , h/4], - [ w/2 , h/4, w/8 , h/8], - [ 5*w/8, h/4, w/16, h/16] + [ 0 , 0 , w2 , h2], + [ w2 , 0 , w4 , h4], + [ w2 , h4, w8 , h8], + [ 5*w8, h4, w16, h16] ]; this._fillMipMap(); @@ -152,7 +163,7 @@ class CachedImage { // naturalHeight. These give the true size of the image. If it failed // to load, either of these should be zero. - if (typeof img.naturalWidth !== "undefined" && img.naturalWidth === 0) { + if (typeof img.naturalWidth !== "undefined" && img.naturalWidth === 0 && img.IEFix!==true) { return false; } diff --git a/lib/network/Images.js b/lib/network/Images.js index 7256f2a8f..6f7c0ac80 100644 --- a/lib/network/Images.js +++ b/lib/network/Images.js @@ -97,6 +97,7 @@ class Images { document.body.appendChild(imageToCache); imageToCache.width = imageToCache.offsetWidth; imageToCache.height = imageToCache.offsetHeight; + imageToCache.IEFix = true; document.body.removeChild(imageToCache); } }