Skip to content

Commit cd02c8e

Browse files
committed
Recalculate bounding box for the signature description in case no height is set
DEVSIX-7970
1 parent c301896 commit cd02c8e

File tree

7 files changed

+9
-7
lines changed

7 files changed

+9
-7
lines changed

forms/src/main/java/com/itextpdf/forms/form/renderer/SignatureAppearanceRenderer.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,18 @@ protected void adjustFieldLayout(LayoutContext layoutContext) {
178178
break;
179179
case DESCRIPTION:
180180
// Default one, it just shows whatever description was defined for the signature.
181+
float additionalHeight = calculateAdditionalHeight();
181182
if (retrieveHeight() == null) {
182183
// Adjust calculated occupied area height to keep the same font size.
183184
float calculatedHeight = getOccupiedArea().getBBox().getHeight();
184-
getOccupiedArea().getBBox().moveDown(calculatedHeight * TOP_SECTION)
185-
.setHeight(calculatedHeight * (1 + TOP_SECTION));
186-
bBox.moveDown(calculatedHeight * TOP_SECTION);
185+
// (calcHeight + addHeight + topSect) * (1 - TOP_SECTION) - addHeight = calcHeight, =>
186+
float topSection = (calculatedHeight + additionalHeight) * TOP_SECTION / (1 - TOP_SECTION);
187+
getOccupiedArea().getBBox().moveDown(topSection + additionalHeight)
188+
.setHeight(calculatedHeight + topSection + additionalHeight);
189+
bBox.moveDown(bBox.getBottom() - getOccupiedArea().getBBox().getBottom() - additionalHeight / 2);
187190
}
188191
descriptionRect = bBox.setHeight(getOccupiedArea().getBBox().getHeight() * (1 - TOP_SECTION)
189-
- calculateAdditionalHeight());
192+
- additionalHeight);
190193
break;
191194
default:
192195
return;

forms/src/test/java/com/itextpdf/forms/form/element/SignatureFieldAppearanceTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ public void fontSizeTest() throws IOException, InterruptedException {
399399
String cmpPdf = SOURCE_FOLDER + "cmp_fontSizeTest.pdf";
400400
try (Document document = new Document(new PdfDocument(new PdfWriter(outPdf)))) {
401401
SignatureFieldAppearance sigField = new SignatureFieldAppearance("SigField");
402-
//TODO DEVSIX-7970 Fontsize doesn't get recalculate correctly in SignatureFieldAppearance making the signature look absent
403402
sigField.setFontSize(20);
404403
sigField.setContent("test");
405404
document.add(sigField);

pdfa/src/test/java/com/itextpdf/pdfa/PdfAFormFieldTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,10 +671,10 @@ public void testCopyPagesDoesntEmbedHelveticaFont() throws IOException, Interrup
671671
}
672672

673673
@Test
674-
public void pdfASignatureFieldTestWithAndFontText() throws IOException, InterruptedException {
674+
public void pdfASignatureFieldWithTextAndFontTest() throws IOException, InterruptedException {
675675
String name = "pdfASignatureFieldTestWithText";
676676
String fileName = DESTINATION_FOLDER + name + ".pdf";
677-
String cmp = SOURCE_FOLDER + "cmp/PdfAFormFieldTest/cmp_pdfASignatureFieldTestWithText.pdf";
677+
String cmp = SOURCE_FOLDER + "cmp/PdfAFormFieldTest/cmp_" + name + ".pdf";
678678

679679
PdfFont fontFreeSans = PdfFontFactory.createFont(SOURCE_FOLDER + "FreeSans.ttf",
680680
"WinAnsi", EmbeddingStrategy.FORCE_EMBEDDED);

0 commit comments

Comments
 (0)