Block[][] blocks = new Block[getTableCell().getNumberRowsSpanned()][getTableCell()
.getNumberColumnsSpanned()];
GridUnit[] gridUnits = (GridUnit[]) primaryGridUnit.getRows().get(startRow);
for (int x = 0; x < getTableCell().getNumberColumnsSpanned(); x++) {
GridUnit gu = gridUnits[x];
BorderInfo border = gu.getBorderBefore(borderBeforeWhich);
int borderWidth = border.getRetainedWidth() / 2;
if (borderWidth > 0) {
addBorder(blocks, startRow, x, Trait.BORDER_BEFORE, border, firstOnPage);
adjustYOffset(blocks[startRow][x], -borderWidth);
adjustBPD(blocks[startRow][x], -borderWidth);
}
}
gridUnits = (GridUnit[]) primaryGridUnit.getRows().get(endRow);
for (int x = 0; x < getTableCell().getNumberColumnsSpanned(); x++) {
GridUnit gu = gridUnits[x];
BorderInfo border = gu.getBorderAfter(borderAfterWhich);
int borderWidth = border.getRetainedWidth() / 2;
if (borderWidth > 0) {
addBorder(blocks, endRow, x, Trait.BORDER_AFTER, border, lastOnPage);
adjustBPD(blocks[endRow][x], -borderWidth);
}
}
for (int y = startRow; y <= endRow; y++) {
gridUnits = (GridUnit[]) primaryGridUnit.getRows().get(y);
BorderInfo border = gridUnits[0].getBorderStart();
int borderWidth = border.getRetainedWidth() / 2;
if (borderWidth > 0) {
addBorder(blocks, y, 0, Trait.BORDER_START, border, inFirstColumn);
adjustXOffset(blocks[y][0], borderWidth);
adjustIPD(blocks[y][0], -borderWidth);
}
border = gridUnits[gridUnits.length - 1].getBorderEnd();
borderWidth = border.getRetainedWidth() / 2;
if (borderWidth > 0) {
addBorder(blocks, y, gridUnits.length - 1, Trait.BORDER_END, border,
inLastColumn);
adjustIPD(blocks[y][gridUnits.length - 1], -borderWidth);
}