[Pkg-javascript-commits] [pdf.js] 53/157: Prevent re-rendering of pages because of rounding errors when computing the scale value

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 06:46:34 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit d0c071a40d32ccd0c22d1255935fa5407b5274c9
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Thu Oct 30 13:04:01 2014 +0100

    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 <kbd>Ctrl</kbd>+<kbd>0</kbd>, 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 a719d62..8616876 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);
         }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list