From 2ecb90fd45813c41fa1f97d1d0b191a769792a94 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Thu, 5 May 2011 12:28:37 -0500 Subject: [PATCH] Mock resource dict, look up fonts --- pdf.js | 25 +++++++++++++++++++------ test.html | 6 +++--- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pdf.js b/pdf.js index a82d92847..4f4d3dc6e 100644 --- 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:"); diff --git a/test.html b/test.html index 16bedf93d..5d446c8f5 100644 --- 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(); }