Skip to content

Commit 47daceb

Browse files
IdamkinIitext-teamcity
authored andcommitted
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 Autoported commit. Original commit hash: [7731715]
1 parent 80ab951 commit 47daceb

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,10 +1276,10 @@ public virtual void TableWithHeaderFooterTest16() {
12761276

12771277
/// <exception cref="System.IO.IOException"/>
12781278
/// <exception cref="System.Exception"/>
1279-
[NUnit.Framework.Ignore("DEVSIX-1320")]
12801279
[NUnit.Framework.Test]
1281-
public virtual void TableWithHeaderFooterTest17() {
1282-
String testName = "tableWithHeaderFooterTest17.pdf";
1280+
[LogMessage(iText.IO.LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)]
1281+
public virtual void SplitRowspanKeepTogetherTest() {
1282+
String testName = "splitRowspanKeepTogetherTest.pdf";
12831283
String outFileName = destinationFolder + testName;
12841284
String cmpFileName = sourceFolder + "cmp_" + testName;
12851285
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName));

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -667,19 +667,20 @@ public override 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 = ((Cell)currentRow[col].GetModelElement()).Clone(true);
670+
CellRenderer overflowCell = (CellRenderer)((Cell)currentRow[col].GetModelElement()).Clone(true).GetRenderer
671+
();
671672
// we will change properties
672-
CellRenderer originalCellRenderer = currentRow[col];
673+
overflowCell.SetParent(this);
674+
overflowCell.DeleteProperty(Property.HEIGHT);
675+
overflowCell.DeleteProperty(Property.MIN_HEIGHT);
676+
overflowCell.DeleteProperty(Property.MAX_HEIGHT);
677+
overflowRows.SetCell(0, col, null);
678+
overflowRows.SetCell(targetOverflowRowIndex[col] - row, col, overflowCell);
673679
currentRow[col].isLastRendererForModelElement = false;
674680
childRenderers.Add(currentRow[col]);
681+
CellRenderer originalCell = currentRow[col];
675682
currentRow[col] = null;
676-
rows[targetOverflowRowIndex[col]][col] = originalCellRenderer;
677-
overflowRows.SetCell(0, col, null);
678-
overflowRows.SetCell(targetOverflowRowIndex[col] - row, col, (CellRenderer)overflowCell.GetRenderer().SetParent
679-
(this));
680-
overflowRows.GetCell(targetOverflowRowIndex[col] - row, col).DeleteProperty(Property.HEIGHT);
681-
overflowRows.GetCell(targetOverflowRowIndex[col] - row, col).DeleteProperty(Property.MIN_HEIGHT);
682-
overflowRows.GetCell(targetOverflowRowIndex[col] - row, col).DeleteProperty(Property.MAX_HEIGHT);
683+
rows[targetOverflowRowIndex[col]][col] = originalCell;
683684
}
684685
else {
685686
childRenderers.Add(currentRow[col]);
@@ -688,15 +689,20 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
688689
for (; i < row + minRowspan && i + 1 < rows.Count && splitResult[1].rows[i + 1 - row][col] != null; i++) {
689690
overflowRows.SetCell(i - row, col, splitResult[1].rows[i + 1 - row][col]);
690691
overflowRows.SetCell(i + 1 - row, col, null);
692+
rows[i][col] = rows[i + 1][col];
693+
rows[i + 1][col] = null;
691694
}
692695
// the number of cells behind is less then minRowspan-1
693696
// so we should process the last cell in the column as in the case 1 == minRowspan
694697
if (i != row + minRowspan - 1 && null != rows[i][col]) {
695-
Cell overflowCell = ((Cell)rows[i][col].GetModelElement());
696-
overflowRows.GetCell(i - row, col).isLastRendererForModelElement = false;
698+
CellRenderer overflowCell = (CellRenderer)((Cell)rows[i][col].GetModelElement()).GetRenderer().SetParent(this
699+
);
700+
rows[i][col].isLastRendererForModelElement = false;
697701
overflowRows.SetCell(i - row, col, null);
698-
overflowRows.SetCell(targetOverflowRowIndex[col] - row, col, (CellRenderer)overflowCell.GetRenderer().SetParent
699-
(this));
702+
overflowRows.SetCell(targetOverflowRowIndex[col] - row, col, overflowCell);
703+
CellRenderer originalCell = rows[i][col];
704+
rows[i][col] = null;
705+
rows[targetOverflowRowIndex[col]][col] = originalCell;
700706
}
701707
}
702708
overflowRows.GetCell(targetOverflowRowIndex[col] - row, col).occupiedArea = cellOccupiedArea;

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9b2dfd99f1a709dc3b4b5df17e0dc53dd9a536e2
1+
7731715cfcd4033907185060dbc786e00064517b

0 commit comments

Comments
 (0)