From af2d39d5ce51934e8048e7197f84536e03fb7998 Mon Sep 17 00:00:00 2001 From: Bl4sio <31994530+Bl4sio@users.noreply.github.com> Date: Wed, 13 Oct 2021 12:44:21 +0200 Subject: [PATCH] Bugfix arc closepath (#3295) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lukas Holländer --- src/modules/context2d.js | 6 +++- test/reference/arc.pdf | Bin 6751 -> 4154 bytes .../bar_graph_with_text_and_lines.pdf | Bin 38987 -> 39696 bytes test/reference/piechart.pdf | Bin 4128 -> 3923 bytes test/reference/smiley.pdf | Bin 3660 -> 3700 bytes test/specs/context2d.spec.js | 30 ++++++++++++++---- 6 files changed, 29 insertions(+), 7 deletions(-) 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 cb7655f14d2b9519eb6135f2b6659b5a1482e9ae..29bca59ee0c19233daa8dd1580fca5bb822e7518 100644 GIT binary patch literal 4154 zcmcInYi{F44E{f-;GbZ3QAEsL4E776SCEgI|(S(Y6IwzQSyHtCsqf?lRQ zO39g#?N|wtEn*{xNQ#e-9Evk@ay1y8a!<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g5m_C3CWZtn&MP4V<<|Q0Ardk6Vo7235!xnxMC(D!&w}Ikc=xbhQ&!E zg}FfxV=230%oJuhOR*xBPhv6&iw#sOmKrc#;`5xW@wN!>8SGz1*nnWMA}yE^WK#Hq z+ubL2Ynln+HY~75$XS0$7N_`*m856Mxj8Ve4AssUVc0^r8cKHapEClq6 zXTIneAPUGf#%2rf>q(7}0Eq~lCevgRVahT(Vi3UVK%yrj_n(vUgj?|imS2M9zu6qm-0lr;wV_6_Zht7E^T?qq$fJQTTs4al1rTy_q)g>pIYv)Y!6Z;R?~kqSyh{? zE|ERy4RcbSXkXfFvf_5@udn`|Yp=~)m+E;CeqRjdbZxKPJ!4S!J z(UmFk+0**~ErJ%op97-Ty(1)`E%8_bcIJQdLLO_wPH`aadvu=*##J%R=li{Cnw2{M z!)n{kH3>JXlGDGNqJYlSLt$|0&+2Sa40f>phYREV{&!}?!?p3}?BnPd^}nChIBPb` z;-iiL@o@3Gyqor`$v<3wHKQ(O)!;I(={iJ5n!>C67RTG!6z%7Z|LywUGn|#p>348| zfglSAbfr%v*~r)tI*)#&$Zo;TX|e^>jtn*R%noB}DvKQ^)Fikarqtw^9fDK1wl&6r z8t^sql0>Tw%%ar?=Ei9~dys}do%e6@K}|3e7gc$j)j7RB{#J642reY&JmT>;T)yJ`)ti-7(JJ4}jBbV`sK&N|KSsOW_wUa? z=H=1AuHC+U;EkYuOXXrRfp0DEyX>x7AOPoO-mNB!X}O~3c9xIOl9wWYDgGg&HCn-# zZ=NVsFvdPq`Y9c2IB9K)bL-FbDIwwRwW%mgHwBeI$A6tmNxd}{q4&JOrMCr*+Tub- ze^W3;hkJc3&DEwxE#j?h%Ps4*l3QzO4M^DM-e2elZ%i4EX7D?r0NKBBo80M X^4`K@UT3qq0f!N(4)*p=&QJdaN7We4 diff --git a/test/reference/bar_graph_with_text_and_lines.pdf b/test/reference/bar_graph_with_text_and_lines.pdf index e5e74c6ed3f04f9995c6f55ad6c80b77d5532086..620816535b68ea4fa472e241d50df162d8d4cd25 100644 GIT binary patch delta 1056 zcmaiyziU)M5XVW(SzIC6#=}Nm6A%K+?9BcIIZ1MNjYzDtl5mA$Bwp^4GbTh6qlqC# zB>Ko%*@}%|2#6q93pVzG=s#hh7S3*pgm;4PHOqYF``y{^?&r6IJMRW}o)1~;^z9>45!djSeuYv}c6^CpBq? zj=Q38qm2>1>U4x6EgeQkAWeiP=X8W&zAcnR35qh*prsBBU(c%uKXs>t@<9?rXpKb0 z5N<<+lM8Ku%1RTEZ8b?3Z9gthgx~LU1ai%LhMGtkVt8pW?b%#9l|Na!EYK+)RB=O4 z(njkaOQ~UKnbpBd&BeosyUXb~y}PYpLL(jLpdB|w;jw#Z+mV%yAVU%;#2k#|ux9pm zSCZ@dRfe1(VT6Gvj{~2*pWubHj?kQ-Ri16Vmm$IrYYBdP&=wr648RaMdx*9dAErHL z*KY~U2`W|~87(Ou_3L^H>DLA;IYI3sM3govrynKd_GU*IPS80UL$U|A_Ioq!d3uYX z))Fj35++#0fDcNZO?2s%K`zF0{$HY2%~`cv)z{!Zz+TLWv#57 z7UZpmyxt3|0innoaBziwr#SIqjX05FP5(n{Y=58Sz*xI_bSUTfa*Bq5Lo3ugg#H6z z|3N(QdoF4m$X3TEM=k11O!pd2xPf+=MWu!$iZ>Cu-x?shW3uk*I1g kHV)XRX6OFja5>p4#)}VbNL<}Xbr7evTe@&5yFKLjl z8zlG=BZEn-7K_aw5`)3)dX~l&cept@=X~e;*}rahxMB0cIHfSmmXi2bl1VKqDcoFactg}UAikF7^@`lt|FCC)x}~}dT(}IB)bwU?4|H!&()i$Z3${p z^7A?gf%xG`E9DWxXN-)Y`+x~sP|%O;vPtQ0Ey`F_;UZC$8%#2>X5SADi+eb<%= zsT+!#4M%@cyv_3%%{ge7<#`F$d0nN*qDVuXWtJdpN}_|NAU gegCMw{Qvd(} diff --git a/test/reference/piechart.pdf b/test/reference/piechart.pdf index eb495391e8a9abaf92cc91bca8ccc45794e5964d..1a815b3aceee6255b856808987bd38e4345cf1f0 100644 GIT binary patch delta 501 zcmZ3Wa9M7`L}p7vlZjIwGUiN9XM8o;kx68-67vKgZvk`ab%z*5`5XmUF5TyXo@0y7MZEDbCsOY>RQ8=6?4%NZJ(8)Jx> z7+{K-8k=FLGsB|S+!9lrrI9H}Z#{~m3{1_@4Ky;e#IV@N*a*`@CYT;EGBw9E&)m=e z$qqwsa2Qz_8X*aS#f%M2F%@me>VVt_-x_; delta 508 zcmcaCw?JXSL>5CsLyL)19!_p$ygj*qiDhy*<4GVrWwJPPFmoDL#^n1rd}fh0}ORWhQQ%j0o8i}RwaWZ@{h8gytL(9>o9w--_k)AC=fTI$m?mlhV{tNT z>Z-lDTa;B>%cF8iK#0(#MWg8$D8}8FL*pcDLoTHFX@HE2VQ;$hr28WT4GD%W#TYr^ zsXunLO?eh*ySx1D2_38Cptp%IflvRT^bum6+#}^|Ujs-x-v`Na;+g^D>;BoL2cUu! rqbhh#Ap|f57_eTKJY!F}JpG??A@W>2v{lnSHTAV%Bo?F5{5*UE#f5L2 delta 500 zcmew&b4F&u1V+<|6You~Wz3xXnQ_zRO-v6sG!68CP?JmFxhOTUBr`wHC9xz`LBqw$ z(9*)((8$mL0<;YbChz8+Cu(G&02WZlQ{aNg7@3(&&f~GFx3DlpmohXkG{6uuG{F=z zGB?IhXM#nqsWGNHGczNQ-g*NAgqsY_Eln^Cv^2)B*vP;X(?5oo9x*aD#4yju#Kauk z4g(`o6H9bKBMVCmR~uQHPrkn0Dc{7^#A|> 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",