var Interpreter = (function() {
function constructor(xref, resources, catalog, graphics) {
this.xref = xref;
- this.resStack = [ resources ];
+ this.res = resources;
this.catalog = catalog;
this.gfx = graphics;
}
} },
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" ],
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");
},
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);
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"),
]
},
{ name: "Simple graphics",
+ res: { },
objs: [
int(150), int(250), cmd("m"),
int(150), int(350), cmd("l"),
]
},
{ name: "Heart",
+ res: { },
objs: [
cmd("q"),
real(0.9), real(0.0), real(0.0), cmd("rg"),
]
},
{ name: "Rectangle",
+ res: { },
objs: [
int(1), int(0), int(0), int(1), int(80), int(80), cmd("cm"),
int(0), int(72), cmd("m"),
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:");
}
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();
}