Skip to content

Bugfix arc closepath #3295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion src/modules/context2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -1011,6 +1014,7 @@ import {
startAngle = 0;
endAngle = 2 * Math.PI;
}
this.lineTo(x_start, y_start);

this.path.push({
type: "arc",
Expand Down Expand Up @@ -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--) {
Expand Down
Binary file modified test/reference/arc.pdf
Binary file not shown.
Binary file modified test/reference/bar_graph_with_text_and_lines.pdf
Binary file not shown.
Binary file modified test/reference/piechart.pdf
Binary file not shown.
Binary file modified test/reference/smiley.pdf
Binary file not shown.
22 changes: 17 additions & 5 deletions test/specs/context2d.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -320,7 +319,7 @@ describe("Context2D: standard tests", () => {
comparePdf(doc.output(), "fillStyle_strokeStyle.pdf", "context2d");
});

xit("context2d: arc", () => {
it("context2d: arc", () => {
var doc = new jsPDF("p", "pt", "a4");
var ctx = doc.context2d;

Expand All @@ -331,32 +330,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");
});

Expand Down Expand Up @@ -649,7 +661,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",
Expand Down