From: Vincent Vanwaelscappel Date: Tue, 26 Mar 2024 16:03:07 +0000 (+0100) Subject: wait #6821 @12 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=ce9de1456aa495d12e973b2ad0ff58d51b5ee842;p=fluidbook-html5.git wait #6821 @12 --- diff --git a/js/libs/fluidbook/fluidbook.loader.js b/js/libs/fluidbook/fluidbook.loader.js index e6fbae9c..d72344ce 100644 --- a/js/libs/fluidbook/fluidbook.loader.js +++ b/js/libs/fluidbook/fluidbook.loader.js @@ -685,6 +685,37 @@ FluidbookLoader.prototype = { this._preloadContentLinkTextures(page, this.fluidbook.settings.clinks[page], this.fluidbook.settings.links[page], enter, function (textures, clinks) { if ($this.fluidbook.pagetransitions.flip3d !== false) { + + let drawTexts = function () { + // Draw the texts if necessary + if ($this.getVersionToLoad(page) === 'textasvector' || $this.getVersionToLoad(page) === 'vector') { + if ($this.fluidbook.support.pdftocanvas) { + $this.renderPDFPageToCanvas(page, ctx, dw, dh, function () { + afterTexts(); + }); + } else { + try { + let img = $this.texts[page]; + if (img !== undefined && img !== null) { + img = img.get(0); + if (img.width === 0) { + $this.deletePage(page); + $this._preloadPage(page, callback); + console.warn('failed to load page for drawing texture ', page); + return; + } + ctx.drawImage(img, -1, 0, dw + 2, dh); + } + } catch (e) { + console.warn(e); + } + afterTexts(); + } + } else { + afterTexts(); + } + }; + let dh = screen.height * window.devicePixelRatio * 1.1; let dw = $this.fluidbook.settings.width * (dh / $this.fluidbook.settings.height); let canvas = $(''); @@ -699,10 +730,25 @@ FluidbookLoader.prototype = { ctx.fillStyle = "#FFFFFF"; ctx.fillRect(0, 0, dw, dh); if ($this.backgrounds[page] !== undefined && $this.backgrounds[page] !== null) { - ctx.drawImage($this.backgrounds[page].get(0), 0, 0, dw * 1.002, dh); + let img = $this.backgrounds[page].get(0); + if (img.complete) { + ctx.drawImage(img, 0, 0, dw * 1.002, dh); + drawTexts(); + } else { + let interval = setInterval(function () { + if (img.complete) { + clearInterval(interval); + ctx.drawImage(img, 0, 0, dw * 1.002, dh); + drawTexts(); + } + }); + } } else { + drawTexts(); } + + let afterTexts = function () { // Draw content links if (clinks !== '') { @@ -827,34 +873,6 @@ FluidbookLoader.prototype = { } }; - // Draw the texts if necessary - if ($this.getVersionToLoad(page) === 'textasvector' || $this.getVersionToLoad(page) === 'vector') { - if ($this.fluidbook.support.pdftocanvas) { - $this.renderPDFPageToCanvas(page, ctx, dw, dh, function () { - afterTexts(); - }); - } else { - try { - let img = $this.texts[page]; - if (img !== undefined && img !== null) { - img = img.get(0); - if (img.width === 0) { - $this.deletePage(page); - $this._preloadPage(page, callback); - console.warn('failed to load page for drawing texture ', page); - return; - } - ctx.drawImage(img, -1, 0, dw + 2, dh); - } - } catch (e) { - console.warn(e); - } - afterTexts(); - } - } else { - afterTexts(); - } - } else { callback(); @@ -1214,7 +1232,16 @@ FluidbookLoader.prototype = { var callbackCalled = false; $(img).one('load', function () { - callback(img); + if (img.complete) { + callback(img); + } else { + let interval = setInterval(function () { + if (img.complete) { + clearInterval(interval); + callback(img); + } + }, 100); + } }); $(img).one('error', function () {