Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/modules/context2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -1722,7 +1722,7 @@ import {
var strokeStyle = this.strokeStyle;
var lineCap = this.lineCap;
var oldLineWidth = this.lineWidth;
var lineWidth = oldLineWidth * this.ctx.transform.scaleX;
var lineWidth = Math.abs(oldLineWidth * this.ctx.transform.scaleX);
var lineJoin = this.lineJoin;

var origPath = JSON.parse(JSON.stringify(this.path));
Expand Down
28 changes: 28 additions & 0 deletions test/specs/context2d.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,4 +555,32 @@ describe("Context2D: standard tests", () => {

comparePdf(doc.output(), "autoPaging10Pages.pdf", "context2d");
});

it("lineWidth should be nonnegative", ()=>{
var doc = new jsPDF({
orientation: "p",
unit: "pt",
format: "a4",
floatPrecision: 3
});
var ctx = doc.context2d;
var writeArray = [];
doc.__private__.setCustomOutputDestination(writeArray);

ctx.beginPath();
ctx.strokeStyle = "#FF0000";
ctx.transform(-1, 0, 0, 1, 0, 0);
ctx.moveTo(0, 0);
ctx.lineTo(100, 100);
ctx.stroke();

expect(writeArray).toEqual([
"1. 0. 0. RG",
"1. w", // <- should be nonnegative
"0. 841.89 m",
"-100. 741.89 l",
"S",
"1. w"
]);
});
});