From 98158b67a36f7dbe48fd507231493201b72d2100 Mon Sep 17 00:00:00 2001 From: KouWakai Date: Fri, 24 Dec 2021 22:10:19 +0900 Subject: [PATCH] Handle non-integer Annotation border widths correctly (issue 14203) The existing code appears to be wrong, since according to the PDF specification the border width of an Annotation only has to be a number and not specifically an integer. Please see: - https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf#page=392 - https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf#G11.2096210 - https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf#G6.1965562 --- src/core/annotation.js | 2 +- test/pdfs/issue14203.pdf.link | 1 + test/test_manifest.json | 9 +++++++++ test/unit/annotation_spec.js | 9 ++++++--- 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 test/pdfs/issue14203.pdf.link diff --git a/src/core/annotation.js b/src/core/annotation.js index 1e8605672..601d3cbe8 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -922,7 +922,7 @@ class AnnotationBorderStyle { this.width = 0; // This is consistent with the behaviour in Adobe Reader. return; } - if (Number.isInteger(width)) { + if (typeof width === "number") { if (width > 0) { const maxWidth = (rect[2] - rect[0]) / 2; const maxHeight = (rect[3] - rect[1]) / 2; diff --git a/test/pdfs/issue14203.pdf.link b/test/pdfs/issue14203.pdf.link new file mode 100644 index 000000000..62359d7eb --- /dev/null +++ b/test/pdfs/issue14203.pdf.link @@ -0,0 +1 @@ +https://github.com/mozilla/pdf.js/files/7428963/pdfcomment.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index a87f6ef00..884c7b666 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -4212,6 +4212,15 @@ "rounds": 1, "type": "eq" }, + { "id": "issue14203", + "file": "pdfs/issue14203.pdf", + "md5": "26c1c1e7341bc23fb28d805fa516dbbe", + "link": true, + "rounds": 1, + "firstPage": 11, + "lastPage": 11, + "type": "eq" + }, { "id": "issue11045", "file": "pdfs/issue11045.pdf", "md5": "101d4cb649cc006e0f2b14923e8d97d6", diff --git a/test/unit/annotation_spec.js b/test/unit/annotation_spec.js index ca7842863..8767e5aca 100644 --- a/test/unit/annotation_spec.js +++ b/test/unit/annotation_spec.js @@ -414,10 +414,13 @@ describe("annotation", function () { describe("AnnotationBorderStyle", function () { it("should set and get a valid width", function () { - const borderStyle = new AnnotationBorderStyle(); - borderStyle.setWidth(3); + const borderStyleInt = new AnnotationBorderStyle(); + borderStyleInt.setWidth(3); + const borderStyleNum = new AnnotationBorderStyle(); + borderStyleNum.setWidth(2.5); - expect(borderStyle.width).toEqual(3); + expect(borderStyleInt.width).toEqual(3); + expect(borderStyleNum.width).toEqual(2.5); }); it("should not set and get an invalid width", function () {