[Pkg-javascript-commits] [pdf.js] 05/116: Removes PDFPageSource

David Prévot taffit at moszumanska.debian.org
Fri Mar 6 16:19:55 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 fe4ac8678198937aca49c02fb7d2e83de183cd0e
Author: Yury Delendik <ydelendik at mozilla.com>
Date:   Mon Sep 29 08:11:46 2014 -0500

    Removes PDFPageSource
---
 web/pdf_page_view.js  | 20 +----------------
 web/pdf_viewer.js     | 58 +++++++++++++++++++++++-------------------------
 web/thumbnail_view.js | 61 +++++++++++++++++++++++++++++----------------------
 web/viewer.js         |  2 +-
 4 files changed, 64 insertions(+), 77 deletions(-)

diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js
index d0a0818..38556ef 100644
--- a/web/pdf_page_view.js
+++ b/web/pdf_page_view.js
@@ -28,7 +28,6 @@
  * @property {IPDFLinkService} linkService - The navigation/linking service.
  * @property {PDFRenderingQueue} renderingQueue - The rendering queue object.
  * @property {Cache} cache - The page cache.
- * @property {PDFPageSource} pageSource
  * @property {IPDFTextLayerFactory} textLayerFactory
  */
 
@@ -49,7 +48,6 @@ var PDFPageView = (function PDFPageViewClosure() {
     var linkService = options.linkService;
     var renderingQueue = options.renderingQueue;
     var cache = options.cache;
-    var pageSource = options.pageSource;
     var textLayerFactory = options.textLayerFactory;
 
     this.id = id;
@@ -64,7 +62,6 @@ var PDFPageView = (function PDFPageViewClosure() {
     this.linkService = linkService;
     this.renderingQueue = renderingQueue;
     this.cache = cache;
-    this.pageSource = pageSource;
     this.textLayerFactory = textLayerFactory;
 
     this.renderingState = RenderingStates.INITIAL;
@@ -378,28 +375,13 @@ var PDFPageView = (function PDFPageViewClosure() {
     },
 
     draw: function PDFPageView_draw(callback) {
-      var pdfPage = this.pdfPage;
-
-      if (this.pagePdfPromise) {
-        return;
-      }
-      if (!pdfPage) {
-        var promise = this.pageSource.getPage();
-        promise.then(function(pdfPage) {
-          delete this.pagePdfPromise;
-          this.setPdfPage(pdfPage);
-          this.draw(callback);
-        }.bind(this));
-        this.pagePdfPromise = promise;
-        return;
-      }
-
       if (this.renderingState !== RenderingStates.INITIAL) {
         console.error('Must be in new state before drawing');
       }
 
       this.renderingState = RenderingStates.RUNNING;
 
+      var pdfPage = this.pdfPage;
       var viewport = this.viewport;
       var div = this.div;
       // Wrap the canvas so if it has a css transform for highdpi the overflow
diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js
index 292d765..6441eae 100644
--- a/web/pdf_viewer.js
+++ b/web/pdf_viewer.js
@@ -235,7 +235,6 @@ var PDFViewer = (function pdfViewer() {
         var scale = this._currentScale || 1.0;
         var viewport = pdfPage.getViewport(scale * CSS_UNITS);
         for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
-          var pageSource = new PDFPageSource(pdfDocument, pageNum);
           var textLayerFactory = null;
           if (!PDFJS.disableTextLayer) {
             textLayerFactory = this;
@@ -248,7 +247,6 @@ var PDFViewer = (function pdfViewer() {
             linkService: this.linkService,
             renderingQueue: this.renderingQueue,
             cache: this.cache,
-            pageSource: pageSource,
             textLayerFactory: textLayerFactory
           });
           bindOnAfterDraw(pageView);
@@ -299,6 +297,7 @@ var PDFViewer = (function pdfViewer() {
       this._currentScaleValue = null;
       this.location = null;
       this._pagesRotation = 0;
+      this._pagesRequests = [];
 
       var container = this.viewer;
       while (container.hasChildNodes()) {
@@ -614,13 +613,38 @@ var PDFViewer = (function pdfViewer() {
       }
     },
 
+    /**
+     * @param {PDFPageView} pageView
+     * @returns {PDFPage}
+     * @private
+     */
+    _ensurePdfPageLoaded: function (pageView) {
+      if (pageView.pdfPage) {
+        return Promise.resolve(pageView.pdfPage);
+      }
+      var pageNumber = pageView.id;
+      if (this._pagesRequests[pageNumber]) {
+        return this._pagesRequests[pageNumber];
+      }
+      var promise = this.pdfDocument.getPage(pageNumber).then(
+          function (pdfPage) {
+        pageView.setPdfPage(pdfPage);
+        this._pagesRequests[pageNumber] = null;
+        return pdfPage;
+      }.bind(this));
+      this._pagesRequests[pageNumber] = promise;
+      return promise;
+    },
+
     forceRendering: function (currentlyVisiblePages) {
       var visiblePages = currentlyVisiblePages || this._getVisiblePages();
       var pageView = this.renderingQueue.getHighestPriority(visiblePages,
                                                             this.pages,
                                                             this.scroll.down);
       if (pageView) {
-        this.renderingQueue.renderView(pageView);
+        this._ensurePdfPageLoaded(pageView).then(function () {
+          this.renderingQueue.renderView(pageView);
+        }.bind(this));
         return true;
       }
       return false;
@@ -705,31 +729,3 @@ var SimpleLinkService = (function SimpleLinkServiceClosure() {
   };
   return SimpleLinkService;
 })();
-
-/**
- * PDFPage object source.
- * @class
- */
-var PDFPageSource = (function PDFPageSourceClosure() {
-  /**
-   * @constructs
-   * @param {PDFDocument} pdfDocument
-   * @param {number} pageNumber
-   * @constructor
-   */
-  function PDFPageSource(pdfDocument, pageNumber) {
-    this.pdfDocument = pdfDocument;
-    this.pageNumber = pageNumber;
-  }
-
-  PDFPageSource.prototype = /** @lends PDFPageSource.prototype */ {
-    /**
-     * @returns {Promise<PDFPage>}
-     */
-    getPage: function () {
-      return this.pdfDocument.getPage(this.pageNumber);
-    }
-  };
-
-  return PDFPageSource;
-})();
diff --git a/web/thumbnail_view.js b/web/thumbnail_view.js
index 1e16a7d..f8c207e 100644
--- a/web/thumbnail_view.js
+++ b/web/thumbnail_view.js
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals mozL10n, RenderingStates, Promise, scrollIntoView, PDFPageSource,
+/* globals mozL10n, RenderingStates, Promise, scrollIntoView,
            watchScroll, getVisibleElements */
 
 'use strict';
@@ -28,13 +28,11 @@ var THUMBNAIL_SCROLL_MARGIN = -19;
  * @param defaultViewport
  * @param linkService
  * @param renderingQueue
- * @param pageSource
  *
  * @implements {IRenderableView}
  */
 var ThumbnailView = function thumbnailView(container, id, defaultViewport,
-                                           linkService, renderingQueue,
-                                           pageSource) {
+                                           linkService, renderingQueue) {
   var anchor = document.createElement('a');
   anchor.href = linkService.getAnchorUrl('#page=' + id);
   anchor.title = mozL10n.get('thumb_page_title', {page: id}, 'Page {{page}}');
@@ -80,7 +78,6 @@ var ThumbnailView = function thumbnailView(container, id, defaultViewport,
   this.hasImage = false;
   this.renderingState = RenderingStates.INITIAL;
   this.renderingQueue = renderingQueue;
-  this.pageSource = pageSource;
 
   this.setPdfPage = function thumbnailViewSetPdfPage(pdfPage) {
     this.pdfPage = pdfPage;
@@ -143,15 +140,6 @@ var ThumbnailView = function thumbnailView(container, id, defaultViewport,
   };
 
   this.draw = function thumbnailViewDraw(callback) {
-    if (!this.pdfPage) {
-      var promise = this.pageSource.getPage(this.id);
-      promise.then(function(pdfPage) {
-        this.setPdfPage(pdfPage);
-        this.draw(callback);
-      }.bind(this));
-      return;
-    }
-
     if (this.renderingState !== RenderingStates.INITIAL) {
       console.error('Must be in new state before drawing');
     }
@@ -204,18 +192,14 @@ var ThumbnailView = function thumbnailView(container, id, defaultViewport,
     return tempCanvas;
   }
 
-  this.setImage = function thumbnailViewSetImage(img) {
-    if (!this.pdfPage) {
-      var promise = this.pageSource.getPage();
-      promise.then(function(pdfPage) {
-        this.setPdfPage(pdfPage);
-        this.setImage(img);
-      }.bind(this));
-      return;
-    }
+  this.setImage = function thumbnailViewSetImage(pageView) {
+    var img = pageView.canvas;
     if (this.hasImage || !img) {
       return;
     }
+    if (this.pdfPage) {
+      this.setPdfPage(pageView.pdfPage);
+    }
     this.renderingState = RenderingStates.FINISHED;
     var ctx = this.getPageDrawContext();
 
@@ -330,6 +314,7 @@ var PDFThumbnailViewer = (function pdfThumbnailViewer() {
     _resetView: function () {
       this.thumbnails = [];
       this._pagesRotation = 0;
+      this._pagesRequests = [];
     },
 
     setDocument: function (pdfDocument) {
@@ -351,15 +336,37 @@ var PDFThumbnailViewer = (function pdfThumbnailViewer() {
         var pagesCount = pdfDocument.numPages;
         var viewport = firstPage.getViewport(1.0);
         for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
-          var pageSource = new PDFPageSource(pdfDocument, pageNum);
           var thumbnail = new ThumbnailView(this.container, pageNum,
                                             viewport.clone(), this.linkService,
-                                            this.renderingQueue, pageSource);
+                                            this.renderingQueue);
           this.thumbnails.push(thumbnail);
         }
       }.bind(this));
     },
 
+    /**
+     * @param {PDFPageView} pageView
+     * @returns {PDFPage}
+     * @private
+     */
+    _ensurePdfPageLoaded: function (thumbView) {
+      if (thumbView.pdfPage) {
+        return Promise.resolve(thumbView.pdfPage);
+      }
+      var pageNumber = thumbView.id;
+      if (this._pagesRequests[pageNumber]) {
+        return this._pagesRequests[pageNumber];
+      }
+      var promise = this.pdfDocument.getPage(pageNumber).then(
+        function (pdfPage) {
+          thumbView.setPdfPage(pdfPage);
+          this._pagesRequests[pageNumber] = null;
+          return pdfPage;
+        }.bind(this));
+      this._pagesRequests[pageNumber] = promise;
+      return promise;
+    },
+
     ensureThumbnailVisible:
         function PDFThumbnailViewer_ensureThumbnailVisible(page) {
       // Ensure that the thumbnail of the current page is visible
@@ -373,7 +380,9 @@ var PDFThumbnailViewer = (function pdfThumbnailViewer() {
                                                              this.thumbnails,
                                                              this.scroll.down);
       if (thumbView) {
-        this.renderingQueue.renderView(thumbView);
+        this._ensurePdfPageLoaded(thumbView).then(function () {
+          this.renderingQueue.renderView(thumbView);
+        }.bind(this));
         return true;
       }
       return false;
diff --git a/web/viewer.js b/web/viewer.js
index 5528dd3..802d554 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -1734,7 +1734,7 @@ document.addEventListener('pagerendered', function (e) {
   var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
   var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.
                       getThumbnail(pageIndex);
-  thumbnailView.setImage(pageView.canvas);
+  thumbnailView.setImage(pageView);
 
 //#if (FIREFOX || MOZCENTRAL)
 //if (pageView.textLayer && pageView.textLayer.textDivs &&

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