Skip to content

Commit

Permalink
Fix zero width lines.
Browse files Browse the repository at this point in the history
  • Loading branch information
brendandahl committed Jan 18, 2012
1 parent 782b67b commit 8aac225
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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]);
}
};

Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
!issue918.pdf
!smaskdim.pdf
!type4psfunc.pdf
!zerowidthline.pdf
Binary file added test/pdfs/zerowidthline.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -417,5 +417,12 @@
"rounds": 1,
"link": true,
"type": "eq"
},
{ "id": "zerowidthline",
"file": "pdfs/zerowidthline.pdf",
"md5": "295d26e61a85635433f8e4b768953f60",
"rounds": 1,
"link": false,
"type": "eq"
}
]

0 comments on commit 8aac225

Please sign in to comment.