Skip to content

Commit 54e4218

Browse files
Make some of the layout tests tagged, update cmps
DEVSIX-1652
1 parent 74a1262 commit 54e4218

21 files changed

+25
-12
lines changed

layout/src/test/java/com/itextpdf/layout/AreaBreakTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public void pageBreakTest03() throws IOException, InterruptedException {
110110
String outFileName = destinationFolder + "pageBreak3.pdf";
111111
String cmpFileName = sourceFolder + "cmp_pageBreak3.pdf";
112112
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
113+
pdfDocument.setTagged();
113114

114115
Document document = new Document(pdfDocument);
115116
document.setRenderer(new ColumnDocumentRenderer(document, new Rectangle[] {new Rectangle(30, 30, 200, 600), new Rectangle(300, 30, 200, 600)}));
@@ -230,6 +231,8 @@ public void areaBreakInsideDiv03Test() throws IOException, InterruptedException
230231
String cmpFileName = sourceFolder + "cmp_areaBreakInsideDiv03.pdf";
231232
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
232233

234+
pdfDocument.setTagged();
235+
233236
Document document = new Document(pdfDocument);
234237
Div div = new Div().add(new Paragraph("Hello")).add(new AreaBreak()).add(new Paragraph("World"));
235238
div.setNextRenderer(new DivRendererWithAreas(div));

layout/src/test/java/com/itextpdf/layout/DefaultLayoutTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public void multipleAdditionsOfSameModelElementTest() throws IOException, Interr
7979
String outFileName = destinationFolder + "multipleAdditionsOfSameModelElementTest1.pdf";
8080
String cmpFileName = sourceFolder + "cmp_multipleAdditionsOfSameModelElementTest1.pdf";
8181
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
82+
pdfDocument.setTagged();
8283

8384
Document document = new Document(pdfDocument);
8485

@@ -172,7 +173,7 @@ public void textWithWhitespacesTest01() throws IOException, InterruptedException
172173

173174
@Test
174175
@LogMessages(messages = {
175-
@LogMessage(count = 2, messageTemplate = LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)
176+
@LogMessage(count = 1, messageTemplate = LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)
176177
})
177178
public void addParagraphOnShortPage1() throws IOException, InterruptedException {
178179
String outFileName = destinationFolder + "addParagraphOnShortPage1.pdf";

layout/src/test/java/com/itextpdf/layout/FloatTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public void inlineFloatingImageToNextPage() throws IOException, InterruptedExcep
317317
String outFile = destinationFolder + "inlineFloatingImageToNextPage.pdf";
318318
String imageSrc = sourceFolder + "itis.jpg";
319319

320-
Document document = new Document(new PdfDocument(new PdfWriter(outFile)));
320+
Document document = new Document(new PdfDocument(new PdfWriter(outFile)).setTagged());
321321

322322
Image img1 = new Image(ImageDataFactory.create(imageSrc)).scaleToFit(100, 100);
323323
Image img2 = new Image(ImageDataFactory.create(imageSrc)).scaleAbsolute(100, 500);
@@ -446,10 +446,11 @@ public void floatsOnCanvas() throws IOException, InterruptedException {
446446
String cmpFileName = sourceFolder + "cmp_floatsOnCanvas.pdf";
447447
String outFile = destinationFolder + "floatsOnCanvas.pdf";
448448

449-
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFile));
449+
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFile)).setTagged();
450450
PdfPage page = pdfDoc.addNewPage();
451451
PdfCanvas pdfCanvas = new PdfCanvas(page);
452452
Canvas canvas = new Canvas(pdfCanvas, pdfDoc, page.getPageSize().applyMargins(36, 36, 36, 36, false));
453+
canvas.enableAutoTagging(page);
453454

454455
Div div = new Div().setBackgroundColor(ColorConstants.RED);
455456
Div fDiv = new Div().setBackgroundColor(ColorConstants.BLUE).setWidth(200).setHeight(200);
@@ -485,7 +486,7 @@ public void floatFixedHeightContentNotFit() throws IOException, InterruptedExcep
485486
String cmpFileName = sourceFolder + "cmp_floatFixedHeightContentNotFit.pdf";
486487
String outFile = destinationFolder + "floatFixedHeightContentNotFit.pdf";
487488

488-
Document document = new Document(new PdfDocument(new PdfWriter(outFile)));
489+
Document document = new Document(new PdfDocument(new PdfWriter(outFile)).setTagged());
489490

490491
Div div = new Div().setBorder(new SolidBorder(ColorConstants.RED, 2));
491492
div.add(new Paragraph("Floating div.")).add(new Paragraph(text));
@@ -543,7 +544,7 @@ public void clearanceApplyingPageSplit02() throws IOException, InterruptedExcept
543544
String cmpFileName = sourceFolder + "cmp_clearanceApplyingPageSplit02.pdf";
544545
String outFile = destinationFolder + "clearanceApplyingPageSplit02.pdf";
545546

546-
Document document = new Document(new PdfDocument(new PdfWriter(outFile)));
547+
Document document = new Document(new PdfDocument(new PdfWriter(outFile)).setTagged());
547548

548549
document.add(new Paragraph(text + text));
549550

@@ -571,7 +572,7 @@ public void clearanceApplyingPageSplit03() throws IOException, InterruptedExcept
571572
String cmpFileName = sourceFolder + "cmp_clearanceApplyingPageSplit03.pdf";
572573
String outFile = destinationFolder + "clearanceApplyingPageSplit03.pdf";
573574

574-
Document document = new Document(new PdfDocument(new PdfWriter(outFile)));
575+
Document document = new Document(new PdfDocument(new PdfWriter(outFile)).setTagged());
575576

576577
document.add(new Paragraph(text + text));
577578

layout/src/test/java/com/itextpdf/layout/ListTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public void addListOnShortPage2() throws IOException, InterruptedException {
236236
String outFileName = destinationFolder + "addListOnShortPage2.pdf";
237237
String cmpFileName = sourceFolder + "cmp_addListOnShortPage2.pdf";
238238

239-
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName));
239+
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName)).setTagged();
240240
Document doc = new Document(pdfDoc, new PageSize(500, 130));
241241
List list = new List(ListNumberingType.DECIMAL);
242242

@@ -363,7 +363,7 @@ public void listOverflowTest03() throws IOException, InterruptedException {
363363
public void listEmptyItemTest01() throws IOException, InterruptedException {
364364
String outFileName = destinationFolder + "listEmptyItemTest01.pdf";
365365
String cmpFileName = sourceFolder + "cmp_listEmptyItemTest01.pdf";
366-
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
366+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName)).setTagged();
367367

368368
Document document = new Document(pdfDocument);
369369

layout/src/test/java/com/itextpdf/layout/PreLayoutTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static void beforeClass() {
8282
public void preLayoutTest01() throws IOException, InterruptedException {
8383
String outFileName = destinationFolder + "preLayoutTest01.pdf";
8484
String cmpFileName = sourceFolder + "cmp_preLayoutTest01.pdf";
85-
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
85+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName)).setTagged();
8686

8787
Document document = new Document(pdfDocument, PageSize.Default, false);
8888

@@ -162,7 +162,7 @@ public void preLayoutTest02() throws IOException, InterruptedException {
162162
public void columnDocumentRendererRelayoutTest() throws IOException, InterruptedException {
163163
String outFileName = destinationFolder + "columnDocumentRendererRelayoutTest.pdf";
164164
String cmpFileName = sourceFolder + "cmp_columnDocumentRendererRelayoutTest.pdf";
165-
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName));
165+
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName)).setTagged();
166166

167167
Document document = new Document(pdfDoc, PageSize.Default, false);
168168
Rectangle column1 = new Rectangle(40, 40, 200, 720);

layout/src/test/java/com/itextpdf/layout/TabsTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public void anchorTabStopsTest02() throws IOException, InterruptedException {
219219
String outFileName = destinationFolder + fileName;
220220
String cmpFileName = sourceFolder + "cmp_" + fileName;
221221

222-
Document doc = initDocument(outFileName);
222+
Document doc = initDocument(outFileName, true);
223223

224224
float tabInterval = doc.getPdfDocument().getDefaultPageSize().getWidth() / 2;
225225

@@ -398,7 +398,13 @@ public void tabsInParagraphTest01() throws IOException, InterruptedException {
398398
}
399399

400400
private Document initDocument(String outFileName) throws FileNotFoundException {
401+
return initDocument(outFileName, false);
402+
}
403+
private Document initDocument(String outFileName, boolean tagged) throws FileNotFoundException {
401404
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName));
405+
if (tagged) {
406+
pdfDoc.setTagged();
407+
}
402408
pdfDoc.setDefaultPageSize(PageSize.A4.rotate());
403409
return new Document(pdfDoc);
404410
}
@@ -435,7 +441,9 @@ private void addTabbedTextToParagraph(Paragraph p, String text, float[] position
435441
for (String line : text.split("\n")) {
436442
for (String chunk : line.split("\t")) {
437443
for (String piece : chunk.split("#")) {
438-
p.add(piece);
444+
if (!piece.isEmpty()) {
445+
p.add(piece);
446+
}
439447
}
440448
p.add(new Tab());
441449
}
Binary file not shown.

0 commit comments

Comments
 (0)