Skip to content

Commit ad71ba6

Browse files
Artyom YanchevskyiText-CI
authored andcommitted
Fix null exception with SeparatedTableBorders
DEVSIX-4865 Autoported commit. Original commit hash: [a7e841cb1]
1 parent 6df3f05 commit ad71ba6

File tree

8 files changed

+22
-72
lines changed

8 files changed

+22
-72
lines changed

itext.tests/itext.layout.tests/itext/layout/TableBorderTest.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,16 @@ public static void BeforeClass() {
7474
}
7575

7676
[NUnit.Framework.Test]
77-
public virtual void CellWithBigRowspanCompletedButRowNotCompletedOnThreePagesTest() {
78-
NUnit.Framework.Assert.That(() => {
79-
fileName = "cellWithBigRowspanCompletedButRowNotCompletedOnThreePagesTest.pdf";
80-
Document doc = CreateDocument();
81-
Table table = new Table(UnitValue.CreatePercentArray(2)).UseAllAvailableWidth().SetBorderCollapse(BorderCollapsePropertyValue
82-
.SEPARATE);
83-
table.AddCell(new Cell(2, 1));
84-
table.AddCell(new Cell(1, 1).SetHeight(2000).SetBackgroundColor(ColorConstants.RED));
85-
doc.Add(table);
86-
CloseDocumentAndCompareOutputs(doc);
87-
}
88-
, NUnit.Framework.Throws.InstanceOf<NullReferenceException>())
89-
;
77+
public virtual void CellWithBigRowspanOnThreePagesTest() {
78+
fileName = "cellWithBigRowspanOnThreePagesTest.pdf";
79+
Document doc = CreateDocument();
80+
Table table = new Table(UnitValue.CreatePercentArray(2)).UseAllAvailableWidth().SetBorderCollapse(BorderCollapsePropertyValue
81+
.SEPARATE);
82+
table.AddCell(new Cell(2, 1));
83+
table.AddCell(new Cell(1, 1).SetHeight(2000).SetBackgroundColor(ColorConstants.RED));
84+
table.AddCell(new Cell(1, 1));
85+
doc.Add(table);
86+
CloseDocumentAndCompareOutputs(doc);
9087
}
9188

9289
[LogMessage(iText.IO.LogMessageConstant.LAST_ROW_IS_NOT_COMPLETE)]

itext.tests/itext.layout.tests/itext/layout/TableTest.cs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,6 @@ public class TableTest : ExtendedITextTest {
7474
private const String MIDDLE_TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.\n"
7575
+ "Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.";
7676

77-
private const String BIG_TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n"
78-
+ " Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n"
79-
+ " Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.\n"
80-
+ " Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n"
81-
+ " Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n"
82-
+ " Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n"
83-
+ " Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat\n"
84-
+ " nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n"
85-
+ " Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu\n"
86-
+ " fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n"
87-
+ " Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n"
88-
+ " Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n"
89-
+ " Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n";
90-
9177
[NUnit.Framework.OneTimeSetUp]
9278
public static void BeforeClass() {
9379
CreateDestinationFolder(destinationFolder);
@@ -2551,26 +2537,6 @@ public virtual void InheritHeaderPropsWhileMinMaxWidthCalculationsTest() {
25512537
+ "cmp_" + filename, destinationFolder, "diff"));
25522538
}
25532539

2554-
[NUnit.Framework.Test]
2555-
public virtual void TableCellWithRowspanExceedsSeveralPagesTest() {
2556-
// TODO: DEVSIX-4865 (if table cell exceeds over two pages we'll get NPE)
2557-
String outFileName = destinationFolder + "tableCellWithRowspanExceedsSeveralPages.pdf";
2558-
String cmpFileName = sourceFolder + "cmp_tableCellWithRowspanExceedsSeveralPages.pdf";
2559-
Document doc = new Document(new PdfDocument(new PdfWriter(outFileName)));
2560-
doc.GetPdfDocument().SetDefaultPageSize(PageSize.A5);
2561-
NUnit.Framework.Assert.That(() => {
2562-
Table table = new Table(2);
2563-
table.SetBorderCollapse(BorderCollapsePropertyValue.SEPARATE).AddCell(new Cell(2, 1).Add(new Paragraph("iText 1"
2564-
))).AddCell(new Cell(1, 1).Add(new Paragraph(BIG_TEXT_CONTENT)));
2565-
doc.Add(table);
2566-
doc.Close();
2567-
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
2568-
));
2569-
}
2570-
, NUnit.Framework.Throws.InstanceOf<NullReferenceException>())
2571-
;
2572-
}
2573-
25742540
private class RotatedDocumentRenderer : DocumentRenderer {
25752541
private readonly PdfDocument pdfDoc;
25762542

itext.tests/itext.layout.tests/itext/layout/renderer/TableRendererTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public virtual void CalculateColumnWidthsNotPointValue() {
7777
tableRenderer.isOriginalNonSplitRenderer = false;
7878
MinMaxWidth minMaxWidth = tableRenderer.GetMinMaxWidth();
7979
// TODO DEVSIX-3676: currently margins and paddings are still applied as if they are in points. After the mentioned ticket is fixed, the expected values should be updated.
80-
NUnit.Framework.Assert.AreEqual(minMaxWidth.GetMaxWidth(), 332.46f, 0.001);
81-
NUnit.Framework.Assert.AreEqual(minMaxWidth.GetMinWidth(), 332.46f, 0.001);
80+
NUnit.Framework.Assert.AreEqual(327.46f, minMaxWidth.GetMaxWidth(), 0.001);
81+
NUnit.Framework.Assert.AreEqual(327.46f, minMaxWidth.GetMinWidth(), 0.001);
8282
}
8383

8484
[NUnit.Framework.Test]

itext/itext.layout/itext/layout/renderer/SeparatedTableBorders.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,7 @@ protected internal override TableBorders UpdateBordersOnNewPage(bool isOriginalN
173173
}
174174

175175
public override float[] GetCellBorderIndents(int row, int col, int rowspan, int colspan) {
176-
float[] indents = new float[4];
177-
Border[] borders = rows[row + startRow - largeTableIndexOffset][col].GetBorders();
178-
for (int i = 0; i < 4; i++) {
179-
if (null != borders[i]) {
180-
indents[i] = borders[i].GetWidth();
181-
}
182-
}
183-
return indents;
176+
return new float[] { 0, 0, 0, 0 };
184177
}
185178

186179
protected internal override void BuildBordersArrays(CellRenderer cell, int row, int col, int[] rowspansToDeduct

itext/itext.layout/itext/layout/renderer/TableRenderer.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,18 +1575,14 @@ private void CorrectLayoutedCellsOccupiedAreas(LayoutResult[] splits, int row, i
15751575
float height = 0;
15761576
int rowspan = (int)cell.GetPropertyAsInteger(Property.ROWSPAN);
15771577
int colspan = (int)cell.GetPropertyAsInteger(Property.COLSPAN);
1578-
float[] indents = bordersHandler.GetCellBorderIndents(bordersHandler is SeparatedTableBorders ? row : targetOverflowRowIndex
1579-
[col], col, rowspan, colspan);
15801578
for (int l = heights.Count - 1 - 1; l > targetOverflowRowIndex[col] - rowspan && l >= 0; l--) {
15811579
height += (float)heights[l];
15821580
}
15831581
float cellHeightInLastRow;
1584-
if (bordersHandler is SeparatedTableBorders) {
1585-
cellHeightInLastRow = cell.GetOccupiedArea().GetBBox().GetHeight() - height;
1586-
}
1587-
else {
1588-
cellHeightInLastRow = cell.GetOccupiedArea().GetBBox().GetHeight() + indents[0] / 2 + indents[2] / 2 - height;
1589-
}
1582+
float[] indents = bordersHandler.GetCellBorderIndents(bordersHandler is SeparatedTableBorders ? row : targetOverflowRowIndex
1583+
[col], col, rowspan, colspan);
1584+
cellHeightInLastRow = cell.GetOccupiedArea().GetBBox().GetHeight() - height + indents[0] / 2 + indents[2]
1585+
/ 2;
15901586
if (heights[heights.Count - 1] < cellHeightInLastRow) {
15911587
if (bordersHandler is SeparatedTableBorders) {
15921588
float differenceToConsider = cellHeightInLastRow - heights[heights.Count - 1];
@@ -1649,8 +1645,6 @@ private void CorrectRowCellsOccupiedAreas(LayoutResult[] splits, int row, int[]
16491645
int colspan = (int)cell.GetPropertyAsInteger(Property.COLSPAN);
16501646
int rowspan = (int)cell.GetPropertyAsInteger(Property.ROWSPAN);
16511647
float rowspanOffset = 0;
1652-
float[] indents = bordersHandler.GetCellBorderIndents(currentRowIndex < row || bordersHandler is SeparatedTableBorders
1653-
? currentRowIndex : targetOverflowRowIndex[col], col, rowspan, colspan);
16541648
// process rowspan
16551649
for (int l = (currentRowIndex < row ? currentRowIndex : heights.Count - 1) - 1; l > (currentRowIndex < row
16561650
? currentRowIndex : targetOverflowRowIndex[col]) - rowspan && l >= 0; l--) {
@@ -1660,9 +1654,9 @@ private void CorrectRowCellsOccupiedAreas(LayoutResult[] splits, int row, int[]
16601654
}
16611655
}
16621656
height += (float)heights[currentRowIndex < row ? currentRowIndex : heights.Count - 1];
1663-
if (!(bordersHandler is SeparatedTableBorders)) {
1664-
height -= indents[0] / 2 + indents[2] / 2;
1665-
}
1657+
float[] indents = bordersHandler.GetCellBorderIndents(currentRowIndex < row || bordersHandler is SeparatedTableBorders
1658+
? currentRowIndex : targetOverflowRowIndex[col], col, rowspan, colspan);
1659+
height -= indents[0] / 2 + indents[2] / 2;
16661660
// Correcting cell bbox only. We don't need #move() here.
16671661
// This is because of BlockRenderer's specificity regarding occupied area.
16681662
float shift = height - cell.GetOccupiedArea().GetBBox().GetHeight();

itext/itext.layout/itext/layout/renderer/TableWidths.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,12 +695,12 @@ private void CalculateMinMaxWidths() {
695695
foreach (TableWidths.CellInfo cell in cells) {
696696
cell.SetParent(tableRenderer);
697697
MinMaxWidth minMax = cell.GetCell().GetMinMaxWidth();
698-
float[] indents = GetCellBorderIndents(cell);
699698
if (BorderCollapsePropertyValue.SEPARATE.Equals(tableRenderer.GetProperty<BorderCollapsePropertyValue?>(Property
700699
.BORDER_COLLAPSE))) {
701700
minMax.SetAdditionalWidth((float)(minMax.GetAdditionalWidth() - horizontalBorderSpacing));
702701
}
703702
else {
703+
float[] indents = GetCellBorderIndents(cell);
704704
minMax.SetAdditionalWidth(minMax.GetAdditionalWidth() + indents[1] / 2 + indents[3] / 2);
705705
}
706706
if (cell.GetColspan() == 1) {

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
41fc0675e3b357298ec476161faa831ea1de9111
1+
a7e841cb148776a804ab87530a76cecc1632bc5e

0 commit comments

Comments
 (0)