Skip to content

Commit

Permalink
#682 Fixed a bug in the previous solution.
Browse files Browse the repository at this point in the history
  • Loading branch information
imajic authored and angelozerr committed Jul 4, 2024
1 parent c85aeae commit de938b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import fr.opensagres.xdocreport.openpdf.extension.ExtendedPdfPTable;

import java.util.Arrays;
import java.util.stream.IntStream;

public class StylableTable
extends ExtendedPdfPTable
Expand Down Expand Up @@ -90,8 +91,8 @@ private void fitCellIntoSpansFromAbove(PdfPCell cell) {
int colSpan = cell.getColspan();

// skip all the cell places already spanned from above
while (spansFromAbove[spansFromAboveIdx] > 0){
if (spansFromAboveIdx < getNumberOfColumns()) {
do {
if (spansFromAboveIdx < getNumberOfColumns() && spansFromAbove[spansFromAboveIdx] > 0) {
spansFromAbove[spansFromAboveIdx]--;
spansFromAboveIdx++;
}
Expand All @@ -101,6 +102,7 @@ private void fitCellIntoSpansFromAbove(PdfPCell cell) {
beginTableRow(currentRowStyle);
}
}
while (spansFromAbove[spansFromAboveIdx] > 0);

for (int col = 0; col < colSpan; col++){
if (spansFromAbove[spansFromAboveIdx] > 0){
Expand All @@ -114,7 +116,10 @@ private void fitCellIntoSpansFromAbove(PdfPCell cell) {
}

private boolean reachedEndOfRow(){
return spansFromAboveIdx == getNumberOfColumns();
return spansFromAboveIdx == getNumberOfColumns()
// we might reach end of row by not yet reaching getNumberOfColumns() with spansFromAboveIdx, but in that
// case all the remaining columns in the row have to be spanned from above
|| IntStream.range(spansFromAboveIdx, getNumberOfColumns()).noneMatch(idx -> spansFromAbove[idx] == 0);
}

public void beginTableRow( Style currentRowStyle )
Expand Down
Binary file not shown.

0 comments on commit de938b7

Please sign in to comment.