From 561faa7c94b5ff29dbd851e7f6c1cca18e656bdf Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 5 Aug 2021 11:32:45 +0200 Subject: [PATCH] Update the Annotation `--zoom-factor` CSS variable when `PDFPageView` is used standalone (PR 13868 follow-up) Without this patch, when using `PDFPageView` directly[1] this CSS variable won't be updated and consequently things won't work as intended. This is purposely implemented such that when a `PDFPageView`-instance is part of a viewer, we don't repeatedly set the CSS variable for every single page. --- [1] See e.g. the "pageviewer" example in the `examples/components/` folder. --- web/base_viewer.js | 2 -- web/pdf_page_view.js | 5 +++++ web/pdf_rendering_queue.js | 7 +++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/web/base_viewer.js b/web/base_viewer.js index ff2840cc6..b872ccac5 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -202,7 +202,6 @@ class BaseViewer { } else { this.renderingQueue = options.renderingQueue; } - this._doc = document.documentElement; this.scroll = watchScroll(this.container, this._scrollUpdate.bind(this)); @@ -708,7 +707,6 @@ class BaseViewer { } return; } - this._doc.style.setProperty("--zoom-factor", newScale); for (let i = 0, ii = this._pages.length; i < ii; i++) { diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index b959657f3..9efa40543 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -110,6 +110,7 @@ class PDFPageView { this.renderingState = RenderingStates.INITIAL; this.resume = null; this._renderError = null; + this._isStandalone = !this.renderingQueue?.hasViewer(); this.annotationLayer = null; this.textLayer = null; @@ -281,6 +282,10 @@ class PDFPageView { if (optionalContentConfigPromise instanceof Promise) { this._optionalContentConfigPromise = optionalContentConfigPromise; } + if (this._isStandalone) { + const doc = document.documentElement; + doc.style.setProperty("--zoom-factor", this.scale); + } const totalRotation = (this.rotation + this.pdfPageRotate) % 360; this.viewport = this.viewport.clone({ diff --git a/web/pdf_rendering_queue.js b/web/pdf_rendering_queue.js index 20f91f30e..5de17d084 100644 --- a/web/pdf_rendering_queue.js +++ b/web/pdf_rendering_queue.js @@ -60,6 +60,13 @@ class PDFRenderingQueue { return this.highestPriorityPage === view.renderingId; } + /** + * @returns {boolean} + */ + hasViewer() { + return !!this.pdfViewer; + } + /** * @param {Object} currentlyVisiblePages */