From 68e6622c57e294d25d8caa9923ec430140350223 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 19 Oct 2021 15:13:04 +0200 Subject: [PATCH] Ignore Square/Circle-annnotations with a zero borderWidth when creating a fallback appearance stream (issue 14164) Trying to render these Annotation-types, when the borderWidth is `0`, causes a "hairline" border to appear. If these Annotations included an appearance stream, as they are supposed to, this wouldn't have happened and the simplest solution here seem to be to just ignore these particular Annotations. --- src/core/annotation.js | 10 ++++++++++ test/pdfs/issue14164.pdf.link | 1 + test/test_manifest.json | 8 ++++++++ 3 files changed, 19 insertions(+) create mode 100644 test/pdfs/issue14164.pdf.link diff --git a/src/core/annotation.js b/src/core/annotation.js index 0a8c1f11b..e7e8c2939 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -2648,6 +2648,11 @@ class SquareAnnotation extends MarkupAnnotation { } const fillAlpha = fillColor ? strokeAlpha : null; + if (this.borderStyle.width === 0 && !fillColor) { + // Prevent rendering a "hairline" border (fixes issue14164.pdf). + return; + } + this._setDefaultAppearance({ xref: parameters.xref, extra: `${this.borderStyle.width} w`, @@ -2697,6 +2702,11 @@ class CircleAnnotation extends MarkupAnnotation { } const fillAlpha = fillColor ? strokeAlpha : null; + if (this.borderStyle.width === 0 && !fillColor) { + // Prevent rendering a "hairline" border (fixes issue14164.pdf). + return; + } + // Circles are approximated by Bézier curves with four segments since // there is no circle primitive in the PDF specification. For the control // points distance, see https://stackoverflow.com/a/27863181. diff --git a/test/pdfs/issue14164.pdf.link b/test/pdfs/issue14164.pdf.link new file mode 100644 index 000000000..cdd49e3b9 --- /dev/null +++ b/test/pdfs/issue14164.pdf.link @@ -0,0 +1 @@ +https://github.com/mozilla/pdf.js/files/7372181/Test.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 2c6007b6a..671327e98 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -973,6 +973,14 @@ "enableXfa": true, "type": "eq" }, + { "id": "issue14164", + "file": "pdfs/issue14164.pdf", + "md5": "feb444c716b0337efff8094b156def32", + "rounds": 1, + "link": true, + "lastPage": 1, + "type": "eq" + }, { "id": "xfa_filled_imm1344e", "file": "pdfs/xfa_filled_imm1344e.pdf", "md5": "0576d16692fcd8ef2366cb48bf296e81",