From d01a0bd0c83cf39efe0637c20abb64f54c95a6ab Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Mon, 8 Apr 2024 16:01:30 +0200 Subject: [PATCH] Fix annotation border style parsing by handling empty dash arrays The PDF specification states that empty dash arrays, i.e. arrays with zero elements, are in fact valid. In that case the dash array simply corresponds to a solid, unbroken line. However, this case was erroneously being flagged as invalid and therefore the annotation was not drawn because its width was set to zero. This commit fixes the issue by allowing dash arrays to have a length of zero. --- src/core/annotation.js | 8 ++++---- test/pdfs/.gitignore | 1 + test/pdfs/issue17904.pdf | Bin 0 -> 1693 bytes test/test_manifest.json | 8 ++++++++ test/unit/annotation_spec.js | 9 +++++++++ 5 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 test/pdfs/issue17904.pdf diff --git a/src/core/annotation.js b/src/core/annotation.js index 5cff3439e..b5ab35857 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -1474,9 +1474,9 @@ class AnnotationBorderStyle { // We validate the dash array, but we do not use it because CSS does not // allow us to change spacing of dashes. For more information, visit // http://www.w3.org/TR/css3-background/#the-border-style. - if (Array.isArray(dashArray) && dashArray.length > 0) { - // According to the PDF specification: the elements in `dashArray` - // shall be numbers that are nonnegative and not all equal to zero. + if (Array.isArray(dashArray)) { + // The PDF specification states that elements in the dash array, if + // present, must be non-negative numbers and must not all equal zero. let isValid = true; let allZeros = true; for (const element of dashArray) { @@ -1488,7 +1488,7 @@ class AnnotationBorderStyle { allZeros = false; } } - if (isValid && !allZeros) { + if (dashArray.length === 0 || (isValid && !allZeros)) { this.dashArray = dashArray; if (forceStyle) { diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index b3649ac87..b4de951e1 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -514,6 +514,7 @@ !issue11549_reduced.pdf !issue8097_reduced.pdf !issue15262.pdf +!issue17904.pdf !bug1743245.pdf !quadpoints.pdf !transparent.pdf diff --git a/test/pdfs/issue17904.pdf b/test/pd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;gVU1lu8_2-(b31og+VkgiOJbyzNi1@%}f$fhxVFpsQ6|TCbsMx$DiPH l;YEsaHQ70wt(YNIT#{H+Qc;we#%pM7Zo;do>gw;t1pp-Cb$S2* literal 0 HcmV?d00001 diff --git a/test/test_manifest.json b/test/test_manifest.json index e2adb07e9..ad3351073 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -3858,6 +3858,14 @@ "type": "eq", "annotations": true }, + { + "id": "issue17904", + "file": "pdfs/issue17904.pdf", + "md5": "4b8f0b565a61bf068ef72d232c997cef", + "rounds": 1, + "type": "eq", + "annotations": true + }, { "id": "issue6179_reduced", "file": "pdfs/issue6179_reduced.pdf", diff --git a/test/unit/annotation_spec.js b/test/unit/annotation_spec.js index 9cb865eb0..5432a4ab6 100644 --- a/test/unit/annotation_spec.js +++ b/test/unit/annotation_spec.js @@ -549,6 +549,15 @@ describe("annotation", function () { expect(borderStyle.dashArray).toEqual([3]); }); + it("should not set the width to zero if the dash array is empty (issue 17904)", function () { + const borderStyle = new AnnotationBorderStyle(); + borderStyle.setWidth(3); + borderStyle.setDashArray([]); + + expect(borderStyle.width).toEqual(3); + expect(borderStyle.dashArray).toEqual([]); + }); + it("should set and get a valid horizontal corner radius", function () { const borderStyle = new AnnotationBorderStyle(); borderStyle.setHorizontalCornerRadius(3);