diff --git a/src/modules/context2d.js b/src/modules/context2d.js index bb4d0e38c..277b5970c 100644 --- a/src/modules/context2d.js +++ b/src/modules/context2d.js @@ -823,21 +823,10 @@ import { typeof this.path[i + 1].x === "number" ) { pathBegin = new Point(this.path[i + 1].x, this.path[i + 1].y); - this.path.push({ - type: "lt", - x: pathBegin.x, - y: pathBegin.y - }); break; } } } - if ( - typeof this.path[i + 2] === "object" && - typeof this.path[i + 2].x === "number" - ) { - this.path.push(JSON.parse(JSON.stringify(this.path[i + 2]))); - } this.path.push({ type: "close" }); @@ -995,9 +984,6 @@ 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; @@ -1014,7 +1000,6 @@ import { startAngle = 0; endAngle = 2 * Math.PI; } - this.lineTo(x_start, y_start); this.path.push({ type: "arc", @@ -2096,6 +2081,7 @@ import { style = null; } + var began = false; for (var k = 0; k < moves.length; k++) { if (moves[k].arc) { var arcs = moves[k].abs; @@ -2113,21 +2099,22 @@ import { arc.endAngle, arc.counterclockwise, undefined, - isClip + isClip, + !began ); } else { drawLine.call(this, arc.x, arc.y); } + began = true; } - putStyle.call(this, style); + } else if (moves[k].close === true) { this.pdf.internal.out("h"); - } - if (!moves[k].arc) { - if (moves[k].close !== true && moves[k].begin !== true) { - var x = moves[k].start.x; - var y = moves[k].start.y; - drawLines.call(this, moves[k].deltas, x, y); - } + began = false; + } else if (moves[k].begin !== true) { + var x = moves[k].start.x; + var y = moves[k].start.y; + drawLines.call(this, moves[k].deltas, x, y); + began = true; } } @@ -2205,15 +2192,28 @@ import { * @param style * @param isClip */ - var drawArc = function(x, y, r, a1, a2, counterclockwise, style, isClip) { + var drawArc = function( + x, + y, + r, + a1, + a2, + counterclockwise, + style, + isClip, + includeMove + ) { // http://hansmuller-flex.blogspot.com/2011/10/more-about-approximating-circular-arcs.html - var includeMove = true; var curves = createArc.call(this, r, a1, a2, counterclockwise); for (var i = 0; i < curves.length; i++) { var curve = curves[i]; - if (includeMove && i === 0) { - doMove.call(this, curve.x1 + x, curve.y1 + y); + if (i === 0) { + if (includeMove) { + doMove.call(this, curve.x1 + x, curve.y1 + y); + } else { + drawLine.call(this, curve.x1 + x, curve.y1 + y); + } } drawCurve.call( this, diff --git a/test/reference/arc.pdf b/test/reference/arc.pdf index 29bca59ee..950d79b90 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 620816535..a78007891 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/html-margin-page-break-image.pdf b/test/reference/html-margin-page-break-image.pdf index 983af6e3c..d919864c3 100644 Binary files a/test/reference/html-margin-page-break-image.pdf and b/test/reference/html-margin-page-break-image.pdf differ diff --git a/test/reference/html-margin-page-break.pdf b/test/reference/html-margin-page-break.pdf index 1aee0ae63..b33794de7 100644 Binary files a/test/reference/html-margin-page-break.pdf and b/test/reference/html-margin-page-break.pdf differ diff --git a/test/reference/html-margin-x-y.pdf b/test/reference/html-margin-x-y.pdf index 70b1e792b..c180b8685 100644 Binary files a/test/reference/html-margin-x-y.pdf and b/test/reference/html-margin-x-y.pdf differ diff --git a/test/reference/html-margin.pdf b/test/reference/html-margin.pdf index 70b1e792b..c180b8685 100644 Binary files a/test/reference/html-margin.pdf and b/test/reference/html-margin.pdf differ diff --git a/test/reference/html-multiple.pdf b/test/reference/html-multiple.pdf index 3b29149aa..b2fda5296 100644 Binary files a/test/reference/html-multiple.pdf and b/test/reference/html-multiple.pdf differ diff --git a/test/reference/html-x-y.pdf b/test/reference/html-x-y.pdf index 70b1e792b..c180b8685 100644 Binary files a/test/reference/html-x-y.pdf and b/test/reference/html-x-y.pdf differ diff --git a/test/reference/paths.pdf b/test/reference/paths.pdf index 851f43171..27661f2c6 100644 Binary files a/test/reference/paths.pdf and b/test/reference/paths.pdf differ diff --git a/test/reference/piechart.pdf b/test/reference/piechart.pdf index 1a815b3ac..c671f4f48 100644 Binary files a/test/reference/piechart.pdf and b/test/reference/piechart.pdf differ diff --git a/test/reference/sierpinski.pdf b/test/reference/sierpinski.pdf index 0dd3107e3..1b5a39f9a 100644 Binary files a/test/reference/sierpinski.pdf and b/test/reference/sierpinski.pdf differ diff --git a/test/reference/smiley.pdf b/test/reference/smiley.pdf index 8f694d4f8..d2613d721 100644 Binary files a/test/reference/smiley.pdf and b/test/reference/smiley.pdf differ diff --git a/test/reference/w3s_arc.pdf b/test/reference/w3s_arc.pdf index 5793d52df..fa93aaf78 100644 Binary files a/test/reference/w3s_arc.pdf and b/test/reference/w3s_arc.pdf differ diff --git a/test/reference/w3s_closePath_v1.pdf b/test/reference/w3s_closePath_v1.pdf index eaa277b85..2e48b503b 100644 Binary files a/test/reference/w3s_closePath_v1.pdf and b/test/reference/w3s_closePath_v1.pdf differ diff --git a/test/reference/w3s_closePath_v2.pdf b/test/reference/w3s_closePath_v2.pdf index c1de9c126..00b478cb5 100644 Binary files a/test/reference/w3s_closePath_v2.pdf and b/test/reference/w3s_closePath_v2.pdf differ diff --git a/test/reference/warnsign.pdf b/test/reference/warnsign.pdf index 3efb57d82..05c5e58e1 100644 Binary files a/test/reference/warnsign.pdf and b/test/reference/warnsign.pdf differ diff --git a/test/specs/context2d.spec.js b/test/specs/context2d.spec.js index 1174a61f9..66ae72e22 100644 --- a/test/specs/context2d.spec.js +++ b/test/specs/context2d.spec.js @@ -375,6 +375,38 @@ describe("Context2D: standard tests", () => { ctx.arc(50, y, 20, 0, Math.PI); ctx.closePath(); ctx.stroke(); + y += pad + 40; + + ctx.beginPath(); + ctx.arc(50, y, 20, -Math.PI / 3, Math.PI, true); + ctx.closePath(); + ctx.stroke(); + + ctx.lineWidth = 4; + ctx.strokeStyle = "red"; + y = 80; + ctx.beginPath(); + ctx.moveTo(150, y); + ctx.lineTo(150, y + 35); + ctx.arc(150, y, 65, 0, Math.PI * 0.8); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + + y = 160; + ctx.beginPath(); + ctx.moveTo(150, y); + ctx.arc(150, y, 65, 0, Math.PI * 0.8); + ctx.fill(); + ctx.stroke(); + + y = 280; + ctx.beginPath(); + ctx.moveTo(150, y); + ctx.arc(150, y, 30, 0, 2 * Math.PI); + ctx.fill(); + ctx.stroke(); + comparePdf(doc.output(), "arc.pdf", "context2d"); });