Skip to content

Commit

Permalink
Recalculate bounding box for the signature description in case no hei…
Browse files Browse the repository at this point in the history
…ght is set

DEVSIX-7970

Autoported commit.
Original commit hash: [cd02c8ea9]
  • Loading branch information
AnhelinaM authored and iText-CI committed Dec 15, 2023
1 parent 49100dc commit cdd3448
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ public virtual void FontSizeTest() {
String cmpPdf = SOURCE_FOLDER + "cmp_fontSizeTest.pdf";
using (Document document = new Document(new PdfDocument(new PdfWriter(outPdf)))) {
SignatureFieldAppearance sigField = new SignatureFieldAppearance("SigField");
//TODO DEVSIX-7970 Fontsize doesn't get recalculate correctly in SignatureFieldAppearance making the signature look absent
sigField.SetFontSize(20);
sigField.SetContent("test");
document.Add(sigField);
Expand All @@ -342,7 +341,7 @@ public virtual void FontSizeTest() {
[NUnit.Framework.Test]
public virtual void FontNullCustomCheck() {
String outPdf = DESTINATION_FOLDER + "fontNullCustomCheck.pdf";
PdfDocument pdfDoc = new _PdfDocument_413(new PdfWriter(outPdf));
PdfDocument pdfDoc = new _PdfDocument_412(new PdfWriter(outPdf));
Document document = new Document(pdfDoc);
SignatureFieldAppearance sigField = new SignatureFieldAppearance("SigField");
sigField.SetContent("test");
Expand All @@ -355,8 +354,8 @@ public virtual void FontNullCustomCheck() {
NUnit.Framework.Assert.AreEqual(LayoutExceptionMessageConstant.INVALID_FONT_PROPERTY_VALUE, e.Message);
}

private sealed class _PdfDocument_413 : PdfDocument {
public _PdfDocument_413(PdfWriter baseArg1)
private sealed class _PdfDocument_412 : PdfDocument {
public _PdfDocument_412(PdfWriter baseArg1)
: base(baseArg1) {
}

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions itext.tests/itext.pdfa.tests/itext/pdfa/PdfAFormFieldTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,10 @@ public virtual void TestCopyPagesDoesntEmbedHelveticaFont() {
}

[NUnit.Framework.Test]
public virtual void PdfASignatureFieldTestWithAndFontText() {
public virtual void PdfASignatureFieldWithTextAndFontTest() {
String name = "pdfASignatureFieldTestWithText";
String fileName = DESTINATION_FOLDER + name + ".pdf";
String cmp = SOURCE_FOLDER + "cmp/PdfAFormFieldTest/cmp_pdfASignatureFieldTestWithText.pdf";
String cmp = SOURCE_FOLDER + "cmp/PdfAFormFieldTest/cmp_" + name + ".pdf";
PdfFont fontFreeSans = PdfFontFactory.CreateFont(SOURCE_FOLDER + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
.FORCE_EMBEDDED);
MakePdfDocument(fileName, cmp, (pdfDoc) => {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,18 @@ protected internal override void AdjustFieldLayout(LayoutContext layoutContext)

case SignatureAppearanceRenderer.RenderingMode.DESCRIPTION: {
// Default one, it just shows whatever description was defined for the signature.
float additionalHeight = CalculateAdditionalHeight();
if (RetrieveHeight() == null) {
// Adjust calculated occupied area height to keep the same font size.
float calculatedHeight = GetOccupiedArea().GetBBox().GetHeight();
GetOccupiedArea().GetBBox().MoveDown(calculatedHeight * TOP_SECTION).SetHeight(calculatedHeight * (1 + TOP_SECTION
));
bBox.MoveDown(calculatedHeight * TOP_SECTION);
// (calcHeight + addHeight + topSect) * (1 - TOP_SECTION) - addHeight = calcHeight, =>
float topSection = (calculatedHeight + additionalHeight) * TOP_SECTION / (1 - TOP_SECTION);
GetOccupiedArea().GetBBox().MoveDown(topSection + additionalHeight).SetHeight(calculatedHeight + topSection
+ additionalHeight);
bBox.MoveDown(bBox.GetBottom() - GetOccupiedArea().GetBBox().GetBottom() - additionalHeight / 2);
}
descriptionRect = bBox.SetHeight(GetOccupiedArea().GetBBox().GetHeight() * (1 - TOP_SECTION) - CalculateAdditionalHeight
());
descriptionRect = bBox.SetHeight(GetOccupiedArea().GetBBox().GetHeight() * (1 - TOP_SECTION) - additionalHeight
);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion port-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c30189650192eacab3e419069eb9287211fbf6e6
cd02c8ea9f548c039b2a0fb93872c5827912c247

0 comments on commit cdd3448

Please sign in to comment.