[Pkg-javascript-commits] [pdf.js] 23/116: Add a |textlayerrendered| event

David Prévot taffit at moszumanska.debian.org
Fri Mar 6 16:19:57 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 3f061cef86a5b9f92e9c5f73ee399397cbaba263
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Wed Dec 31 13:10:59 2014 +0100

    Add a |textlayerrendered| event
---
 web/text_layer_builder.js | 15 +++++++++++++--
 web/viewer.js             | 29 +++++++++++++++++------------
 2 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/web/text_layer_builder.js b/web/text_layer_builder.js
index 020dfdf..7483c02 100644
--- a/web/text_layer_builder.js
+++ b/web/text_layer_builder.js
@@ -46,6 +46,7 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
     this.renderingDone = false;
     this.divContentDone = false;
     this.pageIdx = options.pageIndex;
+    this.pageNumber = this.pageIdx + 1;
     this.matches = [];
     this.viewport = options.viewport;
     this.textDivs = [];
@@ -53,6 +54,16 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
   }
 
   TextLayerBuilder.prototype = {
+    _finishRendering: function TextLayerBuilder_finishRendering() {
+      this.renderingDone = true;
+
+      var event = document.createEvent('CustomEvent');
+      event.initCustomEvent('textlayerrendered', true, true, {
+        pageNumber: this.pageNumber
+      });
+      this.textLayerDiv.dispatchEvent(event);
+    },
+
     renderLayer: function TextLayerBuilder_renderLayer() {
       var textLayerFrag = document.createDocumentFragment();
       var textDivs = this.textDivs;
@@ -63,7 +74,7 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
       // No point in rendering many divs as it would make the browser
       // unusable even after the divs are rendered.
       if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
-        this.renderingDone = true;
+        this._finishRendering();
         return;
       }
 
@@ -107,7 +118,7 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
       }
 
       this.textLayerDiv.appendChild(textLayerFrag);
-      this.renderingDone = true;
+      this._finishRendering();
       this.updateMatches();
     },
 
diff --git a/web/viewer.js b/web/viewer.js
index c00a43b..05b3a5c 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -1741,18 +1741,6 @@ document.addEventListener('pagerendered', function (e) {
     Stats.add(pageNumber, pageView.stats);
   }
 
-//#if (FIREFOX || MOZCENTRAL)
-//if (pageView.textLayer && pageView.textLayer.textDivs &&
-//    pageView.textLayer.textDivs.length > 0 &&
-//    !PDFViewerApplication.supportsDocumentColors) {
-//  console.error(mozL10n.get('document_colors_disabled', null,
-//    'PDF documents are not allowed to use their own colors: ' +
-//    '\'Allow pages to choose their own colors\' ' +
-//    'is deactivated in the browser.'));
-//  PDFViewerApplication.fallback();
-//}
-//#endif
-
   if (pageView.error) {
     PDFViewerApplication.error(mozL10n.get('rendering_error', null,
       'An error occurred while rendering the page.'), pageView.error);
@@ -1779,6 +1767,23 @@ document.addEventListener('pagerendered', function (e) {
   }
 }, true);
 
+document.addEventListener('textlayerrendered', function (e) {
+  var pageIndex = e.detail.pageNumber - 1;
+  var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
+
+//#if (FIREFOX || MOZCENTRAL)
+//if (pageView.textLayer && pageView.textLayer.textDivs &&
+//    pageView.textLayer.textDivs.length > 0 &&
+//    !PDFViewerApplication.supportsDocumentColors) {
+//  console.error(mozL10n.get('document_colors_disabled', null,
+//    'PDF documents are not allowed to use their own colors: ' +
+//    '\'Allow pages to choose their own colors\' ' +
+//    'is deactivated in the browser.'));
+//  PDFViewerApplication.fallback();
+//}
+//#endif
+}, true);
+
 window.addEventListener('presentationmodechanged', function (e) {
   var active = e.detail.active;
   var switchInProgress = e.detail.switchInProgress;

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