From d0c071a40d32ccd0c22d1255935fa5407b5274c9 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 30 Oct 2014 13:04:01 +0100 Subject: [PATCH] Prevent re-rendering of pages because of rounding errors when computing the scale value Currently if the zoom level is reset multiple times in a row, i.e. by pressing Ctrl+0, the pages can be re-rendered each time even though their size shouldn't change. Whether this happens can depend on the size of the viewer, but documents with pages in landscape mode seem to be very susceptible to this. (An example is: https://wiki.mozilla.org/images/5/55/MobileOpportunity.pdf.) This can also effect documents with pages in portrait mode, when they are displayed in Presentation Mode. The reason for this unnecessary re-rendering is that due to limited numerical precision, the new scale value may change in *only* the last decimal place. --- web/pdf_viewer.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index a719d6201..861687626 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -74,6 +74,18 @@ var PDFViewer = (function pdfViewer() { }; } + function isSameScale(oldScale, newScale) { + if (newScale === oldScale) { + return true; + } + if (Math.abs(newScale - oldScale) < 1e-15) { + // Prevent unnecessary re-rendering of all pages when the scale + // changes only because of limited numerical precision. + return true; + } + return false; + } + /** * @constructs PDFViewer * @param {PDFViewerOptions} options @@ -367,7 +379,8 @@ var PDFViewer = (function pdfViewer() { _setScaleUpdatePages: function pdfViewer_setScaleUpdatePages( newScale, newValue, noScroll, preset) { this._currentScaleValue = newValue; - if (newScale === this._currentScale) { + + if (isSameScale(this._currentScale, newScale)) { if (preset) { this._setScaleDispatchEvent(newScale, newValue, true); }