Skip to content

Commit

Permalink
Bugfix arc closepath (#3295)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukas Holländer <lukas.hollaender@yworks.com>
  • Loading branch information
Bl4sio and HackbrettXXX committed Oct 13, 2021
1 parent babeb35 commit af2d39d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
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.
30 changes: 24 additions & 6 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,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;
Expand All @@ -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");
});

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

0 comments on commit af2d39d

Please sign in to comment.