[Pkg-javascript-commits] [pdf.js] 10/116: Refactors draw method in PDFPageView; makes optional some PDFPageViewOptions options

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 2565e627a31dccd562133d2e0f91413f09f302a5
Author: Yury Delendik <ydelendik at mozilla.com>
Date:   Wed Dec 17 14:47:14 2014 -0600

    Refactors draw method in PDFPageView; makes optional some PDFPageViewOptions options
---
 web/annotations_layer_builder.js | 19 +++++++++++++++++++
 web/interfaces.js                |  4 ++--
 web/pdf_page_view.js             | 36 +++++++++++++++++++++++++++---------
 web/pdf_rendering_queue.js       |  5 ++++-
 web/text_layer_builder.js        | 21 +++++++++++++++++++++
 web/thumbnail_view.js            | 16 +++++++++++-----
 6 files changed, 84 insertions(+), 17 deletions(-)

diff --git a/web/annotations_layer_builder.js b/web/annotations_layer_builder.js
index 309f7c0..494ceff 100644
--- a/web/annotations_layer_builder.js
+++ b/web/annotations_layer_builder.js
@@ -154,3 +154,22 @@ var AnnotationsLayerBuilder = (function AnnotationsLayerBuilderClosure() {
   };
   return AnnotationsLayerBuilder;
 })();
+
+/**
+ * @constructor
+ * @implements IPDFAnnotationsLayerFactory
+ */
+function DefaultAnnotationsLayerFactory() {}
+DefaultAnnotationsLayerFactory.prototype = {
+  /**
+   * @param {HTMLDivElement} pageDiv
+   * @param {PDFPage} pdfPage
+   * @returns {AnnotationsLayerBuilder}
+   */
+  createAnnotationsLayerBuilder: function (pageDiv, pdfPage) {
+    return new AnnotationsLayerBuilder({
+      pageDiv: pageDiv,
+      pdfPage: pdfPage
+    });
+  }
+};
diff --git a/web/interfaces.js b/web/interfaces.js
index b99338c..37a7b19 100644
--- a/web/interfaces.js
+++ b/web/interfaces.js
@@ -67,9 +67,9 @@ IRenderableView.prototype = {
    */
   get renderingState() {},
   /**
-   * @param {function} callback - The draw completion callback.
+   * @returns {Promise} Resolved on draw completion.
    */
-  draw: function (callback) {},
+  draw: function () {},
   resume: function () {},
 };
 
diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js
index 50d3c2b..cb0725a 100644
--- a/web/pdf_page_view.js
+++ b/web/pdf_page_view.js
@@ -14,7 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals RenderingStates, PDFJS, CustomStyle, CSS_UNITS, getOutputScale  */
+/* globals RenderingStates, PDFJS, CustomStyle, CSS_UNITS, getOutputScale,
+           TextLayerBuilder, AnnotationsLayerBuilder, Promise */
 
 'use strict';
 
@@ -286,7 +287,7 @@ var PDFPageView = (function PDFPageViewClosure() {
       return this.viewport.convertToPdfPoint(x, y);
     },
 
-    draw: function PDFPageView_draw(callback) {
+    draw: function PDFPageView_draw() {
       if (this.renderingState !== RenderingStates.INITIAL) {
         console.error('Must be in new state before drawing');
       }
@@ -373,6 +374,12 @@ var PDFPageView = (function PDFPageViewClosure() {
         ctx.scale(outputScale.sx, outputScale.sy);
       }
 
+      var resolveRenderPromise, rejectRenderPromise;
+      var promise = new Promise(function (resolve, reject) {
+        resolveRenderPromise = resolve;
+        rejectRenderPromise = reject;
+      });
+
       // Rendering area
 
       var self = this;
@@ -385,6 +392,7 @@ var PDFPageView = (function PDFPageViewClosure() {
         }
 
         if (error === 'cancelled') {
+          rejectRenderPromise(error);
           return;
         }
 
@@ -412,14 +420,16 @@ var PDFPageView = (function PDFPageViewClosure() {
         });
         div.dispatchEvent(event);
 
-        callback();
+        if (!error) {
+          resolveRenderPromise(undefined);
+        } else {
+          rejectRenderPromise(error);
+        }
       }
 
-      var renderContext = {
-        canvasContext: ctx,
-        viewport: this.viewport,
-        // intent: 'default', // === 'display'
-        continueCallback: function pdfViewcContinueCallback(cont) {
+      var renderContinueCallback = null;
+      if (this.renderingQueue) {
+        renderContinueCallback = function renderContinueCallback(cont) {
           if (!self.renderingQueue.isHighestPriority(self)) {
             self.renderingState = RenderingStates.PAUSED;
             self.resume = function resumeCallback() {
@@ -429,7 +439,14 @@ var PDFPageView = (function PDFPageViewClosure() {
             return;
           }
           cont();
-        }
+        };
+      }
+
+      var renderContext = {
+        canvasContext: ctx,
+        viewport: this.viewport,
+        // intent: 'default', // === 'display'
+        continueCallback: renderContinueCallback
       };
       var renderTask = this.renderTask = this.pdfPage.render(renderContext);
 
@@ -462,6 +479,7 @@ var PDFPageView = (function PDFPageViewClosure() {
       if (self.onBeforeDraw) {
         self.onBeforeDraw();
       }
+      return promise;
     },
 
     beforePrint: function PDFPageView_beforePrint() {
diff --git a/web/pdf_rendering_queue.js b/web/pdf_rendering_queue.js
index c7b1b3a..b17a1ee 100644
--- a/web/pdf_rendering_queue.js
+++ b/web/pdf_rendering_queue.js
@@ -165,7 +165,10 @@ var PDFRenderingQueue = (function PDFRenderingQueueClosure() {
           break;
         case RenderingStates.INITIAL:
           this.highestPriorityPage = view.renderingId;
-          view.draw(this.renderHighestPriority.bind(this));
+          var continueRendering = function () {
+            this.renderHighestPriority();
+          }.bind(this);
+          view.draw().then(continueRendering, continueRendering);
           break;
       }
       return true;
diff --git a/web/text_layer_builder.js b/web/text_layer_builder.js
index d300f63..020dfdf 100644
--- a/web/text_layer_builder.js
+++ b/web/text_layer_builder.js
@@ -385,3 +385,24 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
   };
   return TextLayerBuilder;
 })();
+
+/**
+ * @constructor
+ * @implements IPDFTextLayerFactory
+ */
+function DefaultTextLayerFactory() {}
+DefaultTextLayerFactory.prototype = {
+  /**
+   * @param {HTMLDivElement} textLayerDiv
+   * @param {number} pageIndex
+   * @param {PageViewport} viewport
+   * @returns {TextLayerBuilder}
+   */
+  createTextLayerBuilder: function (textLayerDiv, pageIndex, viewport) {
+    return new TextLayerBuilder({
+      textLayerDiv: textLayerDiv,
+      pageIndex: pageIndex,
+      viewport: viewport
+    });
+  }
+};
diff --git a/web/thumbnail_view.js b/web/thumbnail_view.js
index f8c207e..e07ab3a 100644
--- a/web/thumbnail_view.js
+++ b/web/thumbnail_view.js
@@ -139,17 +139,22 @@ var ThumbnailView = function thumbnailView(container, id, defaultViewport,
     return !this.hasImage;
   };
 
-  this.draw = function thumbnailViewDraw(callback) {
+  this.draw = function thumbnailViewDraw() {
     if (this.renderingState !== RenderingStates.INITIAL) {
       console.error('Must be in new state before drawing');
     }
 
     this.renderingState = RenderingStates.RUNNING;
     if (this.hasImage) {
-      callback();
-      return;
+      return Promise.resolve(undefined);
     }
 
+    var resolveRenderPromise, rejectRenderPromise;
+    var promise = new Promise(function (resolve, reject) {
+      resolveRenderPromise = resolve;
+      rejectRenderPromise = reject;
+    });
+
     var self = this;
     var ctx = this.getPageDrawContext();
     var drawViewport = this.viewport.clone({ scale: this.scale });
@@ -171,14 +176,15 @@ var ThumbnailView = function thumbnailView(container, id, defaultViewport,
     this.pdfPage.render(renderContext).promise.then(
       function pdfPageRenderCallback() {
         self.renderingState = RenderingStates.FINISHED;
-        callback();
+        resolveRenderPromise(undefined);
       },
       function pdfPageRenderError(error) {
         self.renderingState = RenderingStates.FINISHED;
-        callback();
+        rejectRenderPromise(error);
       }
     );
     this.hasImage = true;
+    return promise;
   };
 
   function getTempCanvas(width, height) {

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