Skip to content

Commit 4022d69

Browse files
committed
Review all form field text drawing tests
DEVSIX-7433
1 parent d1345ff commit 4022d69

File tree

57 files changed

+327
-373
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+327
-373
lines changed

commons/src/main/java/com/itextpdf/commons/utils/ExperimentalFeatures.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public final class ExperimentalFeatures {
1313
/**
1414
* Determines, whether the old or the new text form field drawing logic will be used.
1515
*/
16-
public static boolean ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING = false;
16+
public static boolean ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING = true;
1717

1818
private ExperimentalFeatures() {
1919
// utility class
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2023 Apryse Group NV
4+
Authors: Apryse Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
package com.itextpdf.commons.utils;
24+
25+
import com.itextpdf.test.ExtendedITextTest;
26+
import com.itextpdf.test.annotations.type.UnitTest;
27+
28+
import org.junit.Assert;
29+
import org.junit.Test;
30+
import org.junit.experimental.categories.Category;
31+
32+
@Category(UnitTest.class)
33+
public class ExperimentalFeaturesTest extends ExtendedITextTest {
34+
35+
@Test
36+
public void testDefaults() {
37+
Assert.assertFalse(ExperimentalFeatures.ENABLE_EXPERIMENTAL_CHECKBOX_RENDERING);
38+
Assert.assertTrue(ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING);
39+
}
40+
}

forms/src/main/java/com/itextpdf/forms/fields/PdfFormAnnotation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,10 +911,10 @@ protected void drawTextFormFieldAndSaveAppearance() {
911911

912912
IFormField textFormField;
913913
if (parent.isMultiline()) {
914-
textFormField = new TextArea(getParentField().getPartialFieldName().toUnicodeString());
914+
textFormField = new TextArea("");
915915
textFormField.setProperty(Property.FONT_SIZE, UnitValue.createPointValue(getFontSize()));
916916
} else {
917-
textFormField = new InputField(getParentField().getPartialFieldName().toUnicodeString());
917+
textFormField = new InputField("");
918918
textFormField.setProperty(Property.FONT_SIZE,
919919
UnitValue.createPointValue(getFontSize(new PdfArray(rectangle), parent.getValueAsString())));
920920
}

forms/src/test/java/com/itextpdf/forms/FlatteningRotatedTest.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.forms;
2424

25-
import com.itextpdf.commons.utils.ExperimentalFeatures;
2625
import com.itextpdf.forms.fields.PdfFormField;
2726
import com.itextpdf.kernel.colors.ColorConstants;
2827
import com.itextpdf.kernel.pdf.PdfDocument;
@@ -35,7 +34,6 @@ This file is part of the iText (R) project.
3534
import java.util.ArrayList;
3635
import java.util.Collection;
3736
import java.util.List;
38-
import org.junit.AfterClass;
3937
import org.junit.Assert;
4038
import org.junit.BeforeClass;
4139
import org.junit.Test;
@@ -51,7 +49,6 @@ public class FlatteningRotatedTest extends ExtendedITextTest {
5149
public static final String destinationFolder = "./target/test/com/itextpdf/forms/FlatteningRotatedTest/";
5250

5351
private final String inputPdfFileName;
54-
private static boolean experimentalRenderingPreviousValue;
5552

5653
@Parameterized.Parameters(name = "{0}")
5754
public static Collection<Object[]> inputFileNames() {
@@ -71,13 +68,6 @@ public FlatteningRotatedTest(Object inputPdfFileName) {
7168
@BeforeClass
7269
public static void beforeClass() {
7370
createOrClearDestinationFolder(destinationFolder);
74-
experimentalRenderingPreviousValue = ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING;
75-
ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING = true;
76-
}
77-
78-
@AfterClass
79-
public static void afterClass() {
80-
ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING = experimentalRenderingPreviousValue;
8171
}
8272

8373
@Test

forms/src/test/java/com/itextpdf/forms/FormFieldAppendTest.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.forms;
2424

25-
import com.itextpdf.commons.utils.ExperimentalFeatures;
2625
import com.itextpdf.forms.fields.PdfFormField;
2726
import com.itextpdf.kernel.pdf.PdfDocument;
2827
import com.itextpdf.kernel.pdf.PdfReader;
@@ -46,18 +45,9 @@ public class FormFieldAppendTest extends ExtendedITextTest {
4645
public static final String sourceFolder = "./src/test/resources/com/itextpdf/forms/FormFieldAppendTest/";
4746
public static final String destinationFolder = "./target/test/com/itextpdf/forms/FormFieldAppendTest/";
4847

49-
private static boolean experimentalRenderingPreviousValue;
50-
5148
@BeforeClass
5249
public static void beforeClass() {
5350
createDestinationFolder(destinationFolder);
54-
experimentalRenderingPreviousValue = ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING;
55-
ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING = true;
56-
}
57-
58-
@AfterClass
59-
public static void afterClass() {
60-
ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING = experimentalRenderingPreviousValue;
6151
}
6252

6353
@Test

forms/src/test/java/com/itextpdf/forms/FormFieldFlatteningTest.java

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.forms;
2424

25+
import com.itextpdf.commons.utils.ExperimentalFeatures;
2526
import com.itextpdf.forms.fields.PdfFormField;
2627
import com.itextpdf.forms.fields.PdfFormAnnotation;
2728
import com.itextpdf.forms.fields.PdfTextFormField;
@@ -106,18 +107,24 @@ public void formFlatteningChoiceFieldTest01() throws IOException, InterruptedExc
106107

107108
@Test
108109
public void multiLineFormFieldClippingTest() throws IOException, InterruptedException {
109-
110-
String src = sourceFolder + "multiLineFormFieldClippingTest.pdf";
111-
String dest = destinationFolder + "multiLineFormFieldClippingTest_flattened.pdf";
112-
String cmp = sourceFolder + "cmp_multiLineFormFieldClippingTest_flattened.pdf";
113-
114-
PdfDocument doc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
115-
PdfAcroForm form = PdfAcroForm.getAcroForm(doc, true);
116-
form.getField("Text1").setValue("Tall letters: T I J L R E F");
117-
form.flattenFields();
118-
doc.close();
119-
120-
Assert.assertNull(new CompareTool().compareByContent(dest, cmp, destinationFolder, "diff_"));
110+
// TODO: DEVSIX-7441 - remove flag
111+
final boolean experimentalRenderingPreviousValue = ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING;
112+
ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING = false;
113+
try {
114+
String src = sourceFolder + "multiLineFormFieldClippingTest.pdf";
115+
String dest = destinationFolder + "multiLineFormFieldClippingTest_flattened.pdf";
116+
String cmp = sourceFolder + "cmp_multiLineFormFieldClippingTest_flattened.pdf";
117+
118+
PdfDocument doc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
119+
PdfAcroForm form = PdfAcroForm.getAcroForm(doc, true);
120+
form.getField("Text1").setValue("Tall letters: T I J L R E F");
121+
form.flattenFields();
122+
doc.close();
123+
124+
Assert.assertNull(new CompareTool().compareByContent(dest, cmp, destinationFolder, "diff_"));
125+
} finally {
126+
ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING = experimentalRenderingPreviousValue;
127+
}
121128
}
122129

123130
@Test
@@ -181,15 +188,29 @@ private static void flattenFieldsAndCompare(String srcFile, String outFile)
181188

182189
@Test
183190
public void fieldsJustificationTest01() throws IOException, InterruptedException {
184-
fillTextFieldsThenFlattenThenCompare("fieldsJustificationTest01");
191+
// TODO: DEVSIX-7441 - remove flag
192+
final boolean experimentalRenderingPreviousValue = ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING;
193+
ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING = false;
194+
try {
195+
fillTextFieldsThenFlattenThenCompare("fieldsJustificationTest01");
196+
} finally {
197+
ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING = experimentalRenderingPreviousValue;
198+
}
185199
}
186200

187201
@Test
188202
@LogMessages(messages = {
189203
@LogMessage(messageTemplate = FormsLogMessageConstants.ANNOTATION_IN_ACROFORM_DICTIONARY, count = 2)
190204
})
191205
public void fieldsJustificationTest02() throws IOException, InterruptedException {
192-
fillTextFieldsThenFlattenThenCompare("fieldsJustificationTest02");
206+
// TODO: DEVSIX-7441 - remove flag
207+
final boolean experimentalRenderingPreviousValue = ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING;
208+
ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING = false;
209+
try {
210+
fillTextFieldsThenFlattenThenCompare("fieldsJustificationTest02");
211+
} finally {
212+
ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING = experimentalRenderingPreviousValue;
213+
}
193214
}
194215

195216
private static void fillTextFieldsThenFlattenThenCompare(String testName) throws IOException, InterruptedException {

forms/src/test/java/com/itextpdf/forms/PdfAcroFormInAppendModeTest.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,22 +124,16 @@ public void removeKidTest() throws IOException, InterruptedException {
124124

125125
@Test
126126
public void replaceFieldTest() throws IOException, InterruptedException {
127-
final boolean experimentalRenderingPreviousValue = ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING;
128-
ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING = true;
129-
try {
130-
String outputFile = "replaceFieldTest.pdf";
131-
PdfDocument outputDoc = new PdfDocument(new PdfReader(INPUT_FILE_WITH_TWO_FORM_FIELDS),
132-
new PdfWriter(DESTINATION_DIR + outputFile),
133-
new StampingProperties().useAppendMode());
134-
PdfFormField newField = new TextFormFieldBuilder(outputDoc, "newfield").setWidgetRectangle(
135-
new Rectangle(20, 160, 100, 20))
136-
.createText().setValue("new field");
137-
PdfAcroForm.getAcroForm(outputDoc, true).replaceField("textfield1", newField);
138-
outputDoc.close();
139-
compareWithCmp(outputFile);
140-
} finally {
141-
ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING = experimentalRenderingPreviousValue;
142-
}
127+
String outputFile = "replaceFieldTest.pdf";
128+
PdfDocument outputDoc = new PdfDocument(new PdfReader(INPUT_FILE_WITH_TWO_FORM_FIELDS),
129+
new PdfWriter(DESTINATION_DIR + outputFile),
130+
new StampingProperties().useAppendMode());
131+
PdfFormField newField = new TextFormFieldBuilder(outputDoc, "newfield").setWidgetRectangle(
132+
new Rectangle(20, 160, 100, 20))
133+
.createText().setValue("new field");
134+
PdfAcroForm.getAcroForm(outputDoc, true).replaceField("textfield1", newField);
135+
outputDoc.close();
136+
compareWithCmp(outputFile);
143137
}
144138

145139
@Test

forms/src/test/java/com/itextpdf/forms/PdfEncryptionTest.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.forms;
2424

25-
import com.itextpdf.commons.utils.ExperimentalFeatures;
2625
import com.itextpdf.forms.fields.PdfButtonFormField;
2726
import com.itextpdf.forms.fields.PdfFormAnnotation;
2827
import com.itextpdf.forms.fields.PdfTextFormField;
@@ -43,7 +42,6 @@ This file is part of the iText (R) project.
4342
import com.itextpdf.test.annotations.LogMessages;
4443
import com.itextpdf.test.annotations.type.BouncyCastleIntegrationTest;
4544

46-
import org.junit.AfterClass;
4745
import org.junit.Assert;
4846
import org.junit.BeforeClass;
4947
import org.junit.Test;
@@ -67,18 +65,9 @@ public class PdfEncryptionTest extends ExtendedITextTest {
6765
*/
6866
public static byte[] OWNER = "World".getBytes(StandardCharsets.ISO_8859_1);
6967

70-
private static boolean experimentalRenderingPreviousValue;
71-
7268
@BeforeClass
7369
public static void beforeClass() {
7470
createOrClearDestinationFolder(destinationFolder);
75-
experimentalRenderingPreviousValue = ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING;
76-
ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING = true;
77-
}
78-
79-
@AfterClass
80-
public static void afterClass() {
81-
ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING = experimentalRenderingPreviousValue;
8271
}
8372

8473
// Custom entry in Info dictionary is used because standard entried are gone into metadata in PDF 2.0

forms/src/test/java/com/itextpdf/forms/PdfFormCopyTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.forms;
2424

25-
import com.itextpdf.forms.logs.FormsLogMessageConstants;
2625
import com.itextpdf.io.logs.IoLogMessageConstant;
2726
import com.itextpdf.io.source.ByteArrayOutputStream;
2827
import com.itextpdf.kernel.pdf.PdfDocument;

forms/src/test/java/com/itextpdf/forms/PdfFormFieldMultilineTextTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.forms;
2424

25+
import com.itextpdf.commons.utils.ExperimentalFeatures;
2526
import com.itextpdf.forms.fields.PdfFormField;
2627
import com.itextpdf.forms.fields.PdfTextFormField;
2728
import com.itextpdf.forms.fields.TextFormFieldBuilder;
@@ -35,13 +36,13 @@ This file is part of the iText (R) project.
3536
import com.itextpdf.kernel.pdf.PdfReader;
3637
import com.itextpdf.kernel.pdf.PdfWriter;
3738
import com.itextpdf.kernel.utils.CompareTool;
38-
import com.itextpdf.layout.properties.HorizontalAlignment;
3939
import com.itextpdf.layout.properties.TextAlignment;
4040
import com.itextpdf.test.ExtendedITextTest;
4141
import com.itextpdf.test.annotations.type.IntegrationTest;
4242

4343
import java.io.IOException;
4444
import java.util.Map;
45+
import org.junit.AfterClass;
4546
import org.junit.Assert;
4647
import org.junit.BeforeClass;
4748
import org.junit.Test;
@@ -53,11 +54,23 @@ public class PdfFormFieldMultilineTextTest extends ExtendedITextTest {
5354
public static final String destinationFolder = "./target/test/com/itextpdf/forms/PdfFormFieldMultilineTextTest/";
5455
public static final String sourceFolder = "./src/test/resources/com/itextpdf/forms/PdfFormFieldMultilineTextTest/";
5556

57+
private static boolean experimentalRenderingPreviousValue;
58+
5659
@BeforeClass
5760
public static void beforeClass() {
61+
// TODO: DEVSIX-7441 - remove flag
62+
experimentalRenderingPreviousValue = ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING;
63+
ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING = false;
64+
5865
createDestinationFolder(destinationFolder);
5966
}
6067

68+
@AfterClass
69+
public static void afterClass() {
70+
ExperimentalFeatures.ENABLE_EXPERIMENTAL_TEXT_FORM_RENDERING = experimentalRenderingPreviousValue;
71+
}
72+
73+
6174
@Test
6275
public void multilineFormFieldTest() throws IOException, InterruptedException {
6376
String filename = destinationFolder + "multilineFormFieldTest.pdf";

0 commit comments

Comments
 (0)