Skip to content

Commit 010d71a

Browse files
committed
Improve table auto layout in case empty cells with fixed table width
DEVSIX-1195
1 parent 36b7b2a commit 010d71a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,18 +414,23 @@ float[] autoLayout() {
414414
} else {
415415
float totalFixed = 0;
416416
float totalFlexible = 0;
417+
float flexibleCount = 0;
417418
for (int i = 0; i < numberOfColumns; i++) {
418419
if (widths[i].isFixed) {
419420
widths[i].finalWidth = widths[i].width;
420421
totalFixed += widths[i].width;
421422
} else if (!widths[i].isPercent) {
422423
totalFlexible += widths[i].width;
424+
flexibleCount++;
423425
}
424426
}
427+
assert totalFlexible > 0 || flexibleCount > 0;
425428
extraWidth = tableWidth - totalPercent - totalFixed;
426429
for (int i = 0; i < numberOfColumns; i++) {
427430
if (!widths[i].isPercent && !widths[i].isFixed) {
428-
widths[i].finalWidth = widths[i].width * extraWidth / totalFlexible;
431+
widths[i].finalWidth = totalFlexible > 0
432+
? widths[i].width * extraWidth / totalFlexible
433+
: extraWidth / flexibleCount;
429434
}
430435
}
431436
}

0 commit comments

Comments
 (0)