Merge pull request #21478 from calixteman/comb-field-vertical-centering

Vertically center the glyphs in comb text fields
This commit is contained in:
calixteman 2026-06-22 09:57:55 +02:00 committed by GitHub
commit 1ddf6449ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 9 deletions

View File

@ -2578,9 +2578,6 @@ class WidgetAnnotation extends Annotation {
fontSize,
totalWidth,
totalHeight,
defaultVPadding,
descent,
lineHeight,
alignment,
bidi(lines[0]).dir === "rtl",
annotationStorage
@ -2942,9 +2939,6 @@ class TextWidgetAnnotation extends WidgetAnnotation {
fontSize,
width,
height,
vPadding,
descent,
lineHeight,
alignment,
isRTL,
annotationStorage
@ -2981,11 +2975,18 @@ class TextWidgetAnnotation extends WidgetAnnotation {
previousWidth = glyphWidth;
}
const renderedComb = buf.join(" ");
// Vertically center the glyphs within the field: comb fields are mostly
// filled with uppercase letters and/or digits, hence we use the cap height
// (with a fallback on the ascent or the font size) to center them.
const vShift =
(height - (font.capHeight || font.ascent || 1) * fontSize) / 2;
return (
`/Tx BMC q ${colors}BT ` +
defaultAppearance +
` 1 0 0 1 ${numberToString(hShift)} ${numberToString(
vPadding + descent
vShift
)} Tm ${renderedComb}` +
" ET Q EMC"
);

View File

@ -2103,7 +2103,7 @@ describe("annotation", function () {
annotationStorage
);
expect(appearance).toEqual(
"/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 3.07 Tm" +
"/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 3.21 Tm" +
" 2.61 0 Td (a) Tj 8 0 Td (a) Tj 8.56 0 Td (\\() Tj" +
" 7.44 0 Td (a) Tj 8 0 Td (a) Tj" +
" 8.56 0 Td (\\)) Tj 7.44 0 Td (a) Tj" +
@ -2144,7 +2144,7 @@ describe("annotation", function () {
annotationStorage
);
expect(appearance).toEqual(
"/Tx BMC q BT /Goth 5 Tf 1 0 0 1 0 3.07 Tm" +
"/Tx BMC q BT /Goth 5 Tf 1 0 0 1 0 2.5 Tm" +
" 1.5 0 Td (\x30\x53) Tj 8 0 Td (\x30\x93) Tj 8 0 Td (\x30\x6b) Tj" +
" 8 0 Td (\x30\x61) Tj 8 0 Td (\x30\x6f) Tj" +
" 8 0 Td (\x4e\x16) Tj 8 0 Td (\x75\x4c) Tj" +