Skip to content

Commit eec31c2

Browse files
author
Kate Ivanova
committed
Add stampingFormXobjectInnerContentTaggedTest
DEVSIX-3322
1 parent 1738b5d commit eec31c2

File tree

3 files changed

+94
-74
lines changed

3 files changed

+94
-74
lines changed

kernel/src/test/java/com/itextpdf/kernel/pdf/ParentTreeTest.java

Lines changed: 94 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ This file is part of the iText (R) project.
4343
package com.itextpdf.kernel.pdf;
4444

4545
import com.itextpdf.io.font.constants.StandardFonts;
46+
import com.itextpdf.io.image.ImageDataFactory;
4647
import com.itextpdf.kernel.font.PdfFontFactory;
4748
import com.itextpdf.kernel.geom.Rectangle;
4849
import com.itextpdf.kernel.pdf.annot.PdfLinkAnnotation;
@@ -51,17 +52,23 @@ This file is part of the iText (R) project.
5152
import com.itextpdf.kernel.pdf.tagging.PdfMcrDictionary;
5253
import com.itextpdf.kernel.pdf.tagging.PdfMcrNumber;
5354
import com.itextpdf.kernel.pdf.tagging.PdfStructElem;
55+
import com.itextpdf.kernel.pdf.xobject.PdfFormXObject;
5456
import com.itextpdf.kernel.utils.CompareTool;
5557
import com.itextpdf.kernel.utils.CompareTool.CompareResult;
5658
import com.itextpdf.test.ExtendedITextTest;
5759
import com.itextpdf.test.annotations.type.IntegrationTest;
60+
import org.junit.Assert;
5861
import org.junit.BeforeClass;
62+
import org.junit.Ignore;
5963
import org.junit.Test;
6064
import org.junit.experimental.categories.Category;
65+
import org.xml.sax.SAXException;
6166

67+
import javax.xml.parsers.ParserConfigurationException;
6268
import java.io.IOException;
6369

6470
import static org.junit.Assert.assertTrue;
71+
import static org.junit.Assert.fail;
6572

6673
@Category(IntegrationTest.class)
6774
public class ParentTreeTest extends ExtendedITextTest {
@@ -104,6 +111,19 @@ public void test01() throws IOException {
104111
assertTrue(checkParentTree(outFile, cmpFile));
105112
}
106113

114+
@Ignore("works in non-deterministic way because of the bug in iText code, DEVSIX-3322")
115+
@Test
116+
//TODO update cmp-file after DEVSIX-3322 fixed
117+
public void stampingFormXobjectInnerContentTaggedTest() throws IOException, InterruptedException {
118+
String pdf = sourceFolder + "alreadyTaggedFormXObjectInnerContent.pdf";
119+
String outPdf = destinationFolder + "stampingFormXobjectInnerContentTaggedTest.pdf";
120+
String cmpPdf = sourceFolder + "cmp_stampingFormXobjectInnerContentTaggedTest.pdf";
121+
122+
PdfDocument taggedPdf = new PdfDocument(new PdfReader(pdf), new PdfWriter(outPdf));
123+
taggedPdf.setTagged();
124+
taggedPdf.close();
125+
Assert.assertNull(new CompareTool().compareByContent(outPdf, cmpPdf, destinationFolder, "diff"));
126+
}
107127

108128
@Test
109129
public void test02() throws IOException {
@@ -149,21 +169,21 @@ public void test03() throws IOException {
149169
PdfPage firstPage = document.addNewPage();
150170

151171
for (int i = 0; i < 51; i++) {
152-
PdfPage anotherPage = document.addNewPage();
153-
PdfCanvas canvas = new PdfCanvas(anotherPage);
154-
canvas.beginText();
155-
canvas.setFontAndSize(PdfFontFactory.createFont(StandardFonts.COURIER), 24);
156-
canvas.setTextMatrix(1, 0, 0, 1, 32, 512);
157-
PdfStructElem paragraph = doc.addKid(new PdfStructElem(document, PdfName.P));
158-
PdfStructElem span1 = paragraph.addKid(new PdfStructElem(document, PdfName.Span, anotherPage));
159-
canvas.openTag(new CanvasTag(span1.addKid(new PdfMcrNumber(anotherPage, span1))));
160-
canvas.showText("Hello ");
161-
canvas.closeTag();
162-
canvas.openTag(new CanvasTag(span1.addKid(new PdfMcrDictionary(anotherPage, span1))));
163-
canvas.showText("World");
164-
canvas.closeTag();
165-
canvas.endText();
166-
canvas.release();
172+
PdfPage anotherPage = document.addNewPage();
173+
PdfCanvas canvas = new PdfCanvas(anotherPage);
174+
canvas.beginText();
175+
canvas.setFontAndSize(PdfFontFactory.createFont(StandardFonts.COURIER), 24);
176+
canvas.setTextMatrix(1, 0, 0, 1, 32, 512);
177+
PdfStructElem paragraph = doc.addKid(new PdfStructElem(document, PdfName.P));
178+
PdfStructElem span1 = paragraph.addKid(new PdfStructElem(document, PdfName.Span, anotherPage));
179+
canvas.openTag(new CanvasTag(span1.addKid(new PdfMcrNumber(anotherPage, span1))));
180+
canvas.showText("Hello ");
181+
canvas.closeTag();
182+
canvas.openTag(new CanvasTag(span1.addKid(new PdfMcrDictionary(anotherPage, span1))));
183+
canvas.showText("World");
184+
canvas.closeTag();
185+
canvas.endText();
186+
canvas.release();
167187
}
168188
document.close();
169189

@@ -180,21 +200,21 @@ public void test04() throws IOException {
180200
PdfStructElem doc = document.getStructTreeRoot().addKid(new PdfStructElem(document, PdfName.Document));
181201

182202
for (int i = 0; i < 51; i++) {
183-
PdfPage anotherPage = document.addNewPage();
184-
PdfCanvas canvas = new PdfCanvas(anotherPage);
185-
canvas.beginText();
186-
canvas.setFontAndSize(PdfFontFactory.createFont(StandardFonts.COURIER), 24);
187-
canvas.setTextMatrix(1, 0, 0, 1, 32, 512);
188-
PdfStructElem paragraph = doc.addKid(new PdfStructElem(document, PdfName.P));
189-
PdfStructElem span1 = paragraph.addKid(new PdfStructElem(document, PdfName.Span, anotherPage));
190-
canvas.openTag(new CanvasTag(span1.addKid(new PdfMcrNumber(anotherPage, span1))));
191-
canvas.showText("Hello ");
192-
canvas.closeTag();
193-
canvas.openTag(new CanvasTag(span1.addKid(new PdfMcrDictionary(anotherPage, span1))));
194-
canvas.showText("World");
195-
canvas.closeTag();
196-
canvas.endText();
197-
canvas.release();
203+
PdfPage anotherPage = document.addNewPage();
204+
PdfCanvas canvas = new PdfCanvas(anotherPage);
205+
canvas.beginText();
206+
canvas.setFontAndSize(PdfFontFactory.createFont(StandardFonts.COURIER), 24);
207+
canvas.setTextMatrix(1, 0, 0, 1, 32, 512);
208+
PdfStructElem paragraph = doc.addKid(new PdfStructElem(document, PdfName.P));
209+
PdfStructElem span1 = paragraph.addKid(new PdfStructElem(document, PdfName.Span, anotherPage));
210+
canvas.openTag(new CanvasTag(span1.addKid(new PdfMcrNumber(anotherPage, span1))));
211+
canvas.showText("Hello ");
212+
canvas.closeTag();
213+
canvas.openTag(new CanvasTag(span1.addKid(new PdfMcrDictionary(anotherPage, span1))));
214+
canvas.showText("World");
215+
canvas.closeTag();
216+
canvas.endText();
217+
canvas.release();
198218
}
199219
document.close();
200220

@@ -210,43 +230,43 @@ public void test05() throws IOException {
210230

211231
PdfStructElem doc = document.getStructTreeRoot().addKid(new PdfStructElem(document, PdfName.Document));
212232

213-
PdfPage page1 = document.addNewPage();
214-
PdfCanvas canvas = new PdfCanvas(page1);
215-
canvas.beginText();
216-
canvas.setFontAndSize(PdfFontFactory.createFont(StandardFonts.COURIER), 24);
217-
canvas.setTextMatrix(1, 0, 0, 1, 32, 512);
218-
PdfStructElem paragraph = doc.addKid(new PdfStructElem(document, PdfName.P));
219-
PdfStructElem span1 = paragraph.addKid(new PdfStructElem(document, PdfName.Span, page1));
220-
221-
canvas.openTag(new CanvasTag(span1.addKid(new PdfMcrNumber(page1, span1))));
222-
canvas.showText("Hello ");
223-
canvas.closeTag();
224-
canvas.openTag(new CanvasTag(span1.addKid(new PdfMcrDictionary(page1, span1))));
225-
canvas.showText("World");
226-
canvas.closeTag();
227-
canvas.endText();
228-
canvas.release();
229-
230-
PdfPage page2 = document.addNewPage();
231-
canvas = new PdfCanvas(page2);
232-
canvas.beginText();
233-
canvas.setFontAndSize(PdfFontFactory.createFont(StandardFonts.HELVETICA), 24);
234-
canvas.setTextMatrix(1, 0, 0, 1, 32, 512);
235-
paragraph = doc.addKid(new PdfStructElem(document, PdfName.P));
236-
span1 = paragraph.addKid(new PdfStructElem(document, PdfName.Span, page2));
237-
canvas.openTag(new CanvasTag(span1.addKid(new PdfMcrNumber(page2, span1))));
238-
canvas.showText("Hello ");
239-
canvas.closeTag();
240-
PdfStructElem span2 = paragraph.addKid(new PdfStructElem(document, PdfName.Span, page2));
241-
canvas.openTag(new CanvasTag(span2.addKid(new PdfMcrNumber(page2, span2))));
242-
canvas.showText("World");
243-
canvas.closeTag();
244-
canvas.endText();
245-
canvas.release();
246-
247-
document.close();
248-
249-
assertTrue(checkParentTree(outFile, cmpFile));
233+
PdfPage page1 = document.addNewPage();
234+
PdfCanvas canvas = new PdfCanvas(page1);
235+
canvas.beginText();
236+
canvas.setFontAndSize(PdfFontFactory.createFont(StandardFonts.COURIER), 24);
237+
canvas.setTextMatrix(1, 0, 0, 1, 32, 512);
238+
PdfStructElem paragraph = doc.addKid(new PdfStructElem(document, PdfName.P));
239+
PdfStructElem span1 = paragraph.addKid(new PdfStructElem(document, PdfName.Span, page1));
240+
241+
canvas.openTag(new CanvasTag(span1.addKid(new PdfMcrNumber(page1, span1))));
242+
canvas.showText("Hello ");
243+
canvas.closeTag();
244+
canvas.openTag(new CanvasTag(span1.addKid(new PdfMcrDictionary(page1, span1))));
245+
canvas.showText("World");
246+
canvas.closeTag();
247+
canvas.endText();
248+
canvas.release();
249+
250+
PdfPage page2 = document.addNewPage();
251+
canvas = new PdfCanvas(page2);
252+
canvas.beginText();
253+
canvas.setFontAndSize(PdfFontFactory.createFont(StandardFonts.HELVETICA), 24);
254+
canvas.setTextMatrix(1, 0, 0, 1, 32, 512);
255+
paragraph = doc.addKid(new PdfStructElem(document, PdfName.P));
256+
span1 = paragraph.addKid(new PdfStructElem(document, PdfName.Span, page2));
257+
canvas.openTag(new CanvasTag(span1.addKid(new PdfMcrNumber(page2, span1))));
258+
canvas.showText("Hello ");
259+
canvas.closeTag();
260+
PdfStructElem span2 = paragraph.addKid(new PdfStructElem(document, PdfName.Span, page2));
261+
canvas.openTag(new CanvasTag(span2.addKid(new PdfMcrNumber(page2, span2))));
262+
canvas.showText("World");
263+
canvas.closeTag();
264+
canvas.endText();
265+
canvas.release();
266+
267+
document.close();
268+
269+
assertTrue(checkParentTree(outFile, cmpFile));
250270
}
251271

252272
@Test
@@ -283,14 +303,14 @@ public void test06() throws IOException {
283303
}
284304

285305
private boolean checkParentTree(String outFileName, String cmpFileName) throws IOException {
286-
PdfReader outReader = new PdfReader(outFileName);
287-
PdfDocument outDocument = new PdfDocument(outReader);
288-
PdfReader cmpReader = new PdfReader(cmpFileName);
289-
PdfDocument cmpDocument = new PdfDocument(cmpReader);
290-
CompareResult result = new CompareTool().compareByCatalog(outDocument, cmpDocument);
291-
if (!result.isOk()) {
306+
PdfReader outReader = new PdfReader(outFileName);
307+
PdfDocument outDocument = new PdfDocument(outReader);
308+
PdfReader cmpReader = new PdfReader(cmpFileName);
309+
PdfDocument cmpDocument = new PdfDocument(cmpReader);
310+
CompareResult result = new CompareTool().compareByCatalog(outDocument, cmpDocument);
311+
if (!result.isOk()) {
292312
System.out.println(result.getReport());
293313
}
294-
return result.isOk();
314+
return result.isOk();
295315
}
296316
}

0 commit comments

Comments
 (0)