From ecc7096a805979a88d117dd139fcd69ddf07b025 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Mon, 7 Jul 2025 11:44:03 +0200 Subject: [PATCH] Fix the default appearance of a Polygon annotation when a fill color is provided It fixes #20062. --- src/core/annotation.js | 22 +++++++++++++++++++++- test/pdfs/.gitignore | 1 + test/pdfs/issue20062.pdf | Bin 0 -> 5551 bytes test/test_manifest.json | 7 +++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100755 test/pdfs/issue20062.pdf diff --git a/src/core/annotation.js b/src/core/annotation.js index 06eeff126..bc9261d25 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -4337,6 +4337,24 @@ class PolylineAnnotation extends MarkupAnnotation { const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0]; const strokeAlpha = dict.get("CA"); + let fillColor = getRgbColor(dict.getArray("IC"), null); + if (fillColor) { + fillColor = getPdfColorArray(fillColor); + } + + let operator; + if (fillColor) { + if (this.color) { + operator = fillColor.every((c, i) => c === strokeColor[i]) + ? "f" + : "B"; + } else { + operator = "f"; + } + } else { + operator = "S"; + } + const borderWidth = this.borderStyle.width || 1, borderAdjust = 2 * borderWidth; @@ -4361,13 +4379,15 @@ class PolylineAnnotation extends MarkupAnnotation { extra: `${borderWidth} w`, strokeColor, strokeAlpha, + fillColor, + fillAlpha: fillColor ? strokeAlpha : null, pointsCallback: (buffer, points) => { for (let i = 0, ii = vertices.length; i < ii; i += 2) { buffer.push( `${vertices[i]} ${vertices[i + 1]} ${i === 0 ? "m" : "l"}` ); } - buffer.push("S"); + buffer.push(operator); return [points[0], points[7], points[2], points[3]]; }, }); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 35f08e9d7..fd0a3e6bb 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -731,3 +731,4 @@ !bug1885505.pdf !bug1974436.pdf !firefox_logo.pdf +!issue20062.pdf diff --git a/test/pdfs/issue20062.pdf b/test/pdfs/issue20062.pdf new file mode 100755 index 0000000000000000000000000000000000000000..b925c251eb662569d45b106e835e8d3f88581c87 GIT binary patch literal 5551 zcmeHLZERat8BR;uXfEKWSfBbA~^xgW=lTl-$? z`nqu{A=)vCRoW^TMWUlZQw4)j5bY$yk4<7jOt7-8r0awRXdoCrm?jnRr-<+OUVq)D z?xaWz{^TmLj_-LtpZ7f{d7qJdCL5(ODLnG~KU{e|9HJBvWa~%5i3FajSWI&&$C-&J zo93HfvS`@i^}=vtqcmgD96w;%uerG6!d?n#6RGgNTX^9XjsA`H6_;gC-vxKHWFu8(fER(gCA#u@Lmuy4{ z#8<#`%qqKUh$mh!$Gk*kT(E5yBJ%ea0U1OkT->NLe7L|$cxjm;*aHX}uEVriIJEYb zuABQ;_0@u|ul`xn|9a!`Qzth+ie4D{AldzVI0Q&_L_3%@T+MM?4l9L2BpezUnO?|- zLtPvJIN9X|iteJKCa6L%gypnS3QSbpEqU2l_r zo(#RUYrMSw%;*1dW%uxbq37Nm{^NiM{p>p(l4GuBYOdyG4Tvo?-754<14;hZyjF&_ z>aTr}(jZ#3%l!_ad_SGEW7ntb)-s6!{O~JL4nAcSK38xKxD`+>WOLYuHW4 zV9-y{I0f50Y_rCK1SY|6u18OaF@uZvtEzh?NE$BxU-C7VP(y?Rr zhfm-CJ#_ZOPtF&gn&%&V_LV2j6(9fHzb|~}@{#hH`Gu>)4_&zTyVt*d?-O?Uj{U1cAAV%)YXhp}6{LHNJAF(Qf)|^*>$hueuANA?g8fty z2U~T`ILch4vvS3nj9h>2M-fypCnHN@j^yfTwpKZG++mBy=ZnViqlRim4kkm1R=icK z*PtIzt5&rd@z!KSgIj>bVeP%f5#)=wM<*jGZv!39YBfI5Hqy0|VGYBn)ZL10Ae66qa1&vz%WTD|AUYQ+2` zV}@PBEv=4ejNm~^rqR=>H=U{*e3 z8u60t)HFA#)$7%Yp?MvG0m20CZw2K2dc`xg(e&y%lSww46*Dd}k;%FtM!6F7p`bA( zs>qTWH3eA}B~~&_PVCz9{4MVky{}I{ zwfE7@j+1SHy93t_T-!omTf#ftwFB3-5ZIRRPIvv+;0pBz3z&5$BkM3W3>aJj6X9)# zvffN4sBIR)8)?R#wf#PId`{TJ>zM9%G*eg2*gTsm+-8-D#DdhusNFe(4=;k_Rl084;zp;YQ| zE>!MJ(4l3RJb~RnE55QfREPc_yai5KmhCo>A6NnPX^fB`pC1=cXdYUqEsGG&110AN z-<|y7m0jH^!ta6o& zAv~W$qc9No5y7k%?X)nJL`5J`0umsQiFaGO{eBGMnX(;|IcV8q*eKWs2i_NtbOdKb zG^#b-HQNCL=@hU)A_&X`B|gI(w*uS_T5d-u$Rx%|vJ4);#O-sT0*%Q$2N{as2(a^* zHy^SN*M=w%ZoLQjD+DAQz}MRmRH}4#EZC6{*VPe;1Q~e`f*pTBJi4_1&ULg(l{w)M el&DP{Do}wwn+SFBNJi*DKe|9uio7iMy7E8sJP!o` literal 0 HcmV?d00001 diff --git a/test/test_manifest.json b/test/test_manifest.json index 1038aca95..e3e74f753 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -12164,5 +12164,12 @@ "rounds": 1, "type": "eq", "annotations": true + }, + { + "id": "issue20062", + "file": "pdfs/issue20062.pdf", + "md5": "9fa985242476c642464d94893528e40f", + "rounds": 1, + "type": "eq" } ]