Skip to content

Commit cbc85b4

Browse files
authored
lineWidth should be nonnegative (#3132)
1 parent e988a04 commit cbc85b4

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/modules/context2d.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ import {
17221722
var strokeStyle = this.strokeStyle;
17231723
var lineCap = this.lineCap;
17241724
var oldLineWidth = this.lineWidth;
1725-
var lineWidth = oldLineWidth * this.ctx.transform.scaleX;
1725+
var lineWidth = Math.abs(oldLineWidth * this.ctx.transform.scaleX);
17261726
var lineJoin = this.lineJoin;
17271727

17281728
var origPath = JSON.parse(JSON.stringify(this.path));

test/specs/context2d.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,4 +555,32 @@ describe("Context2D: standard tests", () => {
555555

556556
comparePdf(doc.output(), "autoPaging10Pages.pdf", "context2d");
557557
});
558+
559+
it("lineWidth should be nonnegative", ()=>{
560+
var doc = new jsPDF({
561+
orientation: "p",
562+
unit: "pt",
563+
format: "a4",
564+
floatPrecision: 3
565+
});
566+
var ctx = doc.context2d;
567+
var writeArray = [];
568+
doc.__private__.setCustomOutputDestination(writeArray);
569+
570+
ctx.beginPath();
571+
ctx.strokeStyle = "#FF0000";
572+
ctx.transform(-1, 0, 0, 1, 0, 0);
573+
ctx.moveTo(0, 0);
574+
ctx.lineTo(100, 100);
575+
ctx.stroke();
576+
577+
expect(writeArray).toEqual([
578+
"1. 0. 0. RG",
579+
"1. w", // <- should be nonnegative
580+
"0. 841.89 m",
581+
"-100. 741.89 l",
582+
"S",
583+
"1. w"
584+
]);
585+
});
558586
});

0 commit comments

Comments
 (0)