From b8b9ccf201219fe01d502c9d78e748e937e5e8a3 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Sun, 6 Dec 2020 21:10:20 +0100 Subject: [PATCH] Reset scale when update spread mode --- web/base_viewer.js | 23 ++++++++++++++++++----- web/pdf_single_page_viewer.js | 4 ++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/web/base_viewer.js b/web/base_viewer.js index 060cf331f79bdc..519f35b112aa4a 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -725,6 +725,20 @@ class BaseViewer { } } + /** + * @private + */ + get _pageWidthScaleFactor() { + if ( + this.spreadMode !== SpreadMode.NONE && + this.scrollMode !== ScrollMode.HORIZONTAL && + !this.isInPresentationMode + ) { + return 2; + } + return 1; + } + _setScale(value, noScroll = false) { let scale = parseFloat(value); @@ -735,10 +749,6 @@ class BaseViewer { if (!currentPage) { return; } - const factor = - this.spreadMode === SpreadMode.NONE || this._isScrollModeHorizontal - ? 1 - : 2; const noPadding = this.isInPresentationMode || this.removePageBorders; let hPadding = noPadding ? 0 : SCROLLBAR_PADDING; @@ -750,7 +760,7 @@ class BaseViewer { const pageWidthScale = (((this.container.clientWidth - hPadding) / currentPage.width) * currentPage.scale) / - factor; + this._pageWidthScaleFactor; const pageHeightScale = ((this.container.clientHeight - vPadding) / currentPage.height) * currentPage.scale; @@ -1481,6 +1491,9 @@ class BaseViewer { } this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView = */ true); this.update(); + if (this._currentScaleValue && isNaN(this._currentScaleValue)) { + this._setScale(this._currentScaleValue, true); + } } } diff --git a/web/pdf_single_page_viewer.js b/web/pdf_single_page_viewer.js index 1e835897d08962..20b340e1336d09 100644 --- a/web/pdf_single_page_viewer.js +++ b/web/pdf_single_page_viewer.js @@ -35,6 +35,10 @@ class PDFSinglePageViewer extends BaseViewer { return shadow(this, "_viewerElement", this._shadowViewer); } + get _pageWidthScaleFactor() { + return 1; + } + _resetView() { super._resetView(); this._previousPageNumber = 1;