Skip to content

Commit

Permalink
Merge branch 'develop' into devsecops
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ivanov committed Dec 16, 2023
2 parents 1177703 + f54feea commit 79a5b72
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 18 deletions.
24 changes: 24 additions & 0 deletions itext.tests/itext.forms.tests/itext/forms/FormFieldsTaggingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,30 @@ public virtual void FormFieldTaggingTest10() {
CompareOutput(outFileName, cmpFileName);
}

[NUnit.Framework.Test]
public virtual void FormFieldTaggingTest11() {
String outFileName = destinationFolder + "taggedPdfWithForms11.pdf";
String cmpFileName = sourceFolder + "cmp_taggedPdfWithForms11.pdf";
PdfWriter writer = new PdfWriter(outFileName);
PdfReader reader = new PdfReader(sourceFolder + "taggedDocWithFields.pdf");
PdfDocument pdfDoc = new PdfDocument(reader, writer);
pdfDoc.SetTagged();
PdfAcroForm acroForm = PdfFormCreator.GetAcroForm(pdfDoc, true);
PdfButtonFormField pushButton = new PushButtonFormFieldBuilder(pdfDoc, "push").SetWidgetRectangle(new Rectangle
(36, 650, 40, 20)).SetCaption("Button 1").CreatePushButton();
pushButton.SetFontSize(12f);
PdfButtonFormField pushButton2 = new PushButtonFormFieldBuilder(pdfDoc, "push 2").SetWidgetRectangle(new Rectangle
(36, 600, 40, 20)).SetCaption("Button 2").CreatePushButton();
pushButton.SetFontSize(12f);
TagTreePointer tagPointer = pdfDoc.GetTagStructureContext().GetAutoTaggingPointer();
tagPointer.MoveToKid(StandardRoles.DIV);
acroForm.AddField(pushButton);
tagPointer.MoveToKid(StandardRoles.FORM);
acroForm.AddField(pushButton2);
pdfDoc.Close();
CompareOutput(outFileName, cmpFileName);
}

private void AddFormFieldsToDocument(PdfDocument pdfDoc, PdfAcroForm acroForm) {
Rectangle rect = new Rectangle(36, 700, 20, 20);
Rectangle rect1 = new Rectangle(36, 680, 20, 20);
Expand Down
15 changes: 10 additions & 5 deletions itext.tests/itext.forms.tests/itext/forms/PdfUA2FormTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Kernel.XMP;
using iText.Layout;
using iText.Layout.Borders;
using iText.Layout.Element;
using iText.Test;
using iText.Test.Pdfa;

Expand Down Expand Up @@ -77,7 +78,7 @@ public virtual void CheckFormFieldTest() {
}

[NUnit.Framework.Test]
public virtual void CheckTextAreaTest() {
public virtual void CheckTextAreaWithLabelTest() {
String outFile = DESTINATION_FOLDER + "textAreaTest.pdf";
String cmpFile = SOURCE_FOLDER + "cmp_textAreaTest.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFile, new WriterProperties().SetPdfVersion
Expand All @@ -87,12 +88,16 @@ public virtual void CheckTextAreaTest() {
.FORCE_EMBEDDED);
document.SetFont(font);
CreateSimplePdfUA2Document(pdfDocument);
TextArea formTextArea = new TextArea("form text area");
Paragraph paragraph = new Paragraph("Widget label").SetFont(font);
paragraph.GetAccessibilityProperties().SetRole(StandardRoles.LBL);
TextArea formTextArea = new TextArea("form text1");
formTextArea.SetProperty(FormProperty.FORM_FIELD_FLATTEN, false);
formTextArea.SetProperty(FormProperty.FORM_FIELD_VALUE, "form\ntext\narea");
document.Add(formTextArea);
PdfAcroForm form = PdfFormCreator.GetAcroForm(pdfDocument, true);
form.GetField("form text area").GetPdfObject().Put(PdfName.Contents, new PdfString("Description"));
Div div = new Div();
div.GetAccessibilityProperties().SetRole(StandardRoles.FORM);
div.Add(paragraph);
div.Add(formTextArea);
document.Add(div);
}
CompareAndValidate(outFile, cmpFile);
}
Expand Down
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.
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 @@ -82,7 +82,9 @@ public static void AddWidgetAnnotationToPage(PdfPage page, PdfAnnotation annotat
if (tagged) {
tagPointer = document.GetTagStructureContext().GetAutoTaggingPointer();
//TODO DEVSIX-4117 PrintField attributes
tagPointer.AddTag(StandardRoles.FORM);
if (!StandardRoles.FORM.Equals(tagPointer.GetRole())) {
tagPointer.AddTag(StandardRoles.FORM);
}
}
page.AddAnnotation(index, annotation, true);
if (tagged) {
Expand Down
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
77ea061eef277cb6792a11128ebf1e75cd395305

0 comments on commit 79a5b72

Please sign in to comment.