]> git.parisson.com Git - pdf.js.git/commitdiff
Implement J (line-cap style)
authorChris Jones <jones.chris.g@gmail.com>
Mon, 9 May 2011 23:57:23 +0000 (18:57 -0500)
committerChris Jones <jones.chris.g@gmail.com>
Mon, 9 May 2011 23:57:23 +0000 (18:57 -0500)
pdf.js

diff --git a/pdf.js b/pdf.js
index 2f5847f6a071c0344b0b74a822c33b2f64c1ea70..069a136bace1b095cde9e392291c6991f84ae117 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -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()
+      ],
+    },
 ];