diff --git a/src/core/annotation.js b/src/core/annotation.js index 6e78864be..08b613250 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -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" diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index f75ed2f4d..65edc5dc8 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -898,3 +898,4 @@ !function_based_shading.pdf !issue16091.pdf !issue7821.pdf +!issue21068.pdf diff --git a/test/pdfs/issue21068.pdf b/test/pdfs/issue21068.pdf new file mode 100644 index 000000000..2495958ad Binary files /dev/null and b/test/pdfs/issue21068.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 98d7ec427..711f9ab49 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -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" + } + } } ]