Skip to content

Commit af2d39d

Browse files
Bl4sioHackbrettXXX
andauthored
Bugfix arc closepath (#3295)
Co-authored-by: Lukas Holländer <[email protected]>
1 parent babeb35 commit af2d39d

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

src/modules/context2d.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,9 @@ import {
995995
}
996996
counterclockwise = Boolean(counterclockwise);
997997

998+
var x_start = x + radius * Math.cos(startAngle);
999+
var y_start = y + radius * Math.sin(startAngle);
1000+
9981001
if (!this.ctx.transform.isIdentity) {
9991002
var xpt = this.ctx.transform.applyToPoint(new Point(x, y));
10001003
x = xpt.x;
@@ -1011,6 +1014,7 @@ import {
10111014
startAngle = 0;
10121015
endAngle = 2 * Math.PI;
10131016
}
1017+
this.lineTo(x_start, y_start);
10141018

10151019
this.path.push({
10161020
type: "arc",
@@ -2021,7 +2025,7 @@ import {
20212025

20222026
case "lt":
20232027
var iii = moves.length;
2024-
if (!isNaN(xPath[i - 1].x)) {
2028+
if (xPath[i - 1] && !isNaN(xPath[i - 1].x)) {
20252029
delta = [pt.x - xPath[i - 1].x, pt.y - xPath[i - 1].y];
20262030
if (iii > 0) {
20272031
for (iii; iii >= 0; iii--) {

test/reference/arc.pdf

-2.54 KB
Binary file not shown.
709 Bytes
Binary file not shown.

test/reference/piechart.pdf

-205 Bytes
Binary file not shown.

test/reference/smiley.pdf

40 Bytes
Binary file not shown.

test/specs/context2d.spec.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ describe("Context2D: standard tests", () => {
3333
};
3434
const canvg = await Canvg.fromString(ctx, svg, options);
3535
await canvg.render(options);
36-
3736
comparePdf(
3837
doc.output(),
3938
"bar_graph_with_text_and_lines.pdf",
@@ -320,8 +319,14 @@ describe("Context2D: standard tests", () => {
320319
comparePdf(doc.output(), "fillStyle_strokeStyle.pdf", "context2d");
321320
});
322321

323-
xit("context2d: arc", () => {
324-
var doc = new jsPDF("p", "pt", "a4");
322+
it("context2d: arc", () => {
323+
var doc = new jsPDF(
324+
{
325+
floatPrecision: 2
326+
},
327+
"pt",
328+
"a4"
329+
);
325330
var ctx = doc.context2d;
326331

327332
var y = 0;
@@ -331,32 +336,45 @@ describe("Context2D: standard tests", () => {
331336
ctx.fillStyle = "black";
332337

333338
y = pad + 40;
334-
ctx.arc(50, y, 20, -10, 170, false);
339+
ctx.beginPath();
340+
ctx.arc(50, y, 20, -Math.PI / 3, Math.PI, false);
335341
ctx.stroke();
336342
y += pad + 40;
337343

338-
ctx.arc(50, y, 20, -10, 170, true);
344+
ctx.beginPath();
345+
ctx.arc(50, y, 20, -Math.PI / 3, Math.PI, true);
339346
ctx.stroke();
340347
y += pad + 40;
341348

349+
ctx.beginPath();
342350
ctx.arc(50, y, 20, 0, Math.PI, false);
343351
ctx.stroke();
344352
y += pad + 40;
345353

354+
ctx.beginPath();
346355
ctx.arc(50, y, 20, 0, Math.PI, true);
347356
ctx.stroke();
348357
y += pad + 40;
349358

359+
ctx.beginPath();
350360
ctx.arc(50, y, 20, 0, 2 * Math.PI, false);
351361
ctx.stroke();
352362
y += pad + 40;
353363

364+
ctx.beginPath();
354365
ctx.arc(50, y, 20, 0, 2 * Math.PI, false);
355366
ctx.fill();
356367
y += pad + 40;
357368

369+
ctx.beginPath();
358370
ctx.arc(50, y, 20, 0, Math.PI, false);
359371
ctx.fill();
372+
y += pad + 40;
373+
374+
ctx.beginPath();
375+
ctx.arc(50, y, 20, 0, Math.PI);
376+
ctx.closePath();
377+
ctx.stroke();
360378
comparePdf(doc.output(), "arc.pdf", "context2d");
361379
});
362380

@@ -649,7 +667,7 @@ describe("Context2D: standard tests", () => {
649667
comparePdf(doc.output(), "autoPaging10Pages.pdf", "context2d");
650668
});
651669

652-
it("lineWidth should be nonnegative", ()=>{
670+
it("lineWidth should be nonnegative", () => {
653671
var doc = new jsPDF({
654672
orientation: "p",
655673
unit: "pt",

0 commit comments

Comments
 (0)