Implement J (line-cap style)

This commit is contained in:
Chris Jones 2011-05-09 18:57:23 -05:00
parent a8d9ab5e62
commit 5bf0818b2e

33
pdf.js
View File

@ -1000,6 +1000,7 @@ var Interpreter = (function() {
this.map = {
// Graphics state
w: gfx.setLineWidth,
J: gfx.setLineCap,
d: gfx.setDash,
q: gfx.save,
Q: gfx.restore,
@ -1105,6 +1106,9 @@ var EchoGraphics = (function() {
setLineWidth: function(width) {
this.printdentln(width +" w");
},
setLineCap: function(style) {
this.printdentln(style +" J");
},
setDash: function(dashArray, dashPhase) {
this.printdentln(""+ dashArray +" "+ dashPhase +" d");
},
@ -1242,6 +1246,8 @@ var CanvasGraphics = (function() {
this.stateStack = [ ];
}
var LINE_CAP_STYLES = [ "butt", "round", "square" ];
constructor.prototype = {
beginDrawing: function(mediaBox) {
var cw = this.ctx.canvas.width, ch = this.ctx.canvas.height;
@ -1257,6 +1263,9 @@ var CanvasGraphics = (function() {
setLineWidth: function(width) {
this.ctx.lineWidth = width;
},
setLineCap: function(style) {
this.ctx.lineCap = LINE_CAP_STYLES[style];
},
setDash: function(dashArray, dashPhase) {
// TODO
},
@ -1511,6 +1520,30 @@ var tests = [
eof()
]
},
{ name: "Line cap",
res: { },
mediaBox: [ 0, 0, 612, 792 ],
objs: [
int(5), cmd("w"),
int(0), cmd("J"), // butt cap
int(100), int(692), cmd("m"),
int(200), int(692), cmd("l"),
cmd("S"),
int(1), cmd("J"), // round cap
int(100), int(686), cmd("m"),
int(200), int(686), cmd("l"),
cmd("S"),
int(2), cmd("J"), // projecting square cap
int(100), int(680), cmd("m"),
int(200), int(680), cmd("l"),
cmd("S"),
eof()
],
},
];