From 5172903e76b4af6b13835debab0c50b693733f5e Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Wed, 25 Sep 2024 09:16:22 +0200 Subject: [PATCH] Correctly compute the font size when printing a text field with an auto font size (bug 1917734) --- src/core/annotation.js | 9 +++++---- test/test_manifest.json | 13 +++++++++++++ test/unit/annotation_spec.js | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/core/annotation.js b/src/core/annotation.js index c77b2b8c96fba0..9f271949943499 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -2526,12 +2526,13 @@ class WidgetAnnotation extends Annotation { const roundWithTwoDigits = x => Math.floor(x * 100) / 100; if (lineCount === -1) { + // Get the text width for a font size of 1. const textWidth = this._getTextWidth(text, font); + + // width / textWidth is the max font size to fit the width. + // height / LINE_FACTOR is the max font size to fit the height. fontSize = roundWithTwoDigits( - Math.min( - height / LINE_FACTOR, - textWidth > width ? width / textWidth : Infinity - ) + Math.min(height / LINE_FACTOR, width / textWidth) ); numberOfLines = 1; } else { diff --git a/test/test_manifest.json b/test/test_manifest.json index 9f9b602240da87..6c33d570dfef1a 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -10500,5 +10500,18 @@ "rounds": 1, "talos": false, "type": "eq" + }, + { + "id": "bug1917734", + "file": "pdfs/bug1917734.pdf", + "md5": "1926879e5a4a87b19f740136a8f3bd8e", + "rounds": 1, + "type": "eq", + "print": true, + "annotationStorage": { + "24R": { + "value": "hello world hello world hello world hello world" + } + } } ] diff --git a/test/unit/annotation_spec.js b/test/unit/annotation_spec.js index 8f917547412700..9e5739fd73f883 100644 --- a/test/unit/annotation_spec.js +++ b/test/unit/annotation_spec.js @@ -1850,7 +1850,7 @@ describe("annotation", function () { const utf16String = "\x30\x53\x30\x93\x30\x6b\x30\x61\x30\x6f\x4e\x16\x75\x4c\x30\x6e"; expect(appearance).toEqual( - "/Tx BMC q BT /Goth 5.92 Tf 0 g 1 0 0 1 0 0 Tm" + + "/Tx BMC q BT /Goth 3.5 Tf 0 g 1 0 0 1 0 0 Tm" + ` 2 3.07 Td (${utf16String}) Tj ET Q EMC` ); });