Skip to content

Commit

Permalink
Merge pull request #7 from MrRio/master
Browse files Browse the repository at this point in the history
lineWidth should be nonnegative (parallax#3132)
  • Loading branch information
sthagen authored Apr 11, 2021
2 parents b59aac9 + cbc85b4 commit 1a93365
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
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"
]);
});
});

0 comments on commit 1a93365

Please sign in to comment.