]> git.parisson.com Git - pdf.js.git/commitdiff
Very basic worker implementation
authorJulian Viereck <julian.viereck@gmail.com>
Mon, 5 Sep 2011 23:07:03 +0000 (16:07 -0700)
committerJulian Viereck <julian.viereck@gmail.com>
Thu, 15 Sep 2011 15:14:34 +0000 (08:14 -0700)
web/viewer.html
web/viewer.js
worker.js [new file with mode: 0644]

index a53593df308bc4da35bb9c84f582f5eed55a32be..d236f840e74c0fbe592060695e76e2d14a34d10f 100644 (file)
@@ -11,6 +11,7 @@
         <script type="text/javascript" src="../crypto.js"></script>
         <script type="text/javascript" src="../glyphlist.js"></script>
         <script type="text/javascript" src="../metrics.js"></script>
+        <script type="text/javascript" src="../worker.js"></script>
   </head>
 
   <body>
index d7c9d6b660d90d604f4f41f3728abe514cb1ed23..082dfaa87815e88c76e4ca59e92f15ca8969ef61 100644 (file)
@@ -152,7 +152,7 @@ var PDFView = {
     while (container.hasChildNodes())
       container.removeChild(container.lastChild);
 
-    var pdf = new PDFDoc(new Stream(data));
+    var pdf = new WorkerPDFDoc(data);
     var pagesCount = pdf.numPages;
     document.getElementById('numPages').innerHTML = pagesCount;
 
diff --git a/worker.js b/worker.js
new file mode 100644 (file)
index 0000000..d267350
--- /dev/null
+++ b/worker.js
@@ -0,0 +1,67 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
+
+'use strict';
+
+var WorkerPage = (function() {
+  function constructor(workerPDF, page) {
+    this.workerPDF = workerPDF;
+    this.page = page;
+    
+    this.ref = page.ref;
+  }
+  
+  constructor.prototype = {
+    get width() {
+      return this.page.width;
+    },
+    
+    get height() {
+      return this.page.height;
+    },
+    
+    get stats() {
+      return this.page.stats;
+    },
+    
+    startRendering: function(ctx, callback, errback)  {
+      // TODO: Place the worker magic HERE.
+      this.page.startRendering(ctx, callback, errback);
+    },
+    
+    getLinks: function() {
+      return this.page.getLinks();
+    }
+  };
+  
+  return constructor;
+})();
+
+var WorkerPDFDoc = (function() {
+  function constructor(data) {
+    this.data = data;
+    this.stream = new Stream(data);
+    this.pdf = new PDFDoc(this.stream);
+    
+    this.catalog = this.pdf.catalog;
+    
+    this.pageCache = [];
+  }
+
+  constructor.prototype = {
+    get numPages() {
+      return this.pdf.numPages;
+    },
+    
+    getPage: function(n) {
+      if (this.pageCache[n]) {
+        return this.pageCache[n];
+      }
+      
+      var page = this.pdf.getPage(n);
+      return this.pageCache[n] = new WorkerPage(this, page);
+    }
+  };
+  
+  return constructor;
+})();