Merge pull request #21069 from calixteman/issue21068

Take into account the alignment when printing/saving a comb field
This commit is contained in:
calixteman 2026-04-10 19:29:20 +02:00 committed by GitHub
commit 7cfcafbb4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 34 additions and 1 deletions

View File

@ -2546,6 +2546,7 @@ class WidgetAnnotation extends Annotation {
defaultVPadding,
descent,
lineHeight,
alignment,
annotationStorage
);
}
@ -2909,6 +2910,7 @@ class TextWidgetAnnotation extends WidgetAnnotation {
vPadding,
descent,
lineHeight,
alignment,
annotationStorage
) {
const combWidth = width / this.data.maxLen;
@ -2921,11 +2923,19 @@ class TextWidgetAnnotation extends WidgetAnnotation {
buf.push(`(${escapeString(text.substring(start, end))}) Tj`);
}
const textWidth = combWidth * positions.length;
let hShift = hPadding;
if (alignment === 1) {
hShift += Math.floor((width - textWidth) / (2 * combWidth)) * combWidth;
} else if (alignment === 2) {
hShift += width - textWidth;
}
const renderedComb = buf.join(` ${numberToString(combWidth)} 0 Td `);
return (
`/Tx BMC q ${colors}BT ` +
defaultAppearance +
` 1 0 0 1 ${numberToString(hPadding)} ${numberToString(
` 1 0 0 1 ${numberToString(hShift)} ${numberToString(
vPadding + descent
)} Tm ${renderedComb}` +
" ET Q EMC"

View File

@ -898,3 +898,4 @@
!function_based_shading.pdf
!issue16091.pdf
!issue7821.pdf
!issue21068.pdf

BIN
test/pdfs/issue21068.pdf Normal file

Binary file not shown.

View File

@ -14075,5 +14075,27 @@
"md5": "7f0f390a70228fffe95835518ec266c5",
"rounds": 1,
"type": "eq"
},
{
"id": "issue21068",
"file": "pdfs/issue21068.pdf",
"md5": "69558d166186923ad9d639d91884dbd6",
"rounds": 1,
"type": "eq",
"print": true,
"annotationStorage": {
"27R": {
"value": "123"
},
"28R": {
"value": "123"
},
"29R": {
"value": "1234"
},
"30R": {
"value": "123"
}
}
}
]