|
|
@ -760,8 +760,10 @@ var Interpreter = (function() { |
|
|
|
interpret: function(obj) { |
|
|
|
interpret: function(obj) { |
|
|
|
return this.interpretHelper(new Parser(new Lexer(obj), true)); |
|
|
|
return this.interpretHelper(new Parser(new Lexer(obj), true)); |
|
|
|
}, |
|
|
|
}, |
|
|
|
interpretHelper: function(parser) { |
|
|
|
interpretHelper: function(mediaBox, parser) { |
|
|
|
this.gfx.beginDrawing(); |
|
|
|
this.gfx.beginDrawing({ x: mediaBox[0], y: mediaBox[1], |
|
|
|
|
|
|
|
width: mediaBox[2] - mediaBox[0], |
|
|
|
|
|
|
|
height: mediaBox[3] - mediaBox[1] }); |
|
|
|
|
|
|
|
|
|
|
|
var args = [ ]; |
|
|
|
var args = [ ]; |
|
|
|
var obj; |
|
|
|
var obj; |
|
|
@ -810,9 +812,12 @@ var EchoGraphics = (function() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype = { |
|
|
|
constructor.prototype = { |
|
|
|
beginDrawing: function () { |
|
|
|
beginDrawing: function(mediaBox) { |
|
|
|
|
|
|
|
this.printdentln("/MediaBox ["+ |
|
|
|
|
|
|
|
mediaBox.x +" "+ mediaBox.y +" "+ |
|
|
|
|
|
|
|
mediaBox.width +" "+ mediaBox.height +" ]"); |
|
|
|
}, |
|
|
|
}, |
|
|
|
endDrawing: function () { |
|
|
|
endDrawing: function() { |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// Graphics state
|
|
|
|
// Graphics state
|
|
|
@ -950,10 +955,11 @@ var CanvasGraphics = (function() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
constructor.prototype = { |
|
|
|
constructor.prototype = { |
|
|
|
beginDrawing: function () { |
|
|
|
beginDrawing: function(mediaBox) { |
|
|
|
|
|
|
|
var cw = this.ctx.canvas.width, ch = this.ctx.canvas.height; |
|
|
|
this.ctx.save(); |
|
|
|
this.ctx.save(); |
|
|
|
this.ctx.scale(1, -1); |
|
|
|
this.ctx.scale(cw / mediaBox.width, -ch / mediaBox.height); |
|
|
|
this.ctx.translate(0, -this.ctx.canvas.height); |
|
|
|
this.ctx.translate(0, -mediaBox.height); |
|
|
|
}, |
|
|
|
}, |
|
|
|
endDrawing: function () { |
|
|
|
endDrawing: function () { |
|
|
|
this.ctx.restore(); |
|
|
|
this.ctx.restore(); |
|
|
@ -1103,11 +1109,12 @@ var tests = [ |
|
|
|
F1: { Type: "Font", |
|
|
|
F1: { Type: "Font", |
|
|
|
Subtype: "Type1", |
|
|
|
Subtype: "Type1", |
|
|
|
Name: "F1", |
|
|
|
Name: "F1", |
|
|
|
BaseFont: "Georgia", |
|
|
|
BaseFont: "Helvetica", |
|
|
|
Encoding: "MacRomanEncoding" |
|
|
|
Encoding: "MacRomanEncoding" |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
mediaBox: [ 0, 0, 612, 792 ], |
|
|
|
objs: [ |
|
|
|
objs: [ |
|
|
|
cmd("BT"), |
|
|
|
cmd("BT"), |
|
|
|
name("F1"), int(24), cmd("Tf"), |
|
|
|
name("F1"), int(24), cmd("Tf"), |
|
|
@ -1119,6 +1126,7 @@ var tests = [ |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ name: "Simple graphics", |
|
|
|
{ name: "Simple graphics", |
|
|
|
res: { }, |
|
|
|
res: { }, |
|
|
|
|
|
|
|
mediaBox: [ 0, 0, 612, 792 ], |
|
|
|
objs: [ |
|
|
|
objs: [ |
|
|
|
int(150), int(250), cmd("m"), |
|
|
|
int(150), int(250), cmd("m"), |
|
|
|
int(150), int(350), cmd("l"), |
|
|
|
int(150), int(350), cmd("l"), |
|
|
@ -1147,6 +1155,7 @@ var tests = [ |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ name: "Heart", |
|
|
|
{ name: "Heart", |
|
|
|
res: { }, |
|
|
|
res: { }, |
|
|
|
|
|
|
|
mediaBox: [ 0, 0, 612, 792 ], |
|
|
|
objs: [ |
|
|
|
objs: [ |
|
|
|
cmd("q"), |
|
|
|
cmd("q"), |
|
|
|
real(0.9), real(0.0), real(0.0), cmd("rg"), |
|
|
|
real(0.9), real(0.0), real(0.0), cmd("rg"), |
|
|
@ -1164,6 +1173,7 @@ var tests = [ |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ name: "Rectangle", |
|
|
|
{ name: "Rectangle", |
|
|
|
res: { }, |
|
|
|
res: { }, |
|
|
|
|
|
|
|
mediaBox: [ 0, 0, 612, 792 ], |
|
|
|
objs: [ |
|
|
|
objs: [ |
|
|
|
int(1), int(0), int(0), int(1), int(80), int(80), cmd("cm"), |
|
|
|
int(1), int(0), int(0), int(1), int(80), int(80), cmd("cm"), |
|
|
|
int(0), int(72), cmd("m"), |
|
|
|
int(0), int(72), cmd("m"), |
|
|
@ -1185,7 +1195,7 @@ function runEchoTests() { |
|
|
|
var output = ""; |
|
|
|
var output = ""; |
|
|
|
var gfx = new EchoGraphics(output); |
|
|
|
var gfx = new EchoGraphics(output); |
|
|
|
var i = new Interpreter(null, test.res, null, gfx); |
|
|
|
var i = new Interpreter(null, test.res, null, gfx); |
|
|
|
i.interpretHelper(new MockParser(test.objs)); |
|
|
|
i.interpretHelper(test.mediaBox, new MockParser(test.objs)); |
|
|
|
|
|
|
|
|
|
|
|
print("done. Output:"); |
|
|
|
print("done. Output:"); |
|
|
|
print(gfx.out); |
|
|
|
print(gfx.out); |
|
|
|