Skip to content

Commit 7731715

Browse files
committed
Fix splitting cell with rowspan bug
The cells in column weren't shifted for original renderer as they should after creating different rows array for overflow renderer. DEVSIX-1320
1 parent 9b2dfd9 commit 7731715

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

layout/src/main/java/com/itextpdf/layout/renderer/TableRenderer.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -667,32 +667,38 @@ public LayoutResult layout(LayoutContext layoutContext) {
667667
if (1 == minRowspan) {
668668
// Here we use the same cell, but create a new renderer which doesn't have any children,
669669
// therefore it won't have any content.
670-
Cell overflowCell = currentRow[col].getModelElement().clone(true); // we will change properties
671-
CellRenderer originalCellRenderer = currentRow[col];
670+
CellRenderer overflowCell = (CellRenderer) currentRow[col].getModelElement().clone(true).getRenderer(); // we will change properties
671+
overflowCell.setParent(this);
672+
overflowCell.deleteProperty(Property.HEIGHT);
673+
overflowCell.deleteProperty(Property.MIN_HEIGHT);
674+
overflowCell.deleteProperty(Property.MAX_HEIGHT);
675+
overflowRows.setCell(0, col, null);
676+
overflowRows.setCell(targetOverflowRowIndex[col] - row, col, overflowCell);
672677
currentRow[col].isLastRendererForModelElement = false;
673678
childRenderers.add(currentRow[col]);
679+
CellRenderer originalCell = currentRow[col];
674680
currentRow[col] = null;
675-
rows.get(targetOverflowRowIndex[col])[col] = originalCellRenderer;
676-
overflowRows.setCell(0, col, null);
677-
overflowRows.setCell(targetOverflowRowIndex[col] - row, col, (CellRenderer) overflowCell.getRenderer().setParent(this));
678-
overflowRows.getCell(targetOverflowRowIndex[col] - row, col).deleteProperty(Property.HEIGHT);
679-
overflowRows.getCell(targetOverflowRowIndex[col] - row, col).deleteProperty(Property.MIN_HEIGHT);
680-
overflowRows.getCell(targetOverflowRowIndex[col] - row, col).deleteProperty(Property.MAX_HEIGHT);
681+
rows.get(targetOverflowRowIndex[col])[col] = originalCell;
681682
} else {
682683
childRenderers.add(currentRow[col]);
683684
// shift all cells in the column up
684685
int i = row;
685686
for (; i < row + minRowspan && i + 1 < rows.size() && splitResult[1].rows.get(i + 1 - row)[col] != null; i++) {
686687
overflowRows.setCell(i - row, col, splitResult[1].rows.get(i + 1 - row)[col]);
687688
overflowRows.setCell(i + 1 - row, col, null);
689+
rows.get(i)[col] = rows.get(i + 1)[col];
690+
rows.get(i + 1)[col] = null;
688691
}
689692
// the number of cells behind is less then minRowspan-1
690693
// so we should process the last cell in the column as in the case 1 == minRowspan
691694
if (i != row + minRowspan - 1 && null != rows.get(i)[col]) {
692-
Cell overflowCell = rows.get(i)[col].getModelElement();
693-
overflowRows.getCell(i - row, col).isLastRendererForModelElement = false;
695+
CellRenderer overflowCell = (CellRenderer) rows.get(i)[col].getModelElement().getRenderer().setParent(this);
696+
rows.get(i)[col].isLastRendererForModelElement = false;
694697
overflowRows.setCell(i - row, col, null);
695-
overflowRows.setCell(targetOverflowRowIndex[col] - row, col, (CellRenderer) overflowCell.getRenderer().setParent(this));
698+
overflowRows.setCell(targetOverflowRowIndex[col] - row, col, overflowCell);
699+
CellRenderer originalCell = rows.get(i)[col];
700+
rows.get(i)[col] = null;
701+
rows.get(targetOverflowRowIndex[col])[col] = originalCell;
696702
}
697703
}
698704
overflowRows.getCell(targetOverflowRowIndex[col] - row, col).occupiedArea = cellOccupiedArea;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,10 +1446,10 @@ public void tableWithHeaderFooterTest16() throws IOException, InterruptedExcepti
14461446
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, testName + "_diff"));
14471447
}
14481448

1449-
@Ignore("DEVSIX-1320")
14501449
@Test
1451-
public void tableWithHeaderFooterTest17() throws IOException, InterruptedException {
1452-
String testName = "tableWithHeaderFooterTest17.pdf";
1450+
@LogMessages(messages = {@LogMessage(messageTemplate = LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)})
1451+
public void splitRowspanKeepTogetherTest() throws IOException, InterruptedException {
1452+
String testName = "splitRowspanKeepTogetherTest.pdf";
14531453
String outFileName = destinationFolder + testName;
14541454
String cmpFileName = sourceFolder + "cmp_" + testName;
14551455

0 commit comments

Comments
 (0)