Skip to content

Commit cf2ff95

Browse files
committed
Refactor TableRenderer. Distinguish between current, split and overflow renderer's rows.
1 parent f1b9e19 commit cf2ff95

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
611611
if (marginsCollapsingEnabled) {
612612
marginsCollapseHandler.endMarginsCollapse(layoutBox);
613613
}
614-
TableRenderer[] splitResult = !split ? split(row + 1, false, cellWithBigRowspanAdded) : split(row, hasContent, cellWithBigRowspanAdded);
614+
TableRenderer[] splitResult = split(row, hasContent, cellWithBigRowspanAdded);
615615
// delete #layout() related properties
616616
if (null != headerRenderer || null != footerRenderer) {
617617
if (null != headerRenderer || tableModel.isEmpty()) {
@@ -633,20 +633,20 @@ public LayoutResult layout(LayoutContext layoutContext) {
633633
if (splits[col].getStatus() != LayoutResult.NOTHING && (hasContent || cellWithBigRowspanAdded)) {
634634
childRenderers.add(cellSplit);
635635
}
636-
LayoutArea cellOccupiedArea = currentRow[col].getOccupiedArea();
636+
LayoutArea cellOccupiedArea = splitResult[1].rows.get(0)[col].getOccupiedArea();
637637
if (hasContent || cellWithBigRowspanAdded || splits[col].getStatus() == LayoutResult.NOTHING) {
638638
CellRenderer cellOverflow = (CellRenderer) splits[col].getOverflowRenderer();
639-
currentRow[col] = null;
640-
rows.get(targetOverflowRowIndex[col])[col] = (CellRenderer) cellOverflow.setParent(splitResult[1]);
639+
splitResult[1].rows.get(0)[col] = null;
640+
splitResult[1].rows.get(targetOverflowRowIndex[col] - row)[col] = (CellRenderer) cellOverflow.setParent(splitResult[1]);
641641
} else {
642-
rows.get(targetOverflowRowIndex[col])[col] = (CellRenderer) currentRow[col].setParent(splitResult[1]);
642+
splitResult[1].rows.get(targetOverflowRowIndex[col] - row)[col] = (CellRenderer) splitResult[1].rows.get(0)[col].setParent(splitResult[1]);
643643
}
644-
rows.get(targetOverflowRowIndex[col])[col].occupiedArea = cellOccupiedArea;
645-
} else if (currentRow[col] != null) {
644+
splitResult[1].rows.get(targetOverflowRowIndex[col] - row)[col].occupiedArea = cellOccupiedArea;
645+
} else if (splitResult[1].rows.get(0)[col] != null) {
646646
if (hasContent) {
647-
rowspans[col] = currentRow[col].getModelElement().getRowspan();
647+
rowspans[col] = splitResult[1].rows.get(0)[col].getModelElement().getRowspan();
648648
}
649-
boolean isBigRowspannedCell = 1 != currentRow[col].getModelElement().getRowspan();
649+
boolean isBigRowspannedCell = 1 != splitResult[1].rows.get(0)[col].getModelElement().getRowspan();
650650
if (hasContent || isBigRowspannedCell) {
651651
columnsWithCellToBeEnlarged[col] = true;
652652
}
@@ -662,36 +662,36 @@ public LayoutResult layout(LayoutContext layoutContext) {
662662

663663
for (col = 0; col < numberOfColumns; col++) {
664664
if (columnsWithCellToBeEnlarged[col]) {
665-
LayoutArea cellOccupiedArea = currentRow[col].getOccupiedArea();
665+
LayoutArea cellOccupiedArea = splitResult[1].rows.get(0)[col].getOccupiedArea();
666666
if (1 == minRowspan) {
667667
// Here we use the same cell, but create a new renderer which doesn't have any children,
668668
// therefore it won't have any content.
669-
Cell overflowCell = currentRow[col].getModelElement().clone(true); // we will change properties
670-
currentRow[col].isLastRendererForModelElement = false;
671-
childRenderers.add(currentRow[col]);
672-
currentRow[col] = null;
673-
rows.get(targetOverflowRowIndex[col])[col] = (CellRenderer) overflowCell.getRenderer().setParent(this);
674-
rows.get(targetOverflowRowIndex[col])[col].deleteProperty(Property.HEIGHT);
675-
rows.get(targetOverflowRowIndex[col])[col].deleteProperty(Property.MIN_HEIGHT);
676-
rows.get(targetOverflowRowIndex[col])[col].deleteProperty(Property.MAX_HEIGHT);
669+
Cell overflowCell = splitResult[1].rows.get(0)[col].getModelElement().clone(true); // we will change properties
670+
splitResult[1].rows.get(0)[col].isLastRendererForModelElement = false;
671+
childRenderers.add(splitResult[1].rows.get(0)[col]);
672+
splitResult[1].rows.get(0)[col] = null;
673+
splitResult[1].rows.get(targetOverflowRowIndex[col] - row)[col] = (CellRenderer) overflowCell.getRenderer().setParent(this);
674+
splitResult[1].rows.get(targetOverflowRowIndex[col] - row)[col].deleteProperty(Property.HEIGHT);
675+
splitResult[1].rows.get(targetOverflowRowIndex[col] - row)[col].deleteProperty(Property.MIN_HEIGHT);
676+
splitResult[1].rows.get(targetOverflowRowIndex[col] - row)[col].deleteProperty(Property.MAX_HEIGHT);
677677
} else {
678-
childRenderers.add(currentRow[col]);
678+
childRenderers.add(splitResult[1].rows.get(0)[col]);
679679
// shift all cells in the column up
680680
int i = row;
681-
for (; i < row + minRowspan && i + 1 < rows.size() && rows.get(i + 1)[col] != null; i++) {
682-
rows.get(i)[col] = rows.get(i + 1)[col];
683-
rows.get(i + 1)[col] = null;
681+
for (; i < row + minRowspan && i + 1 < rows.size() && splitResult[1].rows.get(i + 1 - row)[col] != null; i++) {
682+
splitResult[1].rows.get(i - row)[col] = splitResult[1].rows.get(i + 1 - row)[col];
683+
splitResult[1].rows.get(i + 1 - row)[col] = null;
684684
}
685685
// the number of cells behind is less then minRowspan-1
686686
// so we should process the last cell in the column as in the case 1 == minRowspan
687687
if (i != row + minRowspan - 1 && null != rows.get(i)[col]) {
688688
Cell overflowCell = rows.get(i)[col].getModelElement();
689-
rows.get(i)[col].isLastRendererForModelElement = false;
690-
rows.get(i)[col] = null;
691-
rows.get(targetOverflowRowIndex[col])[col] = (CellRenderer) overflowCell.getRenderer().setParent(this);
689+
splitResult[1].rows.get(i - row)[col].isLastRendererForModelElement = false;
690+
splitResult[1].rows.get(i - row)[col] = null;
691+
splitResult[1].rows.get(targetOverflowRowIndex[col] - row)[col] = (CellRenderer) overflowCell.getRenderer().setParent(this);
692692
}
693693
}
694-
rows.get(targetOverflowRowIndex[col])[col].occupiedArea = cellOccupiedArea;
694+
splitResult[1].rows.get(targetOverflowRowIndex[col] - row)[col].occupiedArea = cellOccupiedArea;
695695
}
696696
}
697697
}
@@ -709,7 +709,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
709709
}
710710
if (Boolean.TRUE.equals(getPropertyAsBoolean(Property.FILL_AVAILABLE_AREA))
711711
|| Boolean.TRUE.equals(getPropertyAsBoolean(Property.FILL_AVAILABLE_AREA_ON_SPLIT))) {
712-
extendLastRow(currentRow, layoutBox);
712+
extendLastRow(splitResult[1].rows.get(0), layoutBox);
713713
}
714714
adjustFooterAndFixOccupiedArea(layoutBox);
715715

0 commit comments

Comments
 (0)