Skip to content

Commit a6146b4

Browse files
joris.schellekensitext-teamcity
authored andcommitted
Change CollapsedTableBorders to handle empty nested table
Resolves: DEVSIX-1398 Autoported commit. Original commit hash: [a26b6926d]
1 parent b099987 commit a6146b4

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using iText.Kernel.Pdf;
3+
using iText.Kernel.Utils;
4+
using iText.Layout;
5+
using iText.Layout.Element;
6+
using iText.Test;
7+
8+
namespace iText.Layout.Renderer {
9+
public class EmptyNestedTableTest : ExtendedITextTest {
10+
public static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
11+
.CurrentContext.TestDirectory) + "/resources/itext/layout/EmptyNestedTableTest/";
12+
13+
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
14+
+ "/test/itext/layout/EmptyNestedTableTest/";
15+
16+
/// <exception cref="System.IO.IOException"/>
17+
/// <exception cref="System.Exception"/>
18+
[NUnit.Framework.Test]
19+
public virtual void BuildEmptyTable() {
20+
String outFileName = destinationFolder + "emptNestedTableTest.pdf";
21+
String cmpFileName = sourceFolder + "cmp_emptNestedTableTest.pdf";
22+
// setup document
23+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
24+
pdfDocument.SetTagged();
25+
Document layoutDocument = new Document(pdfDocument);
26+
// add table to document
27+
Table x = new Table(1).AddCell(new Cell().Add(new Table(1)));
28+
layoutDocument.Add(x);
29+
// close document
30+
layoutDocument.Close();
31+
// compare
32+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
33+
, "diff"));
34+
}
35+
}
36+
}

itext/itext.layout/itext/layout/renderer/CollapsedTableBorders.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ protected internal virtual iText.Layout.Renderer.CollapsedTableBorders CollapseA
7373
int[] rowspansToDeduct = new int[numberOfColumns];
7474
int numOfRowsToRemove = 0;
7575
for (int row = startRow - largeTableIndexOffset; row <= finishRow - largeTableIndexOffset; row++) {
76-
currentRow = rows[row];
76+
currentRow = rows.IsEmpty() ? null : rows[row];
7777
bool hasCells = false;
7878
for (int col = 0; col < numberOfColumns; col++) {
79-
if (null != currentRow[col]) {
79+
if (null != currentRow && null != currentRow[col]) {
8080
int colspan = (int)currentRow[col].GetPropertyAsInteger(Property.COLSPAN);
8181
if (rowspansToDeduct[col] > 0) {
8282
int rowspan = (int)currentRow[col].GetPropertyAsInteger(Property.ROWSPAN) - rowspansToDeduct[col];

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
07e073ffa9e240b2dc3aab3a5e221c71b6e3e9dd
1+
a26b6926d5a429dd4c61fb0fbdeee1855f337e94

0 commit comments

Comments
 (0)