Correctly compute the font size when printing a text field with an auto font size (bug 1917734)

This commit is contained in:
Calixte Denizet 2024-09-25 09:16:22 +02:00
parent 529906c74f
commit fc1564f476
2 changed files with 6 additions and 5 deletions

View File

@ -2526,12 +2526,13 @@ class WidgetAnnotation extends Annotation {
const roundWithTwoDigits = x => Math.floor(x * 100) / 100; const roundWithTwoDigits = x => Math.floor(x * 100) / 100;
if (lineCount === -1) { if (lineCount === -1) {
// Get the text width for a font size of 1.
const textWidth = this._getTextWidth(text, font); 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( fontSize = roundWithTwoDigits(
Math.min( Math.min(height / LINE_FACTOR, width / textWidth)
height / LINE_FACTOR,
textWidth > width ? width / textWidth : Infinity
)
); );
numberOfLines = 1; numberOfLines = 1;
} else { } else {

View File

@ -1850,7 +1850,7 @@ describe("annotation", function () {
const utf16String = const utf16String =
"\x30\x53\x30\x93\x30\x6b\x30\x61\x30\x6f\x4e\x16\x75\x4c\x30\x6e"; "\x30\x53\x30\x93\x30\x6b\x30\x61\x30\x6f\x4e\x16\x75\x4c\x30\x6e";
expect(appearance).toEqual( 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` ` 2 3.07 Td (${utf16String}) Tj ET Q EMC`
); );
}); });