Merge branch 'master' of github.com:andreasgal/pdf.js

This commit is contained in:
Andreas Gal 2011-05-10 00:31:51 -07:00
commit f9faa3f34a

192
pdf.js
View File

@ -1566,6 +1566,8 @@ var Interpreter = (function() {
J: gfx.setLineCap, J: gfx.setLineCap,
j: gfx.setLineJoin, j: gfx.setLineJoin,
d: gfx.setDash, d: gfx.setDash,
ri: gfx.setRenderingIntent,
i: gfx.setFlatness,
q: gfx.save, q: gfx.save,
Q: gfx.restore, Q: gfx.restore,
cm: gfx.transform, cm: gfx.transform,
@ -1578,10 +1580,14 @@ var Interpreter = (function() {
re: gfx.rectangle, re: gfx.rectangle,
S: gfx.stroke, S: gfx.stroke,
f: gfx.fill, f: gfx.fill,
"f*": gfx.eoFill,
B: gfx.fillStroke, B: gfx.fillStroke,
b: gfx.closeFillStroke, b: gfx.closeFillStroke,
n: gfx.endPath,
// Clipping // Clipping
W: gfx.clip,
"W*": gfx.eoClip,
// Text // Text
BT: gfx.beginText, BT: gfx.beginText,
@ -1591,19 +1597,30 @@ var Interpreter = (function() {
gfx.setFont(font, size); gfx.setFont(font, size);
}, },
Td: gfx.moveText, Td: gfx.moveText,
Tm: gfx.setTextMatrix,
Tj: gfx.showText, Tj: gfx.showText,
TJ: gfx.showSpacedText, TJ: gfx.showSpacedText,
// Type3 fonts // Type3 fonts
// Color // Color
CS: gfx.setStrokeColorSpace,
cs: gfx.setFillColorSpace,
SC: gfx.setStrokeColor,
SCN: gfx.setStrokeColorN,
sc: gfx.setFillColor,
scn: gfx.setFillColorN,
g: gfx.setFillGray, g: gfx.setFillGray,
RG: gfx.setStrokeRGBColor, RG: gfx.setStrokeRGBColor,
rg: gfx.setFillRGBColor, rg: gfx.setFillRGBColor,
// Shading // Shading
sh: gfx.shadingFill,
// Images // Images
// XObjects // XObjects
Do: gfx.paintXObject,
// Marked content // Marked content
// Compatibility // Compatibility
}; };
@ -1627,11 +1644,10 @@ var Interpreter = (function() {
if (IsCmd(obj)) { if (IsCmd(obj)) {
var cmd = obj.cmd; var cmd = obj.cmd;
var fn = map[cmd]; var fn = map[cmd];
if (fn) { if (fn)
if (fn.length != args.length) // TODO figure out how to type-check vararg functions
error("Invalid number of arguments '" + cmd + "'");
fn.apply(gfx, args); fn.apply(gfx, args);
} else else
error("Unknown command '" + cmd + "'"); error("Unknown command '" + cmd + "'");
args.length = 0; args.length = 0;
} else { } else {
@ -1676,6 +1692,12 @@ var EchoGraphics = (function() {
setDash: function(dashArray, dashPhase) { setDash: function(dashArray, dashPhase) {
this.printdentln(""+ dashArray +" "+ dashPhase +" d"); this.printdentln(""+ dashArray +" "+ dashPhase +" d");
}, },
setRenderingIntent: function(intent) {
this.printdentln("/"+ intent.name + " ri");
},
setFlatness: function(flatness) {
this.printdentln(""+ flatness +" i");
},
save: function() { save: function() {
this.printdentln("q"); this.printdentln("q");
}, },
@ -1711,14 +1733,26 @@ var EchoGraphics = (function() {
fill: function() { fill: function() {
this.printdentln("f"); this.printdentln("f");
}, },
eoFill: function() {
this.printdentln("f*");
},
fillStroke: function() { fillStroke: function() {
this.printdentln("B"); this.printdentln("B");
}, },
closeFillStroke: function() { closeFillStroke: function() {
this.printdentln("b"); this.printdentln("b");
}, },
endPath: function() {
this.printdentln("n");
},
// Clipping // Clipping
clip: function() {
this.printdentln("W");
},
eoClip: function() {
this.printdentln("W*");
},
// Text // Text
beginText: function() { beginText: function() {
@ -1735,6 +1769,10 @@ var EchoGraphics = (function() {
moveText: function (x, y) { moveText: function (x, y) {
this.printdentln(""+ x +" "+ y +" Td"); this.printdentln(""+ x +" "+ y +" Td");
}, },
setTextMatrix: function(a, b, c, d, e, f) {
this.printdentln(""+ a +" "+ b +" "+ c +
" "+d +" "+ e +" "+ f + " Tm");
},
showText: function(text) { showText: function(text) {
this.printdentln("( "+ text +" ) Tj"); this.printdentln("( "+ text +" ) Tj");
}, },
@ -1745,6 +1783,36 @@ var EchoGraphics = (function() {
// Type3 fonts // Type3 fonts
// Color // Color
setStrokeColorSpace: function(space) {
this.printdentln("/"+ space.name +" CS");
},
setFillColorSpace: function(space) {
this.printdentln("/"+ space.name +" cs");
},
setStrokeColor: function(/*...*/) {
this.printdent("");
for (var i = 0; i < arguments.length; ++i)
this.print(""+ arguments[i] +" ");
this.printdentln("SC");
},
setStrokeColorN: function(/*...*/) {
this.printdent("");
for (var i = 0; i < arguments.length; ++i)
this.print(""+ arguments[i] +" ");
this.printdentln("SCN");
},
setFillColor: function(/*...*/) {
this.printdent("");
for (var i = 0; i < arguments.length; ++i)
this.print(""+ arguments[i] +" ");
this.printdentln("sc");
},
setFillColorN: function(/*...*/) {
this.printdent("");
for (var i = 0; i < arguments.length; ++i)
this.print(""+ arguments[i] +" ");
this.printdentln("scn");
},
setFillGray: function(gray) { setFillGray: function(gray) {
this.printdentln(""+ gray +" g"); this.printdentln(""+ gray +" g");
}, },
@ -1756,8 +1824,16 @@ var EchoGraphics = (function() {
}, },
// Shading // Shading
shadingFill: function(entry) {
this.printdentln("/"+ entry.name +" sh");
},
// Images // Images
// XObjects // XObjects
paintXObject: function(obj) {
this.printdentln("/"+ obj.name +" Do");
},
// Marked content // Marked content
// Compatibility // Compatibility
@ -1769,9 +1845,13 @@ var EchoGraphics = (function() {
this.print(str); this.print(str);
this.out += "\n"; this.out += "\n";
}, },
printdentln: function(str) { printdent: function(str) {
this.print(this.indentationStr); this.print(this.indentationStr);
this.println(str); this.print(str);
},
printdentln: function(str) {
this.printdent(str);
this.println("");
}, },
indent: function() { indent: function() {
this.indentation += 2; this.indentation += 2;
@ -1808,10 +1888,13 @@ var CanvasGraphics = (function() {
this.ctx = canvasCtx; this.ctx = canvasCtx;
this.current = new CanvasExtraState(); this.current = new CanvasExtraState();
this.stateStack = [ ]; this.stateStack = [ ];
this.pendingClip = null;
} }
var LINE_CAP_STYLES = [ "butt", "round", "square" ]; var LINE_CAP_STYLES = [ "butt", "round", "square" ];
var LINE_JOIN_STYLES = [ "miter", "round", "bevel" ]; var LINE_JOIN_STYLES = [ "miter", "round", "bevel" ];
var NORMAL_CLIP = {};
var EO_CLIP = {};
constructor.prototype = { constructor.prototype = {
beginDrawing: function(mediaBox) { beginDrawing: function(mediaBox) {
@ -1837,6 +1920,12 @@ var CanvasGraphics = (function() {
setDash: function(dashArray, dashPhase) { setDash: function(dashArray, dashPhase) {
// TODO // TODO
}, },
setRenderingIntent: function(intent) {
// TODO
},
setFlatness: function(flatness) {
// TODO
},
save: function() { save: function() {
this.ctx.save(); this.ctx.save();
this.stateStack.push(this.current); this.stateStack.push(this.current);
@ -1874,6 +1963,10 @@ var CanvasGraphics = (function() {
this.ctx.fill(); this.ctx.fill();
this.consumePath(); this.consumePath();
}, },
eoFill: function() {
// TODO: <canvas> needs to support even-odd winding rule
this.fill();
},
fillStroke: function() { fillStroke: function() {
this.ctx.fill(); this.ctx.fill();
this.ctx.stroke(); this.ctx.stroke();
@ -1882,8 +1975,17 @@ var CanvasGraphics = (function() {
closeFillStroke: function() { closeFillStroke: function() {
return this.fillStroke(); return this.fillStroke();
}, },
endPath: function() {
this.consumePath();
},
// Clipping // Clipping
clip: function() {
this.pendingClip = NORMAL_CLIP;
},
eoClip: function() {
this.pendingClip = EO_CLIP;
},
// Text // Text
beginText: function() { beginText: function() {
@ -1899,10 +2001,13 @@ var CanvasGraphics = (function() {
moveText: function (x, y) { moveText: function (x, y) {
this.current.lineX += x; this.current.lineX += x;
this.current.lineY += y; this.current.lineY += y;
// XXX transform // TODO transform
this.current.curX = this.current.lineX; this.current.curX = this.current.lineX;
this.current.curY = this.current.lineY; this.current.curY = this.current.lineY;
}, },
setTextMatrix: function(a, b, c, d, e, f) {
// TODO
},
showText: function(text) { showText: function(text) {
this.ctx.save(); this.ctx.save();
this.ctx.translate(0, 2 * this.current.curY); this.ctx.translate(0, 2 * this.current.curY);
@ -1929,6 +2034,24 @@ var CanvasGraphics = (function() {
// Type3 fonts // Type3 fonts
// Color // Color
setStrokeColorSpace: function(space) {
// TODO
},
setFillColorSpace: function(space) {
// TODO
},
setStrokeColor: function(/*...*/) {
// TODO
},
setStrokeColorN: function(/*...*/) {
// TODO
},
setFillColor: function(/*...*/) {
// TODO
},
setFillColorN: function(/*...*/) {
// TODO
},
setFillGray: function(gray) { setFillGray: function(gray) {
this.setFillRGBColor(gray, gray, gray); this.setFillRGBColor(gray, gray, gray);
}, },
@ -1939,9 +2062,24 @@ var CanvasGraphics = (function() {
this.ctx.fillStyle = this.makeCssRgb(r, g, b); this.ctx.fillStyle = this.makeCssRgb(r, g, b);
}, },
// Shading
shadingFill: function(entry) {
// TODO
},
// XObjects
paintXObject: function(obj) {
// TODO
},
// Helper functions // Helper functions
consumePath: function() { consumePath: function() {
if (this.pendingClip) {
// TODO: <canvas> needs to support even-odd winding rule
this.ctx.clip();
this.pendingClip = null;
}
this.ctx.beginPath(); this.ctx.beginPath();
}, },
makeCssRgb: function(r, g, b) { makeCssRgb: function(r, g, b) {
@ -2139,6 +2277,46 @@ var tests = [
eof() eof()
], ],
}, },
{ name: "NYI", // check that NYI commands are no-ops
res: { },
mediaBox: [ 0, 0, 612, 792 ],
objs: [
name("Perceptual"), cmd("ri"),
int(2), cmd("i"),
int(1), int(0), int(0), int(1), int(80), int(80), cmd("Tm"),
name("DeviceRGB"), cmd("CS"),
name("DeviceGray"), cmd("cs"),
int(1), int(0), int(0), cmd("SC"),
int(1), int(0), int(0), cmd("SCN"),
int(1), cmd("sc"),
int(1), cmd("scn"),
name("object"), cmd("Do"),
name("shading"), cmd("sh"),
eof()
],
},
{ name: "Broken heart",
res: { },
mediaBox: [ 0, 0, 612, 792 ],
objs: [
cmd("q"),
int(20), int(20), int(60), int(60), cmd("re"),
int(60), int(60), int(60), int(60), cmd("re"),
cmd("W"), cmd("n"),
real(0.9), real(0.0), real(0.0), cmd("rg"),
int(75), int(40), cmd("m"),
int(75), int(37), int(70), int(25), int(50), int(25), cmd("c"),
int(20), int(25), int(20), real(62.5), int(20), real(62.5), cmd("c"),
int(20), int(80), int(40), int(102), int(75), int(120), cmd("c"),
int(110), int(102), int(130), int(80), int(130), real(62.5), cmd("c"),
int(130), real(62.5), int(130), int(25), int(100), int(25), cmd("c"),
int(85), int(25), int(75), int(37), int(75), int(40), cmd("c"),
cmd("f"),
cmd("Q"),
eof()
]
},
]; ];