]> git.parisson.com Git - pdf.js.git/commitdiff
Fix zero width lines.
authorBrendan Dahl <brendan.dahl@gmail.com>
Wed, 18 Jan 2012 04:50:49 +0000 (20:50 -0800)
committerBrendan Dahl <brendan.dahl@gmail.com>
Wed, 18 Jan 2012 04:50:49 +0000 (20:50 -0800)
src/canvas.js
test/pdfs/.gitignore
test/pdfs/zerowidthline.pdf [new file with mode: 0644]
test/test_manifest.json

index 4feac4efec5150dd55f0d84daed1a79a839a29ed..5ef9008610a2b0b12c3978a0b9d516e97476bd05 100644 (file)
@@ -48,6 +48,7 @@ var CanvasExtraState = (function CanvasExtraStateClosure() {
     // Note: fill alpha applies to all non-stroking operations
     this.fillAlpha = 1;
     this.strokeAlpha = 1;
+    this.lineWidth = 1;
 
     this.old = old;
   }
@@ -329,6 +330,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
 
     // Graphics state
     setLineWidth: function canvasGraphicsSetLineWidth(width) {
+      this.current.lineWidth = width;
       this.ctx.lineWidth = width;
     },
     setLineCap: function canvasGraphicsSetLineCap(style) {
@@ -442,6 +444,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
       consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
       var ctx = this.ctx;
       var strokeColor = this.current.strokeColor;
+      if (this.current.lineWidth === 0)
+        ctx.lineWidth = this.getSinglePixelWidth();
       // For stroke we want to temporarily change the global alpha to the
       // stroking alpha.
       ctx.globalAlpha = this.current.strokeAlpha;
@@ -640,7 +644,6 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
         ctx.translate(current.x, current.y);
 
         ctx.scale(textHScale, 1);
-        ctx.lineWidth /= current.textMatrix[0];
 
         if (textSelection) {
           this.save();
@@ -677,7 +680,15 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
       } else {
         ctx.save();
         this.applyTextTransforms();
-        ctx.lineWidth /= current.textMatrix[0] * fontMatrix[0];
+
+        var lineWidth = current.lineWidth;
+        var scale = Math.abs(current.textMatrix[0] * fontMatrix[0]);
+        if (scale == 0 || lineWidth == 0)
+          lineWidth = this.getSinglePixelWidth();
+        else
+          lineWidth /= scale;
+
+        ctx.lineWidth = lineWidth;
 
         if (textSelection)
           text.geom = this.getTextGeometry();
@@ -1142,6 +1153,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
     },
     restoreFillRule: function canvasGraphicsRestoreFillRule(rule) {
       this.ctx.mozFillRule = rule;
+    },
+    getSinglePixelWidth: function getSinglePixelWidth(scale) {
+      var inverse = this.ctx.mozCurrentTransformInverse;
+      return Math.abs(inverse[0] + inverse[2]);
     }
   };
 
index 9569807826a9e3134cbbe89305e082e754125b94..1aae828008a1ba674bb5dcc692f3063f1ac12006 100644 (file)
@@ -22,3 +22,4 @@
 !issue918.pdf
 !smaskdim.pdf
 !type4psfunc.pdf
+!zerowidthline.pdf
diff --git a/test/pdfs/zerowidthline.pdf b/test/pdfs/zerowidthline.pdf
new file mode 100644 (file)
index 0000000..379f180
Binary files /dev/null and b/test/pdfs/zerowidthline.pdf differ
index 6d04597d8ff457a4dc999e62cc1d13951f7b6c22..ebbcad7c538885b99e332437f7c2e2f21ebdd9b8 100644 (file)
       "rounds": 1,
       "link": true,
       "type": "eq"
+    },
+    {  "id": "zerowidthline",
+      "file": "pdfs/zerowidthline.pdf",
+      "md5": "295d26e61a85635433f8e4b768953f60",
+      "rounds": 1,
+      "link": false,
+      "type": "eq"
     }
 ]