@@ -65,8 +65,6 @@ This file is part of the iText (R) project.
6565import com .itextpdf .layout .property .UnitValue ;
6666import com .itextpdf .layout .property .VerticalAlignment ;
6767import com .itextpdf .layout .tagging .LayoutTaggingHelper ;
68- import org .slf4j .Logger ;
69- import org .slf4j .LoggerFactory ;
7068
7169import java .util .ArrayDeque ;
7270import java .util .ArrayList ;
@@ -75,6 +73,8 @@ This file is part of the iText (R) project.
7573import java .util .HashMap ;
7674import java .util .List ;
7775import java .util .Map ;
76+ import org .slf4j .Logger ;
77+ import org .slf4j .LoggerFactory ;
7878
7979/**
8080 * This class represents the {@link IRenderer renderer} object for a {@link Table}
@@ -781,7 +781,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
781781 // And now, when we possess such knowledge, we are performing the second attempt, but we need to nullify results
782782 // from the previous attempt
783783 if (bordersHandler instanceof CollapsedTableBorders ) {
784- ((CollapsedTableBorders )bordersHandler ).setBottomBorderCollapseWith (null );
784+ ((CollapsedTableBorders ) bordersHandler ).setBottomBorderCollapseWith (null , null );
785785 }
786786 bordersHandler .collapseTableWithFooter (footerRenderer .bordersHandler , hasContent || 0 != childRenderers .size ());
787787
@@ -1050,10 +1050,6 @@ public LayoutResult layout(LayoutContext layoutContext) {
10501050 }
10511051 }
10521052 } else {
1053- // the bottom border should be processed and placed lately
1054- if (0 != heights .size ()) {
1055- heights .set (heights .size () - 1 , heights .get (heights .size () - 1 ) - bottomTableBorderWidth / 2 );
1056- }
10571053 if (null == footerRenderer ) {
10581054 if (0 != childRenderers .size ()) {
10591055 bordersHandler .applyBottomTableBorder (occupiedArea .getBBox (), layoutBox , 0 == childRenderers .size (), false , true );
@@ -1460,7 +1456,7 @@ private void drawBorders(DrawContext drawContext, boolean hasHeader, boolean has
14601456 }
14611457
14621458
1463- // process halves of the borders here
1459+ // process halves of horizontal bounding borders
14641460 if (childRenderers .size () == 0 ) {
14651461 Border [] borders = bordersHandler .tableBoundingBorders ;
14661462 if (null != borders [0 ]) {
@@ -1492,56 +1488,72 @@ private void drawBorders(DrawContext drawContext, boolean hasHeader, boolean has
14921488
14931489 if (bordersHandler instanceof CollapsedTableBorders ) {
14941490 if (hasFooter ) {
1495- ((CollapsedTableBorders ) bordersHandler ).setBottomBorderCollapseWith (footerRenderer .bordersHandler .getFirstHorizontalBorder ());
1491+ ((CollapsedTableBorders ) bordersHandler ).setBottomBorderCollapseWith (
1492+ footerRenderer .bordersHandler .getFirstHorizontalBorder (),
1493+ ((CollapsedTableBorders ) footerRenderer .bordersHandler )
1494+ .getVerticalBordersCrossingTopHorizontalBorder ());
14961495 } else if (isBottomTablePart ) {
1497- ((CollapsedTableBorders ) bordersHandler ).setBottomBorderCollapseWith (null );
1496+ ((CollapsedTableBorders ) bordersHandler ).setBottomBorderCollapseWith (null , null );
14981497 }
14991498 }
15001499 // we do not need to fix top border, because either this is header or the top border has been already written
15011500 float y1 = startY ;
1501+
1502+ float [] heightsArray = new float [heights .size ()];
1503+ for (int j = 0 ; j < heights .size (); j ++) {
1504+ heightsArray [j ] = heights .get (j );
1505+ }
1506+
1507+ // draw vertical borders
1508+ float x1 = startX ;
1509+ for (int i = 0 ; i <= bordersHandler .getNumberOfColumns (); i ++) {
1510+ bordersHandler .drawVerticalBorder (drawContext .getCanvas (),
1511+ new TableBorderDescriptor (i , startY , x1 , heightsArray ));
1512+ if (i < countedColumnWidth .length ) {
1513+ x1 += countedColumnWidth [i ];
1514+ }
1515+ }
1516+
1517+ // draw horizontal borders
1518+
1519+ // draw top border
15021520 if (isFooterRendererOfLargeTable ) {
1503- bordersHandler .drawHorizontalBorder (0 , startX , y1 , drawContext .getCanvas (), countedColumnWidth );
1521+ bordersHandler .drawHorizontalBorder (drawContext .getCanvas (), new TableBorderDescriptor (0 , startX , y1 ,
1522+ countedColumnWidth ));
15041523 }
1505- if (0 != heights .size ()) {
1524+ if (isTopTablePart ) {
1525+ bordersHandler .drawHorizontalBorder (drawContext .getCanvas (), new TableBorderDescriptor (0 , startX , startY ,
1526+ countedColumnWidth ));
1527+ }
1528+
1529+ // draw inner borders
1530+ if (!heights .isEmpty ()) {
15061531 y1 -= (float ) heights .get (0 );
15071532 }
15081533 for (int i = 1 ; i < heights .size (); i ++) {
1509- bordersHandler .drawHorizontalBorder (i , startX , y1 , drawContext .getCanvas (), countedColumnWidth );
1534+ bordersHandler .drawHorizontalBorder (drawContext .getCanvas (),
1535+ new TableBorderDescriptor (i , startX , y1 , countedColumnWidth ));
15101536 if (i < heights .size ()) {
15111537 y1 -= (float ) heights .get (i );
15121538 }
15131539 }
1514- if (!isBottomTablePart && isComplete ) {
1515- bordersHandler .drawHorizontalBorder (heights .size (), startX , y1 , drawContext .getCanvas (), countedColumnWidth );
1516- }
15171540
1518- float x1 = startX ;
1519- if (countedColumnWidth .length > 0 ) {
1520- x1 += countedColumnWidth [0 ];
1521- }
1522- for (int i = 1 ; i < bordersHandler .getNumberOfColumns (); i ++) {
1523- bordersHandler .drawVerticalBorder (i , startY , x1 , drawContext .getCanvas (), heights );
1524- if (i < countedColumnWidth .length ) {
1525- x1 += countedColumnWidth [i ];
1526- }
1541+ // draw bottom border
1542+ // TODO DEVSIX-5867 Check hasFooter, so that two footers are not drawn
1543+ if (!isBottomTablePart && isComplete ) {
1544+ bordersHandler .drawHorizontalBorder (drawContext .getCanvas (),
1545+ new TableBorderDescriptor (heights .size (), startX , y1 , countedColumnWidth ));
15271546 }
15281547
1529- // Draw bounding borders. Vertical borders are the last to draw in order to collapse with header / footer
1530- if (isTopTablePart ) {
1531- bordersHandler .drawHorizontalBorder (0 , startX , startY , drawContext .getCanvas (), countedColumnWidth );
1532- }
15331548 //!isLastRendererForModelElement is a check that this is a split render. This is the case with the splitting of
15341549 // one cell when part of the cell moves to the next page. Therefore, if such a splitting occurs, a bottom border
15351550 // should be drawn. However, this should not be done for empty renderers that are also created during splitting,
15361551 // but this splitting, if the table does not fit on the page and the next cell is added to the next page.
15371552 // In this case, this code should not be processed, since the border in the above code has already been drawn.
15381553 if (isBottomTablePart && (isComplete || (!isLastRendererForModelElement && !isEmptyTableRenderer ()))) {
1539- bordersHandler .drawHorizontalBorder (heights .size (), startX , y1 , drawContext .getCanvas (), countedColumnWidth );
1554+ bordersHandler .drawHorizontalBorder (drawContext .getCanvas (), new TableBorderDescriptor (
1555+ heights .size (), startX , y1 , countedColumnWidth ));
15401556 }
1541- // draw left
1542- bordersHandler .drawVerticalBorder (0 , startY , startX , drawContext .getCanvas (), heights );
1543- // draw right
1544- bordersHandler .drawVerticalBorder (bordersHandler .getNumberOfColumns (), startY , x1 , drawContext .getCanvas (), heights );
15451557
15461558 if (isTagged ) {
15471559 drawContext .getCanvas ().closeTag ();
0 commit comments