[Pkg-javascript-commits] [pdf.js] 06/174: For documents with different page sizes, ensure that the correct page becomes visible on load when e.g. the 'page' hash parameter was provided (bug 1191279, issue 6393)

David Prévot taffit at moszumanska.debian.org
Thu Nov 19 18:44:58 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 59548921d17cc1a00f91e815c23eedd96e5b70d3
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Wed Aug 5 17:35:41 2015 +0200

    For documents with different page sizes, ensure that the correct page becomes visible on load when e.g. the 'page' hash parameter was provided (bug 1191279, issue 6393)
    
    This issue is actually, in a sense, "caused" by the fact that the API/viewer supports partial loading/rendering. Previously when the *entire* document was always fetched before rendering begun, we knew all page sizes in advance and this issue didn't exist.
    
    Now we use the size of *one* page in order to set the initial size of every page, until we've fetched the pages and thus know their correct sizes.
    This means that during loading the size of the pages can change, which may cause the initial position to become scrolled out of view.
    
    The most naive solution to this problem would perhaps be to delay setting the initial position on load for all documents, until all pages are fetched. However I think that would be a *really* bad idea, since doing so would make the initial rendering slower and make it feel sluggish for most documents.
    
    Since there is generally no way of knowing if a document has different sized pages prior to loading it, we can only check once the pages are available.
    Hence this patch, which treats documents with different sized pages as a special case, by re-applying the initial position when all pages have become available.
---
 web/viewer.js | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/web/viewer.js b/web/viewer.js
index 514e0c3..6fd8462 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -790,6 +790,12 @@ var PDFViewerApplication = {
         }
       }
 
+      var initialParams = {
+        destination: self.initialDestination,
+        bookmark: self.initialBookmark,
+        hash: null,
+      };
+
       store.initializedPromise.then(function resolved() {
         var storedHash = null;
         if (self.preferenceShowPreviousViewOnLoad &&
@@ -807,6 +813,8 @@ var PDFViewerApplication = {
         }
         self.setInitialView(storedHash, scale);
 
+        initialParams.hash = storedHash;
+
         // Make all navigation keys work on document load,
         // unless the viewer is embedded in a web page.
         if (!self.isViewerEmbedded) {
@@ -816,6 +824,23 @@ var PDFViewerApplication = {
         console.error(reason);
         self.setInitialView(null, scale);
       });
+
+      // For documents with different page sizes,
+      // ensure that the correct location becomes visible on load.
+      pagesPromise.then(function resolved() {
+        if (!initialParams.destination && !initialParams.bookmark &&
+            !initialParams.hash) {
+          return;
+        }
+        if (self.hasEqualPageSizes) {
+          return;
+        }
+        self.initialDestination = initialParams.destination;
+        self.initialBookmark = initialParams.bookmark;
+
+        self.pdfViewer.currentScaleValue = self.pdfViewer.currentScaleValue;
+        self.setInitialView(initialParams.hash, scale);
+      });
     });
 
     pagesPromise.then(function() {

-- 
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