]> git.parisson.com Git - pdf.js.git/commitdiff
Mock resource dict, look up fonts
authorChris Jones <jones.chris.g@gmail.com>
Thu, 5 May 2011 17:28:37 +0000 (12:28 -0500)
committerChris Jones <jones.chris.g@gmail.com>
Thu, 5 May 2011 17:28:37 +0000 (12:28 -0500)
pdf.js
test.html

diff --git a/pdf.js b/pdf.js
index a82d92847965a1a167526357968e6c8a1317c71c..4f4d3dc6e95b1e0ead9f5a51bc8a9a31d4c005c5 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -647,7 +647,7 @@ var PDFDoc = (function () {
 var Interpreter = (function() {
     function constructor(xref, resources, catalog, graphics) {
         this.xref = xref;
-        this.resStack = [ resources ];
+        this.res = resources;
         this.catalog = catalog;
         this.gfx = graphics;
     }
@@ -724,7 +724,7 @@ var Interpreter = (function() {
             } },
         Tf: { params: [ "Name", "Num" ],
               op: function(args) {
-                var font = args[0]  // XXX look up
+                var font = this.res.Font[args[0]];
                 this.gfx.setFont(font, args[1]);
             } },
         Td: { params: [ "Num", "Num" ],
@@ -867,7 +867,7 @@ var EchoGraphics = (function() {
             this.printdentln("ET");
         },
         setFont: function(font, size) {
-            this.printdentln("/"+ font +" "+ size +" Tf");
+            this.printdentln("/"+ font.Name +" "+ size +" Tf");
         },
         moveText: function (x, y) {
             this.printdentln(""+ x +" "+ y +" Td");
@@ -1029,8 +1029,7 @@ var CanvasGraphics = (function() {
 
         },
         setFont: function(font, size) {
-            // NYI
-            this.ctx.font = size +'px Helvetica';
+            this.ctx.font = size +'px '+ font.BaseFont;
         },
         moveText: function (x, y) {
             this.moveTo(x, y);
@@ -1098,6 +1097,17 @@ function real(r)    { return new Obj(Obj.Real, r); }
 
 var tests = [
     { name: "Hello world",
+      res: {
+          // XXX not structured correctly
+          Font: {
+              F1: { Type: "Font",
+                    Subtype: "Type1",
+                    Name: "F1",
+                    BaseFont: "Georgia",
+                    Encoding: "MacRomanEncoding"
+              },
+          }
+      },
       objs: [
           cmd("BT"),
           name("F1"), int(24), cmd("Tf"),
@@ -1108,6 +1118,7 @@ var tests = [
           ]
     },
     { name: "Simple graphics",
+      res: { },
       objs: [
           int(150), int(250), cmd("m"),
           int(150), int(350), cmd("l"),
@@ -1135,6 +1146,7 @@ var tests = [
       ]
     },
     { name: "Heart",
+      res: { },
       objs: [
           cmd("q"),
           real(0.9), real(0.0), real(0.0), cmd("rg"),
@@ -1151,6 +1163,7 @@ var tests = [
       ]
     },
     { name: "Rectangle",
+      res: { },
       objs: [
           int(1), int(0), int(0), int(1), int(80), int(80), cmd("cm"),
           int(0), int(72), cmd("m"),
@@ -1171,7 +1184,7 @@ function runEchoTests() {
 
         var output = "";
         var gfx = new EchoGraphics(output);
-        var i = new Interpreter(null, null, null, gfx);
+        var i = new Interpreter(null, test.res, null, gfx);
         i.interpretHelper(new MockParser(test.objs));
 
         print("done.  Output:");
index 16bedf93da6b92a3098f665f755361a06a55830d..5d446c8f5688c3929813bdd78b8e8b7c596bff06 100644 (file)
--- a/test.html
+++ b/test.html
@@ -22,15 +22,15 @@ function load() {
 }
 
 function displayPage(number) {
-    var page = tests[number].objs;
+    var page = tests[number];
     pageDisplay.value = number;
 
     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));
+    var interp = new Interpreter(null, page.res, null, gfx);
+    interp.interpretHelper(new MockParser(page.objs));
     ctx.restore();
 }