Skip to content

Commit 6a4ae76

Browse files
author
joris.schellekens
committed
implemented code review remarks
resolves DEVSIX-1398
1 parent 2c92884 commit 6a4ae76

File tree

1 file changed

+43
-41
lines changed

1 file changed

+43
-41
lines changed

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

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -73,52 +73,54 @@ protected CollapsedTableBorders collapseAllBordersAndEmptyRows() {
7373
CellRenderer[] currentRow;
7474
int[] rowspansToDeduct = new int[numberOfColumns];
7575
int numOfRowsToRemove = 0;
76-
for (int row = startRow - largeTableIndexOffset; row <= finishRow - largeTableIndexOffset; row++) {
77-
currentRow = rows.isEmpty() ? null : rows.get(row);
78-
boolean hasCells = false;
79-
for (int col = 0; col < numberOfColumns; col++) {
80-
if (null != currentRow && null != currentRow[col]) {
81-
int colspan = (int) currentRow[col].getPropertyAsInteger(Property.COLSPAN);
82-
if (rowspansToDeduct[col] > 0) {
83-
int rowspan = (int) currentRow[col].getPropertyAsInteger(Property.ROWSPAN) - rowspansToDeduct[col];
84-
if (rowspan < 1) {
85-
Logger logger = LoggerFactory.getLogger(TableRenderer.class);
86-
logger.warn(LogMessageConstant.UNEXPECTED_BEHAVIOUR_DURING_TABLE_ROW_COLLAPSING);
87-
rowspan = 1;
76+
if (!rows.isEmpty()) {
77+
for (int row = startRow - largeTableIndexOffset; row <= finishRow - largeTableIndexOffset; row++) {
78+
currentRow = rows.get(row);
79+
boolean hasCells = false;
80+
for (int col = 0; col < numberOfColumns; col++) {
81+
if (null != currentRow && null != currentRow[col]) {
82+
int colspan = (int) currentRow[col].getPropertyAsInteger(Property.COLSPAN);
83+
if (rowspansToDeduct[col] > 0) {
84+
int rowspan = (int) currentRow[col].getPropertyAsInteger(Property.ROWSPAN) - rowspansToDeduct[col];
85+
if (rowspan < 1) {
86+
Logger logger = LoggerFactory.getLogger(TableRenderer.class);
87+
logger.warn(LogMessageConstant.UNEXPECTED_BEHAVIOUR_DURING_TABLE_ROW_COLLAPSING);
88+
rowspan = 1;
89+
}
90+
currentRow[col].setProperty(Property.ROWSPAN, rowspan);
91+
if (0 != numOfRowsToRemove) {
92+
removeRows(row - numOfRowsToRemove, numOfRowsToRemove);
93+
row -= numOfRowsToRemove;
94+
numOfRowsToRemove = 0;
95+
}
8896
}
89-
currentRow[col].setProperty(Property.ROWSPAN, rowspan);
90-
if (0 != numOfRowsToRemove) {
91-
removeRows(row - numOfRowsToRemove, numOfRowsToRemove);
92-
row -= numOfRowsToRemove;
93-
numOfRowsToRemove = 0;
97+
buildBordersArrays(currentRow[col], row, col, rowspansToDeduct);
98+
hasCells = true;
99+
for (int i = 0; i < colspan; i++) {
100+
rowspansToDeduct[col + i] = 0;
101+
}
102+
col += colspan - 1;
103+
} else {
104+
if (horizontalBorders.get(row).size() <= col) {
105+
horizontalBorders.get(row).add(null);
94106
}
95-
}
96-
buildBordersArrays(currentRow[col], row, col, rowspansToDeduct);
97-
hasCells = true;
98-
for (int i = 0; i < colspan; i++) {
99-
rowspansToDeduct[col + i] = 0;
100-
}
101-
col += colspan - 1;
102-
} else {
103-
if (horizontalBorders.get(row).size() <= col) {
104-
horizontalBorders.get(row).add(null);
105107
}
106108
}
107-
}
108-
if (!hasCells) {
109-
if (row == rows.size() - 1) {
110-
removeRows(row - rowspansToDeduct[0], rowspansToDeduct[0]);
111-
// delete current row
112-
rows.remove(row - rowspansToDeduct[0]);
113-
setFinishRow(finishRow - 1);
114-
115-
Logger logger = LoggerFactory.getLogger(TableRenderer.class);
116-
logger.warn(LogMessageConstant.LAST_ROW_IS_NOT_COMPLETE);
117-
} else {
118-
for (int i = 0; i < numberOfColumns; i++) {
119-
rowspansToDeduct[i]++;
109+
if (!hasCells) {
110+
if (row == rows.size() - 1) {
111+
removeRows(row - rowspansToDeduct[0], rowspansToDeduct[0]);
112+
// delete current row
113+
rows.remove(row - rowspansToDeduct[0]);
114+
setFinishRow(finishRow - 1);
115+
116+
Logger logger = LoggerFactory.getLogger(TableRenderer.class);
117+
logger.warn(LogMessageConstant.LAST_ROW_IS_NOT_COMPLETE);
118+
} else {
119+
for (int i = 0; i < numberOfColumns; i++) {
120+
rowspansToDeduct[i]++;
121+
}
122+
numOfRowsToRemove++;
120123
}
121-
numOfRowsToRemove++;
122124
}
123125
}
124126
}

0 commit comments

Comments
 (0)