From 45c1390c4280e3b8ecc2e1fafd700cd09f911c44 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 18 Jun 2021 11:59:50 +0200 Subject: [PATCH] Switch the order of the "display"/"print" intent handling in `XfaLayerBuilder.render` Given that the "print"-intent is special, and that we should always fallback to the "display"-intent, let's ensure that the code actually reflects that. Also, ensure that the method always returns a `Promise` since that's what the documentation says. --- web/xfa_layer_builder.js | 87 ++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/web/xfa_layer_builder.js b/web/xfa_layer_builder.js index 99c95c5de..43ffbe917 100644 --- a/web/xfa_layer_builder.js +++ b/web/xfa_layer_builder.js @@ -43,56 +43,55 @@ class XfaLayerBuilder { * annotations is complete. */ render(viewport, intent = "display") { - if (intent === "display") { - return this.pdfPage - .getXfa() - .then(xfa => { - if (this._cancelled) { - return; - } - const parameters = { - viewport: viewport.clone({ dontFlip: true }), - div: this.div, - xfa, - page: this.pdfPage, - annotationStorage: this.annotationStorage, - }; + if (intent === "print") { + viewport.dontFlip = true; + const parameters = { + viewport, + div: this.div, + xfa: this.xfaHtml, + page: null, + annotationStorage: this.annotationStorage, + intent, + }; - if (this.div) { - XfaLayer.update(parameters); - } else { - // Create an xfa layer div and render the form - this.div = document.createElement("div"); - this.pageDiv.appendChild(this.div); - parameters.div = this.div; + // Create an xfa layer div and render the form + const div = document.createElement("div"); + this.pageDiv.appendChild(div); + parameters.div = div; - XfaLayer.render(parameters); - } - }) - .catch(error => { - console.error(error); - }); + XfaLayer.render(parameters); + return Promise.resolve(); } - // intent === "print". - viewport.dontFlip = true; - const parameters = { - viewport, - div: this.div, - xfa: this.xfaHtml, - page: null, - annotationStorage: this.annotationStorage, - intent, - }; + // intent === "display" + return this.pdfPage + .getXfa() + .then(xfa => { + if (this._cancelled) { + return; + } + const parameters = { + viewport: viewport.clone({ dontFlip: true }), + div: this.div, + xfa, + page: this.pdfPage, + annotationStorage: this.annotationStorage, + }; - // Create an xfa layer div and render the form - const div = document.createElement("div"); - this.pageDiv.appendChild(div); - parameters.div = div; + if (this.div) { + XfaLayer.update(parameters); + } else { + // Create an xfa layer div and render the form + this.div = document.createElement("div"); + this.pageDiv.appendChild(this.div); + parameters.div = this.div; - XfaLayer.render(parameters); - - return null; + XfaLayer.render(parameters); + } + }) + .catch(error => { + console.error(error); + }); } cancel() {