diff --git a/src/modules/context2d.js b/src/modules/context2d.js index 785dbc4ad..bb4d0e38c 100644 --- a/src/modules/context2d.js +++ b/src/modules/context2d.js @@ -995,6 +995,9 @@ import { } counterclockwise = Boolean(counterclockwise); + var x_start = x + radius * Math.cos(startAngle); + var y_start = y + radius * Math.sin(startAngle); + if (!this.ctx.transform.isIdentity) { var xpt = this.ctx.transform.applyToPoint(new Point(x, y)); x = xpt.x; @@ -1011,6 +1014,7 @@ import { startAngle = 0; endAngle = 2 * Math.PI; } + this.lineTo(x_start, y_start); this.path.push({ type: "arc", @@ -2021,7 +2025,7 @@ import { case "lt": var iii = moves.length; - if (!isNaN(xPath[i - 1].x)) { + if (xPath[i - 1] && !isNaN(xPath[i - 1].x)) { delta = [pt.x - xPath[i - 1].x, pt.y - xPath[i - 1].y]; if (iii > 0) { for (iii; iii >= 0; iii--) { diff --git a/test/reference/arc.pdf b/test/reference/arc.pdf index cb7655f14..29bca59ee 100644 Binary files a/test/reference/arc.pdf and b/test/reference/arc.pdf differ diff --git a/test/reference/bar_graph_with_text_and_lines.pdf b/test/reference/bar_graph_with_text_and_lines.pdf index e5e74c6ed..620816535 100644 Binary files a/test/reference/bar_graph_with_text_and_lines.pdf and b/test/reference/bar_graph_with_text_and_lines.pdf differ diff --git a/test/reference/piechart.pdf b/test/reference/piechart.pdf index eb495391e..1a815b3ac 100644 Binary files a/test/reference/piechart.pdf and b/test/reference/piechart.pdf differ diff --git a/test/reference/smiley.pdf b/test/reference/smiley.pdf index a0b1fcb88..8f694d4f8 100644 Binary files a/test/reference/smiley.pdf and b/test/reference/smiley.pdf differ diff --git a/test/specs/context2d.spec.js b/test/specs/context2d.spec.js index 6d6343a9b..1174a61f9 100644 --- a/test/specs/context2d.spec.js +++ b/test/specs/context2d.spec.js @@ -33,7 +33,6 @@ describe("Context2D: standard tests", () => { }; const canvg = await Canvg.fromString(ctx, svg, options); await canvg.render(options); - comparePdf( doc.output(), "bar_graph_with_text_and_lines.pdf", @@ -320,8 +319,14 @@ describe("Context2D: standard tests", () => { comparePdf(doc.output(), "fillStyle_strokeStyle.pdf", "context2d"); }); - xit("context2d: arc", () => { - var doc = new jsPDF("p", "pt", "a4"); + it("context2d: arc", () => { + var doc = new jsPDF( + { + floatPrecision: 2 + }, + "pt", + "a4" + ); var ctx = doc.context2d; var y = 0; @@ -331,32 +336,45 @@ describe("Context2D: standard tests", () => { ctx.fillStyle = "black"; y = pad + 40; - ctx.arc(50, y, 20, -10, 170, false); + ctx.beginPath(); + ctx.arc(50, y, 20, -Math.PI / 3, Math.PI, false); ctx.stroke(); y += pad + 40; - ctx.arc(50, y, 20, -10, 170, true); + ctx.beginPath(); + ctx.arc(50, y, 20, -Math.PI / 3, Math.PI, true); ctx.stroke(); y += pad + 40; + ctx.beginPath(); ctx.arc(50, y, 20, 0, Math.PI, false); ctx.stroke(); y += pad + 40; + ctx.beginPath(); ctx.arc(50, y, 20, 0, Math.PI, true); ctx.stroke(); y += pad + 40; + ctx.beginPath(); ctx.arc(50, y, 20, 0, 2 * Math.PI, false); ctx.stroke(); y += pad + 40; + ctx.beginPath(); ctx.arc(50, y, 20, 0, 2 * Math.PI, false); ctx.fill(); y += pad + 40; + ctx.beginPath(); ctx.arc(50, y, 20, 0, Math.PI, false); ctx.fill(); + y += pad + 40; + + ctx.beginPath(); + ctx.arc(50, y, 20, 0, Math.PI); + ctx.closePath(); + ctx.stroke(); comparePdf(doc.output(), "arc.pdf", "context2d"); }); @@ -649,7 +667,7 @@ describe("Context2D: standard tests", () => { comparePdf(doc.output(), "autoPaging10Pages.pdf", "context2d"); }); - it("lineWidth should be nonnegative", ()=>{ + it("lineWidth should be nonnegative", () => { var doc = new jsPDF({ orientation: "p", unit: "pt",