@@ -734,7 +734,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
734
734
}
735
735
}
736
736
// Correct occupied areas of all added cells
737
- correctCellsOccupiedAreas (splits , row , targetOverflowRowIndex );
737
+ correctCellsOccupiedAreas (splits , row , targetOverflowRowIndex , blockMinHeight , layoutBox , bottomTableBorderWidth , row == rows . size () - 1 );
738
738
}
739
739
// process footer with collapsed borders
740
740
if ((split || processAsLast || row == rows .size () - 1 ) && null != footerRenderer ) {
@@ -1048,6 +1048,19 @@ public LayoutResult layout(LayoutContext layoutContext) {
1048
1048
verticalBorders .add (new ArrayList <Border >());
1049
1049
}
1050
1050
verticalBorders .add (rightVerticalBorders );
1051
+
1052
+ if (null != blockMinHeight && blockMinHeight > occupiedArea .getBBox ().getHeight () + bottomTableBorderWidth ) {
1053
+ float blockBottom = Math .max (occupiedArea .getBBox ().getBottom () - ((float ) blockMinHeight - occupiedArea .getBBox ().getHeight () - bottomTableBorderWidth ), layoutBox .getBottom () + bottomTableBorderWidth );
1054
+ if (0 != heights .size ()) {
1055
+ heights .set (heights .size () - 1 , heights .get (heights .size () - 1 ) + occupiedArea .getBBox ().getBottom () - blockBottom );
1056
+ } else {
1057
+ heights .add ((occupiedArea .getBBox ().getBottom () - blockBottom ) + topTableBorderWidth / 2 + bottomTableBorderWidth / 2 );
1058
+ }
1059
+
1060
+ occupiedArea .getBBox ()
1061
+ .increaseHeight (occupiedArea .getBBox ().getBottom () - blockBottom )
1062
+ .setY (blockBottom );
1063
+ }
1051
1064
}
1052
1065
1053
1066
// Apply bottom and top border
@@ -1087,20 +1100,6 @@ public LayoutResult layout(LayoutContext layoutContext) {
1087
1100
extendLastRow (rows .get (rows .size () - 1 ), layoutBox );
1088
1101
}
1089
1102
1090
- if (null != blockMinHeight && blockMinHeight > occupiedArea .getBBox ().getHeight ()) {
1091
- float blockBottom = Math .max (occupiedArea .getBBox ().getBottom () - ((float ) blockMinHeight - occupiedArea .getBBox ().getHeight ()), layoutBox .getBottom ());
1092
- if (0 != heights .size ()) {
1093
- heights .set (heights .size () - 1 , heights .get (heights .size () - 1 ) + occupiedArea .getBBox ().getBottom () - blockBottom );
1094
- } else {
1095
- heights .add ((occupiedArea .getBBox ().getBottom () - blockBottom ) + occupiedArea .getBBox ().getHeight () / 2 );
1096
- }
1097
-
1098
- occupiedArea .getBBox ()
1099
- .increaseHeight (occupiedArea .getBBox ().getBottom () - blockBottom )
1100
- .setY (blockBottom );
1101
- }
1102
-
1103
-
1104
1103
if (isPositioned ()) {
1105
1104
float y = (float ) this .getPropertyAsFloat (Property .Y );
1106
1105
float relativeY = isFixedLayout () ? 0 : layoutBox .getY ();
@@ -2007,31 +2006,43 @@ private void fixFooterBorders(List<Border> tableBottomBorders, int colNum, int r
2007
2006
}
2008
2007
}
2009
2008
2010
- private void correctCellsOccupiedAreas (LayoutResult [] splits , int row , int [] targetOverflowRowIndex ) {
2011
- // Correct occupied areas of all added cells
2012
- for (int k = 0 ; k <= row ; k ++) {
2013
- CellRenderer [] currentRow = rows .get (k );
2014
- if (k < row || (row + 1 == heights .size ())) {
2015
- for (int col = 0 ; col < currentRow .length ; col ++) {
2016
- CellRenderer cell = (k < row || null == splits [col ]) ? currentRow [col ] : (CellRenderer ) splits [col ].getSplitRenderer ();
2017
- if (cell == null ) {
2018
- continue ;
2019
- }
2020
- float height = 0 ;
2021
- int rowspan = (int ) cell .getPropertyAsInteger (Property .ROWSPAN );
2022
- for (int l = k ; l > ((k == row + 1 ) ? targetOverflowRowIndex [col ] : k ) - rowspan && l >= 0 ; l --) {
2023
- height += (float ) heights .get (l );
2024
- }
2025
- // Correcting cell bbox only. We don't need #move() here.
2026
- // This is because of BlockRenderer's specificity regarding occupied area.
2027
- float shift = height - cell .getOccupiedArea ().getBBox ().getHeight ();
2028
- Rectangle bBox = cell .getOccupiedArea ().getBBox ();
2029
- bBox .moveDown (shift );
2030
- bBox .setHeight (height );
2031
- cell .applyVerticalAlignment ();
2009
+ private void correctCellsOccupiedAreas (LayoutResult [] splits , int row , int [] targetOverflowRowIndex , Float blockMinHeight , Rectangle layoutBox , float bottomTableBorderWidth , boolean isLastRenderer ) {
2010
+ float additionalCellHeight = 0 ;
2011
+ if (isLastRenderer ) {
2012
+ if (null != blockMinHeight && blockMinHeight > occupiedArea .getBBox ().getHeight () + bottomTableBorderWidth / 2 ) {
2013
+ additionalCellHeight = Math .min (layoutBox .getHeight () - bottomTableBorderWidth / 2 , blockMinHeight - occupiedArea .getBBox ().getHeight () - bottomTableBorderWidth / 2 ) / heights .size ();
2014
+ for (int i = 0 ; i < heights .size (); i ++) {
2015
+ heights .set (i , heights .get (i ) + additionalCellHeight );
2032
2016
}
2033
2017
}
2034
2018
}
2019
+ float cumulativeShift = 0 ;
2020
+ // Correct occupied areas of all added cells
2021
+ for (int k = 0 ; k < heights .size (); k ++) {
2022
+ CellRenderer [] currentRow = rows .get (k );
2023
+ for (int col = 0 ; col < currentRow .length ; col ++) {
2024
+ CellRenderer cell = (k < row || null == splits [col ]) ? currentRow [col ] : (CellRenderer ) splits [col ].getSplitRenderer ();
2025
+ if (cell == null ) {
2026
+ continue ;
2027
+ }
2028
+ float height = 0 ;
2029
+ int rowspan = (int ) cell .getPropertyAsInteger (Property .ROWSPAN );
2030
+ for (int l = k ; l > ((k == row + 1 ) ? targetOverflowRowIndex [col ] : k ) - rowspan && l >= 0 ; l --) {
2031
+ height += (float ) heights .get (l );
2032
+ }
2033
+ // Correcting cell bbox only. We don't need #move() here.
2034
+ // This is because of BlockRenderer's specificity regarding occupied area.
2035
+ float shift = height - cell .getOccupiedArea ().getBBox ().getHeight ();
2036
+ Rectangle bBox = cell .getOccupiedArea ().getBBox ();
2037
+ bBox .moveDown (shift );
2038
+ bBox .setHeight (height );
2039
+ cell .move (0 , - (cumulativeShift - (rowspan - 1 ) * additionalCellHeight ));
2040
+ cell .applyVerticalAlignment ();
2041
+ }
2042
+ cumulativeShift += additionalCellHeight ;
2043
+ }
2044
+ occupiedArea .getBBox ().moveDown (cumulativeShift ).increaseHeight (cumulativeShift );
2045
+ layoutBox .decreaseHeight (cumulativeShift );
2035
2046
}
2036
2047
2037
2048
private void prepareBuildingBordersArrays (CellRenderer cell , Border [] tableBorders , int colNum , int row , int col ) {
@@ -2328,7 +2339,7 @@ private float getTableWidth() {
2328
2339
2329
2340
protected TableRenderer saveCellsProperties () {
2330
2341
CellRenderer [] currentRow ;
2331
- int colN = ((Table )getModelElement ()).getNumberOfColumns ();
2342
+ int colN = ((Table ) getModelElement ()).getNumberOfColumns ();
2332
2343
for (int row = 0 ; row < rows .size (); row ++) {
2333
2344
currentRow = rows .get (row );
2334
2345
for (int col = 0 ; col < colN ; col ++) {
@@ -2342,7 +2353,7 @@ protected TableRenderer saveCellsProperties() {
2342
2353
2343
2354
protected TableRenderer restoreCellsProperties () {
2344
2355
CellRenderer [] currentRow ;
2345
- int colN = ((Table )getModelElement ()).getNumberOfColumns ();
2356
+ int colN = ((Table ) getModelElement ()).getNumberOfColumns ();
2346
2357
for (int row = 0 ; row < rows .size (); row ++) {
2347
2358
currentRow = rows .get (row );
2348
2359
for (int col = 0 ; col < colN ; col ++) {
0 commit comments