Skip to content

Commit

Permalink
Correctly compute the font size when printing a text field with an au…
Browse files Browse the repository at this point in the history
…to font size (bug 1917734)
  • Loading branch information
calixteman committed Sep 25, 2024
1 parent 529906c commit a8998fc
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -669,3 +669,4 @@
!issue18693.pdf
!bug1918115.pdf
!bug1919513.pdf
!bug1917734.pdf
Binary file added test/pdfs/bug1917734.pdf
Binary file not shown.
13 changes: 13 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
]
2 changes: 1 addition & 1 deletion test/unit/annotation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
);
});
Expand Down

0 comments on commit a8998fc

Please sign in to comment.