Skip to content

Commit 8c8a996

Browse files
author
Andrei Stryhelski
committed
Add signature appearance tests which contains graphic elements, fix file naming in PdfUADestinationsTest
DEVSIX-9034
1 parent 85b1bd7 commit 8c8a996

File tree

4 files changed

+201
-12
lines changed

4 files changed

+201
-12
lines changed

pdfua/src/test/java/com/itextpdf/pdfua/checkers/PdfUADestinationsTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void pureExplicitDestinationTest(String destinationWrapType) throws IOExc
135135
@ParameterizedTest
136136
@MethodSource("destinationWrapperType")
137137
public void namedDestinationWithStructureDestinationTest(String destinationWrapType) throws IOException {
138-
String filename = "namedDestinationWithStructureDestination_" + destinationWrapType;
138+
String filename = "namedDestWithStructureDest_" + destinationWrapType;
139139
framework.addBeforeGenerationHook(document -> {
140140
document.addNewPage();
141141
addDestinationToDocument(document, destinationWrapType, createNamedDestination(document, "destination",
@@ -147,7 +147,7 @@ public void namedDestinationWithStructureDestinationTest(String destinationWrapT
147147
@ParameterizedTest
148148
@MethodSource("destinationWrapperType")
149149
public void namedDestinationWithDictionaryWithStructureDestinationTest(String destinationWrapType) throws IOException {
150-
String filename = "namedDestinationWithDictionaryWithStructureDestination_" + destinationWrapType;
150+
String filename = "namedDestWithDictWithStructDest_" + destinationWrapType;
151151
framework.addBeforeGenerationHook(document -> {
152152
document.addNewPage();
153153
addDestinationToDocument(document, destinationWrapType, createNamedDestinationWithDictionary(document, createStructureDestination(document)));
@@ -172,7 +172,7 @@ public void namedDestinationWithDictionaryWithStructureDestinationTest(String de
172172
@ParameterizedTest
173173
@MethodSource("destinationWrapperType")
174174
public void namedDestinationWithDictionaryAndSDWithStructureDestinationTest(String destinationWrapType) throws IOException {
175-
String filename = "namedDestinationWithDictionaryAndSDWithStructureDestination_" + destinationWrapType;
175+
String filename = "namedDestWithDictAndSDWithStructDest_" + destinationWrapType;
176176
framework.addBeforeGenerationHook(document -> {
177177
document.addNewPage();
178178
addDestinationToDocument(document, destinationWrapType,
@@ -184,7 +184,7 @@ public void namedDestinationWithDictionaryAndSDWithStructureDestinationTest(Stri
184184
@ParameterizedTest
185185
@MethodSource("destinationWrapperType")
186186
public void namedDestinationWithExplicitDestinationTest(String destinationWrapType) throws IOException {
187-
String filename = "namedDestinationWithExplicitDestination_" + destinationWrapType;
187+
String filename = "namedDestWithExplicitDest_" + destinationWrapType;
188188
framework.addBeforeGenerationHook(document -> {
189189
document.addNewPage();
190190
addDestinationToDocument(document, destinationWrapType, createNamedDestination(document, "destination",
@@ -214,7 +214,7 @@ public void namedDestinationWithExplicitDestinationTest(String destinationWrapTy
214214
@ParameterizedTest
215215
@MethodSource("destinationWrapperType")
216216
public void namedDestinationWithDictionaryAndSDWithExplicitDestinationTest(String destinationWrapType) throws IOException {
217-
String filename = "namedDestinationWithDictionaryAndSDWithExplicitDestination_" + destinationWrapType;
217+
String filename = "namedDestWithDictAndSDWithExplicitDest_" + destinationWrapType;
218218
framework.addBeforeGenerationHook(document -> {
219219
document.addNewPage();
220220
addDestinationToDocument(document, destinationWrapType,
@@ -244,7 +244,7 @@ public void namedDestinationWithDictionaryAndSDWithExplicitDestinationTest(Strin
244244
@ParameterizedTest
245245
@MethodSource("destinationWrapperType")
246246
public void namedDestinationWithNamedDestinationWithStructureDestinationTest(String destinationWrapType) throws IOException {
247-
String filename = "namedDestinationWithNamedDestinationWithStructureDestination_" + destinationWrapType;
247+
String filename = "namedDestWithNamedDestWithStructDest_" + destinationWrapType;
248248
framework.addBeforeGenerationHook(document -> {
249249
document.addNewPage();
250250
addDestinationToDocument(document, destinationWrapType, createNamedDestination(document, "destination1",
@@ -269,7 +269,7 @@ public void namedDestinationWithNamedDestinationWithStructureDestinationTest(Str
269269
@ParameterizedTest
270270
@MethodSource("destinationWrapperType")
271271
public void namedDestinationWithCyclicReferenceTest(String destinationWrapType) throws IOException {
272-
String filename = "namedDestinationWithCyclicReference_" + destinationWrapType;
272+
String filename = "namedDestWithCyclicReference_" + destinationWrapType;
273273
framework.addBeforeGenerationHook(document -> {
274274
document.addNewPage();
275275
addDestinationToDocument(document, destinationWrapType, createNamedDestination(document, "destination",
@@ -300,7 +300,7 @@ public void namedDestinationWithCyclicReferenceTest(String destinationWrapType)
300300
@ParameterizedTest
301301
@MethodSource("destinationWrapperType")
302302
public void stringDestinationWithStructureDestinationTest(String destinationWrapType) throws IOException {
303-
String filename = "stringDestinationWithStructureDestination_" + destinationWrapType;
303+
String filename = "stringDestWithStructureDest_" + destinationWrapType;
304304
framework.addBeforeGenerationHook(document -> {
305305
document.addNewPage();
306306
addDestinationToDocument(document, destinationWrapType, createStringDestination(document,
@@ -312,7 +312,7 @@ public void stringDestinationWithStructureDestinationTest(String destinationWrap
312312
@ParameterizedTest
313313
@MethodSource("destinationWrapperType")
314314
public void stringDestinationWithDictionaryWithStructureDestinationTest(String destinationWrapType) throws IOException {
315-
String filename = "namedDestinationWithDictionaryWithStructureDestination_" + destinationWrapType;
315+
String filename = "stringDestWithDictWithStructDest_" + destinationWrapType;
316316
framework.addBeforeGenerationHook(document -> {
317317
document.addNewPage();
318318
addDestinationToDocument(document, destinationWrapType, createStringDestinationWithDictionary(document, createStructureDestination(document)));
@@ -337,7 +337,7 @@ public void stringDestinationWithDictionaryWithStructureDestinationTest(String d
337337
@ParameterizedTest
338338
@MethodSource("destinationWrapperType")
339339
public void stringDestinationWithDictionaryAndSDWithStructureDestinationTest(String destinationWrapType) throws IOException {
340-
String filename = "namedDestinationWithDictionaryAndSDWithStructureDestination_" + destinationWrapType;
340+
String filename = "stringDestWithDictAndSDWithStructDest_" + destinationWrapType;
341341
framework.addBeforeGenerationHook(document -> {
342342
document.addNewPage();
343343
addDestinationToDocument(document, destinationWrapType,
@@ -349,7 +349,7 @@ public void stringDestinationWithDictionaryAndSDWithStructureDestinationTest(Str
349349
@ParameterizedTest
350350
@MethodSource("destinationWrapperType")
351351
public void stringDestinationWithExplicitDestinationTest(String destinationWrapType) throws IOException {
352-
String filename = "namedDestinationWithExplicitDestination_" + destinationWrapType;
352+
String filename = "stringDestWithExplicitDest_" + destinationWrapType;
353353
framework.addBeforeGenerationHook(document -> {
354354
document.addNewPage();
355355
addDestinationToDocument(document, destinationWrapType, createStringDestination(document,
@@ -379,7 +379,7 @@ public void stringDestinationWithExplicitDestinationTest(String destinationWrapT
379379
@ParameterizedTest
380380
@MethodSource("destinationWrapperType")
381381
public void stringDestinationWithDictionaryAndSDWithExplicitDestinationTest(String destinationWrapType) throws IOException {
382-
String filename = "namedDestinationWithDictionaryAndSDWithExplicitDestination_" + destinationWrapType;
382+
String filename = "stringDestWithDictAndSDWithExplicitDest_" + destinationWrapType;
383383
framework.addBeforeGenerationHook(document -> {
384384
document.addNewPage();
385385
addDestinationToDocument(document, destinationWrapType,

pdfua/src/test/java/com/itextpdf/pdfua/checkers/PdfUAFormFieldsTest.java

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ This file is part of the iText (R) project.
4747
import com.itextpdf.forms.form.element.SignatureFieldAppearance;
4848
import com.itextpdf.forms.form.element.TextArea;
4949
import com.itextpdf.io.font.PdfEncodings;
50+
import com.itextpdf.io.image.ImageDataFactory;
5051
import com.itextpdf.kernel.colors.ColorConstants;
5152
import com.itextpdf.kernel.exceptions.KernelExceptionMessageConstant;
5253
import com.itextpdf.kernel.font.PdfFont;
@@ -64,21 +65,29 @@ This file is part of the iText (R) project.
6465
import com.itextpdf.kernel.pdf.PdfString;
6566
import com.itextpdf.kernel.pdf.PdfUAConformance;
6667
import com.itextpdf.kernel.pdf.annot.PdfAnnotation;
68+
import com.itextpdf.kernel.pdf.canvas.draw.SolidLine;
6769
import com.itextpdf.kernel.pdf.tagging.PdfObjRef;
6870
import com.itextpdf.kernel.pdf.tagging.PdfStructElem;
6971
import com.itextpdf.kernel.pdf.tagging.PdfStructTreeRoot;
7072
import com.itextpdf.kernel.pdf.tagging.PdfStructureAttributes;
7173
import com.itextpdf.kernel.pdf.tagging.StandardRoles;
7274
import com.itextpdf.kernel.pdf.tagutils.DefaultAccessibilityProperties;
7375
import com.itextpdf.kernel.pdf.tagutils.TagTreePointer;
76+
import com.itextpdf.kernel.pdf.xobject.PdfImageXObject;
7477
import com.itextpdf.layout.borders.SolidBorder;
7578
import com.itextpdf.layout.element.Div;
7679
import com.itextpdf.layout.element.IBlockElement;
80+
import com.itextpdf.layout.element.Image;
81+
import com.itextpdf.layout.element.LineSeparator;
7782
import com.itextpdf.layout.element.Paragraph;
83+
import com.itextpdf.layout.properties.BackgroundImage;
84+
import com.itextpdf.layout.properties.UnitValue;
7885
import com.itextpdf.pdfua.UaValidationTestFramework;
7986
import com.itextpdf.pdfua.exceptions.PdfUAExceptionMessageConstants;
8087
import com.itextpdf.test.ExtendedITextTest;
8188
import com.itextpdf.test.TestUtil;
89+
90+
import java.net.MalformedURLException;
8291
import org.junit.jupiter.api.BeforeAll;
8392
import org.junit.jupiter.api.BeforeEach;
8493
import org.junit.jupiter.api.Tag;
@@ -96,6 +105,8 @@ public class PdfUAFormFieldsTest extends ExtendedITextTest {
96105
private static final String FONT = "./src/test/resources/com/itextpdf/pdfua/font/FreeSans.ttf";
97106
private static final String DESTINATION_FOLDER = TestUtil.getOutputPath() + "/pdfua/PdfUATest/PdfUAFormFieldTest/";
98107

108+
private static final String DOG = "./src/test/resources/com/itextpdf/pdfua/img/DOG.bmp";
109+
99110
private UaValidationTestFramework framework;
100111

101112
@BeforeAll
@@ -2735,6 +2746,83 @@ public void textFieldRVAndVNegativeTest3(PdfUAConformance pdfUAConformance) thro
27352746
}
27362747
}
27372748

2749+
@ParameterizedTest
2750+
@MethodSource("data")
2751+
// TODO DEVSIX-9023 Support "Signature fields" UA-2 rules
2752+
public void signatureAppearanceWithImage(PdfUAConformance pdfUAConformance) throws IOException {
2753+
framework.addSuppliers(new UaValidationTestFramework.Generator<IBlockElement>() {
2754+
@Override
2755+
public IBlockElement generate() {
2756+
SignatureFieldAppearance appearance = new SignatureFieldAppearance("name");
2757+
Div div = new Div();
2758+
Image img;
2759+
try {
2760+
img = new Image(ImageDataFactory.create(DOG));
2761+
} catch (MalformedURLException e) {
2762+
throw new RuntimeException(e.getMessage());
2763+
}
2764+
div.add(img);
2765+
appearance.setContent(div);
2766+
appearance.setInteractive(true);
2767+
appearance.setAlternativeDescription("Alternative Description");
2768+
return appearance;
2769+
}
2770+
});
2771+
// TODO DEVSIX-9067 PdfUA: PdfUAConformanceException when SignatureFieldAppearance contains Image
2772+
framework.assertITextFail("signatureAppearanceWithImage", PdfUAExceptionMessageConstants.IMAGE_SHALL_HAVE_ALT,
2773+
pdfUAConformance);
2774+
framework.assertVeraPdfValid("signatureAppearanceWithImage", pdfUAConformance);
2775+
}
2776+
2777+
@ParameterizedTest
2778+
@MethodSource("data")
2779+
// TODO DEVSIX-9023 Support "Signature fields" UA-2 rules
2780+
public void signatureAppearanceWithLineSeparator(PdfUAConformance pdfUAConformance) throws IOException {
2781+
framework.addSuppliers(new UaValidationTestFramework.Generator<IBlockElement>() {
2782+
@Override
2783+
public IBlockElement generate() {
2784+
SignatureFieldAppearance appearance = new SignatureFieldAppearance("name");
2785+
Div div = new Div();
2786+
LineSeparator line = new LineSeparator(new SolidLine(3));
2787+
div.add(line);
2788+
appearance.setContent(div);
2789+
appearance.setInteractive(true);
2790+
appearance.setAlternativeDescription("Alternative Description");
2791+
return appearance;
2792+
}
2793+
});
2794+
framework.assertBothValid("signatureAppearanceLineSep", pdfUAConformance);
2795+
}
2796+
2797+
@ParameterizedTest
2798+
@MethodSource("data")
2799+
// TODO DEVSIX-9023 Support "Signature fields" UA-2 rules
2800+
public void signatureAppearanceBackgroundImage(PdfUAConformance pdfUAConformance) throws IOException {
2801+
framework.addSuppliers(new UaValidationTestFramework.Generator<IBlockElement>() {
2802+
@Override
2803+
public IBlockElement generate() {
2804+
SignatureFieldAppearance appearance = new SignatureFieldAppearance("name");
2805+
try {
2806+
appearance.setFont(getFont());
2807+
PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.create(DOG));
2808+
BackgroundImage backgroundImage = new BackgroundImage.Builder().setImage(xObject).build();
2809+
backgroundImage.getBackgroundSize().setBackgroundSizeToValues(UnitValue.createPointValue(100), UnitValue.createPointValue(100));
2810+
Div div = new Div();
2811+
div.add(new Paragraph("Some text"));
2812+
appearance.setContent(div).setFontSize(50)
2813+
.setBorder(new SolidBorder(ColorConstants.YELLOW, 10)).setHeight(200).setWidth(300);
2814+
appearance.setBackgroundImage(backgroundImage);
2815+
appearance.setAlternativeDescription("Alternative Description");
2816+
appearance.setInteractive(true);
2817+
} catch (MalformedURLException e) {
2818+
throw new RuntimeException(e.getMessage());
2819+
}
2820+
return appearance;
2821+
}
2822+
});
2823+
framework.assertBothValid("signatureAppearanceBackgroundImage", pdfUAConformance);
2824+
}
2825+
27382826
private PdfFont getFont() {
27392827
try {
27402828
return PdfFontFactory.createFont(FONT);

0 commit comments

Comments
 (0)