]> git.parisson.com Git - pdf.js.git/commitdiff
Dumb text WIP, more UI for test.html
authorChris Jones <jones.chris.g@gmail.com>
Thu, 5 May 2011 01:08:52 +0000 (20:08 -0500)
committerChris Jones <jones.chris.g@gmail.com>
Thu, 5 May 2011 01:08:52 +0000 (20:08 -0500)
pdf.js
test.html

diff --git a/pdf.js b/pdf.js
index 7fcd972b476d47c83c3c47e0a4c40ae64e5c3dd0..a0172264b36bf5d48a7ab975dd7782778863598d 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -817,8 +817,8 @@ var EchoGraphics = (function() {
             this.dedent();
             this.printdentln("ET");
         },
-        setFont: function(font, sizePt) {
-            this.printdentln("/"+ font +" "+ sizePt +" Tf");
+        setFont: function(font, size) {
+            this.printdentln("/"+ font +" "+ size +" Tf");
         },
         moveText: function (x, y) {
             this.printdentln(""+ x +" "+ y +" Td");
@@ -963,7 +963,25 @@ var CanvasGraphics = (function() {
         },
 
         // Clipping
+
         // Text
+        beginText: function() {
+
+        },
+        endText: function() {
+
+        },
+        setFont: function(font, size) {
+            // NYI
+            this.ctx.font = size +'px Helvetica';
+        },
+        moveText: function (x, y) {
+            this.moveTo(x, y);
+        },
+        showText: function(text) {
+            this.ctx.fillText(text, 100, 100);
+        },
+
         // Type3 fonts
 
         // Color
@@ -1001,7 +1019,7 @@ try {
 
 var MockParser = (function() {
     function constructor(objs) {
-        this.objs = objs;
+        this.objs = objs.slice(0);
     }
 
     constructor.prototype = {
index 09d677f036a21dd8788077474f0b9e153ebf3924..22e9101d29ab3e1848f85d6cdae12679e00f4ad4 100644 (file)
--- a/test.html
+++ b/test.html
   </style>
 
   <script type="application/javascript;version=1.8">
-var canvas;
+var canvas, numPages, pageDisplay, pageNum;
 function load() {
     canvas = document.getElementById("canvas");
-    displayPage();
+    pageDisplay = document.getElementById("pageNumber");
+    numPages = tests.length;
+    displayPage(pageNum = 0);
 }
 
-function displayPage() {
-    var page = tests[1].objs;
+function displayPage(number) {
+    var page = tests[number].objs;
+    pageDisplay.value = number;
 
-    var gfx = new CanvasGraphics(canvas.getContext("2d"), 96.0, 96.0, null);
+    var ctx = canvas.getContext("2d");
+    ctx.save();
+    ctx.clearRect(0, 0, canvas.width, canvas.height);
+    var gfx = new CanvasGraphics(ctx, 96.0, 96.0, null);
     var interp = new Interpreter(null, null, null, gfx);
     interp.interpretHelper(new MockParser(page));
+    ctx.restore();
+}
+
+function nextPage() {
+    pageNum = (pageNum + 1) % numPages;
+    displayPage(pageNum);
+}
+
+function prevPage() {
+    pageNum = (pageNum - 1 + numPages) % numPages;
+    displayPage(pageNum);
 }
   </script>
 </head>
 
 <body onload="load();">
   <div>
-    <button>Previous</button>
+    <button onclick="prevPage();">Previous</button>
     <input type="text" id="pageNumber" value="0"></input>
-    <button>Next</button>
+    <button onclick="nextPage();">Next</button>
   <div id="viewer">
     <!-- Canvas dimensions must be specified in CSS pixels.  CSS pixels
       -- are always 96 dpi.  These dimensions are 8.5x11in at 96dpi. -->