|
|
@ -53,25 +53,28 @@ import java.util.ArrayList; |
|
|
|
|
|
|
|
|
|
|
|
import com.fr.third.com.lowagie.text.DocumentException; |
|
|
|
import com.fr.third.com.lowagie.text.DocumentException; |
|
|
|
import com.fr.third.com.lowagie.text.Element; |
|
|
|
import com.fr.third.com.lowagie.text.Element; |
|
|
|
|
|
|
|
import com.fr.third.com.lowagie.text.LargeElement; |
|
|
|
import com.fr.third.com.lowagie.text.ElementListener; |
|
|
|
import com.fr.third.com.lowagie.text.ElementListener; |
|
|
|
import com.fr.third.com.lowagie.text.Image; |
|
|
|
import com.fr.third.com.lowagie.text.Image; |
|
|
|
import com.fr.third.com.lowagie.text.LargeElement; |
|
|
|
|
|
|
|
import com.fr.third.com.lowagie.text.Phrase; |
|
|
|
import com.fr.third.com.lowagie.text.Phrase; |
|
|
|
import com.fr.third.com.lowagie.text.Rectangle; |
|
|
|
import com.fr.third.com.lowagie.text.Rectangle; |
|
|
|
import com.fr.third.com.lowagie.text.pdf.events.PdfPTableEventForwarder; |
|
|
|
import com.fr.third.com.lowagie.text.pdf.events.PdfPTableEventForwarder; |
|
|
|
|
|
|
|
import com.fr.third.com.lowagie.text.pdf.BorderStyle; |
|
|
|
|
|
|
|
import com.fr.third.com.lowagie.text.pdf.TableProperties; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* This is a table that can be put at an absolute position but can also |
|
|
|
* This is a table that can be put at an absolute position but can also |
|
|
|
* be added to the document as the class <CODE>Table</CODE>. |
|
|
|
* be added to the document as the class <CODE>Table</CODE>. |
|
|
|
* In the last case when crossing pages the table always break at full rows; if a |
|
|
|
* In the last case when crossing pages the table always break at full rows; if a |
|
|
|
* row is bigger than the page it is dropped silently to avoid infinite loops. |
|
|
|
* row is bigger than the page it is dropped silently to avoid infinite loops. |
|
|
|
* <P> |
|
|
|
* <p> |
|
|
|
* A PdfPTableEvent can be associated to the table to do custom drawing |
|
|
|
* A PdfPTableEvent can be associated to the table to do custom drawing |
|
|
|
* when the table is rendered. |
|
|
|
* when the table is rendered. |
|
|
|
|
|
|
|
* |
|
|
|
* @author Paulo Soares (psoares@consiste.pt) |
|
|
|
* @author Paulo Soares (psoares@consiste.pt) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
public class PdfPTable implements LargeElement{ |
|
|
|
public class PdfPTable implements LargeElement { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The index of the original <CODE>PdfcontentByte</CODE>. |
|
|
|
* The index of the original <CODE>PdfcontentByte</CODE>. |
|
|
@ -97,12 +100,20 @@ public class PdfPTable implements LargeElement{ |
|
|
|
protected float totalHeight = 0; |
|
|
|
protected float totalHeight = 0; |
|
|
|
protected PdfPCell currentRow[]; |
|
|
|
protected PdfPCell currentRow[]; |
|
|
|
protected int currentRowIdx = 0; |
|
|
|
protected int currentRowIdx = 0; |
|
|
|
protected PdfPCell defaultCell = new PdfPCell((Phrase)null); |
|
|
|
protected PdfPCell defaultCell = new PdfPCell((Phrase) null); |
|
|
|
protected float totalWidth = 0; |
|
|
|
protected float totalWidth = 0; |
|
|
|
protected float relativeWidths[]; |
|
|
|
protected float relativeWidths[]; |
|
|
|
protected float absoluteWidths[]; |
|
|
|
protected float absoluteWidths[]; |
|
|
|
protected PdfPTableEvent tableEvent; |
|
|
|
protected PdfPTableEvent tableEvent; |
|
|
|
|
|
|
|
private TableProperties tableProperties; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TableProperties getTableProperties() { |
|
|
|
|
|
|
|
return tableProperties; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setTableProperties(TableProperties tableProperties) { |
|
|
|
|
|
|
|
this.tableProperties = tableProperties; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Holds value of property headerRows. |
|
|
|
* Holds value of property headerRows. |
|
|
@ -125,6 +136,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
private boolean skipFirstHeader = false; |
|
|
|
private boolean skipFirstHeader = false; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Holds value of property skipLastFooter. |
|
|
|
* Holds value of property skipLastFooter. |
|
|
|
|
|
|
|
* |
|
|
|
* @since 2.1.6 |
|
|
|
* @since 2.1.6 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private boolean skipLastFooter = false; |
|
|
|
private boolean skipLastFooter = false; |
|
|
@ -188,6 +200,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Keeps track of the completeness of the current row. |
|
|
|
* Keeps track of the completeness of the current row. |
|
|
|
|
|
|
|
* |
|
|
|
* @since 2.1.6 |
|
|
|
* @since 2.1.6 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected boolean rowCompleted = true; |
|
|
|
protected boolean rowCompleted = true; |
|
|
@ -243,7 +256,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
currentRow[k] = new PdfPCell(table.currentRow[k]); |
|
|
|
currentRow[k] = new PdfPCell(table.currentRow[k]); |
|
|
|
} |
|
|
|
} |
|
|
|
for (int k = 0; k < table.rows.size(); ++k) { |
|
|
|
for (int k = 0; k < table.rows.size(); ++k) { |
|
|
|
PdfPRow row = (PdfPRow)(table.rows.get(k)); |
|
|
|
PdfPRow row = (PdfPRow) (table.rows.get(k)); |
|
|
|
if (row != null) |
|
|
|
if (row != null) |
|
|
|
row = new PdfPRow(row); |
|
|
|
row = new PdfPRow(row); |
|
|
|
rows.add(row); |
|
|
|
rows.add(row); |
|
|
@ -296,6 +309,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
horizontalAlignment = sourceTable.horizontalAlignment; |
|
|
|
horizontalAlignment = sourceTable.horizontalAlignment; |
|
|
|
keepTogether = sourceTable.keepTogether; |
|
|
|
keepTogether = sourceTable.keepTogether; |
|
|
|
complete = sourceTable.complete; |
|
|
|
complete = sourceTable.complete; |
|
|
|
|
|
|
|
tableProperties = sourceTable.tableProperties; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -313,7 +327,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
absoluteWidths = new float[relativeWidths.length]; |
|
|
|
absoluteWidths = new float[relativeWidths.length]; |
|
|
|
totalHeight = 0; |
|
|
|
totalHeight = 0; |
|
|
|
calculateWidths(); |
|
|
|
calculateWidths(); |
|
|
|
calculateHeights(true); |
|
|
|
// calculateHeights(true);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -338,10 +352,14 @@ public class PdfPTable implements LargeElement{ |
|
|
|
return; |
|
|
|
return; |
|
|
|
float total = 0; |
|
|
|
float total = 0; |
|
|
|
int numCols = getNumberOfColumns(); |
|
|
|
int numCols = getNumberOfColumns(); |
|
|
|
|
|
|
|
BorderStyle borderStyle = tableProperties.getBorderStyle(); |
|
|
|
|
|
|
|
float borderWidth = tableProperties.isCollapse() ? borderStyle.getBorderWidth() / 2 : borderStyle.getBorderWidth(); |
|
|
|
|
|
|
|
float cellspacing = tableProperties.getCellspacing(); |
|
|
|
|
|
|
|
float cellpadding = tableProperties.getCellpadding(); |
|
|
|
for (int k = 0; k < numCols; ++k) |
|
|
|
for (int k = 0; k < numCols; ++k) |
|
|
|
total += relativeWidths[k]; |
|
|
|
total += relativeWidths[k]; |
|
|
|
for (int k = 0; k < numCols; ++k) |
|
|
|
for (int k = 0; k < numCols; ++k) |
|
|
|
absoluteWidths[k] = totalWidth * relativeWidths[k] / total; |
|
|
|
absoluteWidths[k] = (totalWidth - cellspacing * (numCols + 1) - numCols * 2 * (borderWidth + cellpadding) - 2 * borderWidth) * relativeWidths[k] / total; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -355,7 +373,11 @@ public class PdfPTable implements LargeElement{ |
|
|
|
this.totalWidth = totalWidth; |
|
|
|
this.totalWidth = totalWidth; |
|
|
|
totalHeight = 0; |
|
|
|
totalHeight = 0; |
|
|
|
calculateWidths(); |
|
|
|
calculateWidths(); |
|
|
|
calculateHeights(true); |
|
|
|
// calculateHeights(true);
|
|
|
|
|
|
|
|
for (int k = 0; k < rows.size(); ++k) { |
|
|
|
|
|
|
|
PdfPRow row = (PdfPRow) rows.get(k); |
|
|
|
|
|
|
|
row.setWidths(absoluteWidths); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -415,9 +437,14 @@ public class PdfPTable implements LargeElement{ |
|
|
|
if (totalWidth <= 0) |
|
|
|
if (totalWidth <= 0) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
totalHeight = 0; |
|
|
|
totalHeight = 0; |
|
|
|
|
|
|
|
BorderStyle borderStyle = tableProperties.getBorderStyle(); |
|
|
|
|
|
|
|
float borderWidth = tableProperties.isCollapse() ? borderStyle.getBorderWidth() / 2 : borderStyle.getBorderWidth(); |
|
|
|
|
|
|
|
float cellspacing = tableProperties.getCellspacing(); |
|
|
|
|
|
|
|
float cellpadding = tableProperties.getCellpadding(); |
|
|
|
for (int k = 0; k < rows.size(); ++k) { |
|
|
|
for (int k = 0; k < rows.size(); ++k) { |
|
|
|
totalHeight += getRowHeight(k, firsttime); |
|
|
|
totalHeight += getRowHeight(k, firsttime); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
totalHeight += (rows.size() + 1) * 2 * borderWidth + cellpadding * 2 * rows.size() + (rows.size() + 1) * cellspacing; |
|
|
|
return totalHeight; |
|
|
|
return totalHeight; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -487,7 +514,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
PdfPRow row = new PdfPRow(currentRow); |
|
|
|
PdfPRow row = new PdfPRow(currentRow); |
|
|
|
if (totalWidth > 0) { |
|
|
|
if (totalWidth > 0) { |
|
|
|
row.setWidths(absoluteWidths); |
|
|
|
row.setWidths(absoluteWidths); |
|
|
|
totalHeight += row.getMaxHeights(); |
|
|
|
// totalHeight += row.getMaxHeights();
|
|
|
|
} |
|
|
|
} |
|
|
|
rows.add(row); |
|
|
|
rows.add(row); |
|
|
|
currentRow = new PdfPCell[numCols]; |
|
|
|
currentRow = new PdfPCell[numCols]; |
|
|
@ -504,6 +531,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
/** |
|
|
|
/** |
|
|
|
* When updating the row index, cells with rowspan should be taken into account. |
|
|
|
* When updating the row index, cells with rowspan should be taken into account. |
|
|
|
* This is what happens in this method. |
|
|
|
* This is what happens in this method. |
|
|
|
|
|
|
|
* |
|
|
|
* @since 2.1.6 |
|
|
|
* @since 2.1.6 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void skipColsWithRowspanAbove() { |
|
|
|
private void skipColsWithRowspanAbove() { |
|
|
@ -516,6 +544,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Checks if there are rows above belonging to a rowspan. |
|
|
|
* Checks if there are rows above belonging to a rowspan. |
|
|
|
|
|
|
|
* |
|
|
|
* @param currRow the current row to check |
|
|
|
* @param currRow the current row to check |
|
|
|
* @param currCol the current column to check |
|
|
|
* @param currCol the current column to check |
|
|
|
* @return true if there's a cell above that belongs to a rowspan |
|
|
|
* @return true if there's a cell above that belongs to a rowspan |
|
|
@ -529,34 +558,34 @@ public class PdfPTable implements LargeElement{ |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
int row = currRow - 1; |
|
|
|
int row = currRow - 1; |
|
|
|
PdfPRow aboveRow = (PdfPRow)rows.get(row); |
|
|
|
PdfPRow aboveRow = (PdfPRow) rows.get(row); |
|
|
|
if (aboveRow == null) |
|
|
|
if (aboveRow == null) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
PdfPCell aboveCell = (PdfPCell)aboveRow.getCells()[currCol]; |
|
|
|
PdfPCell aboveCell = (PdfPCell) aboveRow.getCells()[currCol]; |
|
|
|
while ((aboveCell == null) && (row > 0)) { |
|
|
|
while ((aboveCell == null) && (row > 0)) { |
|
|
|
aboveRow = (PdfPRow)rows.get(--row); |
|
|
|
aboveRow = (PdfPRow) rows.get(--row); |
|
|
|
if (aboveRow == null) |
|
|
|
if (aboveRow == null) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
aboveCell = (PdfPCell)aboveRow.getCells()[currCol]; |
|
|
|
aboveCell = (PdfPCell) aboveRow.getCells()[currCol]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int distance = currRow - row; |
|
|
|
int distance = currRow - row; |
|
|
|
|
|
|
|
|
|
|
|
if (aboveCell == null) { |
|
|
|
if (aboveCell == null) { |
|
|
|
int col = currCol - 1; |
|
|
|
int col = currCol - 1; |
|
|
|
aboveCell = (PdfPCell)aboveRow.getCells()[col]; |
|
|
|
aboveCell = (PdfPCell) aboveRow.getCells()[col]; |
|
|
|
while ((aboveCell == null) && (row > 0)) |
|
|
|
while ((aboveCell == null) && (row > 0)) |
|
|
|
aboveCell = (PdfPCell)aboveRow.getCells()[--col]; |
|
|
|
aboveCell = (PdfPCell) aboveRow.getCells()[--col]; |
|
|
|
return aboveCell != null && aboveCell.getRowspan() > distance; |
|
|
|
return aboveCell != null && aboveCell.getRowspan() > distance; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ((aboveCell.getRowspan() == 1) && (distance > 1)) { |
|
|
|
if ((aboveCell.getRowspan() == 1) && (distance > 1)) { |
|
|
|
int col = currCol - 1; |
|
|
|
int col = currCol - 1; |
|
|
|
aboveRow = (PdfPRow)rows.get(row + 1); |
|
|
|
aboveRow = (PdfPRow) rows.get(row + 1); |
|
|
|
distance--; |
|
|
|
distance--; |
|
|
|
aboveCell = (PdfPCell)aboveRow.getCells()[col]; |
|
|
|
aboveCell = (PdfPCell) aboveRow.getCells()[col]; |
|
|
|
while ((aboveCell == null) && (col > 0)) |
|
|
|
while ((aboveCell == null) && (col > 0)) |
|
|
|
aboveCell = (PdfPCell)aboveRow.getCells()[--col]; |
|
|
|
aboveCell = (PdfPCell) aboveRow.getCells()[--col]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return aboveCell != null && aboveCell.getRowspan() > distance; |
|
|
|
return aboveCell != null && aboveCell.getRowspan() > distance; |
|
|
@ -618,7 +647,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
* @param canvases an array of 4 <CODE>PdfContentByte</CODE> obtained from |
|
|
|
* @param canvases an array of 4 <CODE>PdfContentByte</CODE> obtained from |
|
|
|
* <CODE>beginWrittingRows()</CODE> |
|
|
|
* <CODE>beginWrittingRows()</CODE> |
|
|
|
* @return the y coordinate position of the bottom of the last row |
|
|
|
* @return the y coordinate position of the bottom of the last row |
|
|
|
* @see #beginWritingRows(com.fr.third.com.lowagie.text.pdf.PdfContentByte) |
|
|
|
* @see #beginWritingRows(PdfContentByte) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public float writeSelectedRows(int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte[] canvases) { |
|
|
|
public float writeSelectedRows(int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte[] canvases) { |
|
|
|
return writeSelectedRows(0, -1, rowStart, rowEnd, xPos, yPos, canvases); |
|
|
|
return writeSelectedRows(0, -1, rowStart, rowEnd, xPos, yPos, canvases); |
|
|
@ -642,7 +671,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
* @param canvases an array of 4 <CODE>PdfContentByte</CODE> obtained from |
|
|
|
* @param canvases an array of 4 <CODE>PdfContentByte</CODE> obtained from |
|
|
|
* <CODE>beginWritingRows()</CODE> |
|
|
|
* <CODE>beginWritingRows()</CODE> |
|
|
|
* @return the y coordinate position of the bottom of the last row |
|
|
|
* @return the y coordinate position of the bottom of the last row |
|
|
|
* @see #beginWritingRows(com.fr.third.com.lowagie.text.pdf.PdfContentByte) |
|
|
|
* @see #beginWritingRows(PdfContentByte) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public float writeSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte[] canvases) { |
|
|
|
public float writeSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte[] canvases) { |
|
|
|
if (totalWidth <= 0) |
|
|
|
if (totalWidth <= 0) |
|
|
@ -670,7 +699,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
|
|
|
|
|
|
|
|
float yPosStart = yPos; |
|
|
|
float yPosStart = yPos; |
|
|
|
for (int k = rowStart; k < rowEnd; ++k) { |
|
|
|
for (int k = rowStart; k < rowEnd; ++k) { |
|
|
|
PdfPRow row = (PdfPRow)rows.get(k); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(k); |
|
|
|
if (row != null) { |
|
|
|
if (row != null) { |
|
|
|
row.writeCells(colStart, colEnd, xPos, yPos, canvases); |
|
|
|
row.writeCells(colStart, colEnd, xPos, yPos, canvases); |
|
|
|
yPos -= row.getMaxHeights(); |
|
|
|
yPos -= row.getMaxHeights(); |
|
|
@ -681,7 +710,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
float heights[] = new float[rowEnd - rowStart + 1]; |
|
|
|
float heights[] = new float[rowEnd - rowStart + 1]; |
|
|
|
heights[0] = yPosStart; |
|
|
|
heights[0] = yPosStart; |
|
|
|
for (int k = rowStart; k < rowEnd; ++k) { |
|
|
|
for (int k = rowStart; k < rowEnd; ++k) { |
|
|
|
PdfPRow row = (PdfPRow)rows.get(k); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(k); |
|
|
|
float hr = 0; |
|
|
|
float hr = 0; |
|
|
|
if (row != null) |
|
|
|
if (row != null) |
|
|
|
hr = row.getMaxHeights(); |
|
|
|
hr = row.getMaxHeights(); |
|
|
@ -835,6 +864,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
public float getRowHeight(int idx) { |
|
|
|
public float getRowHeight(int idx) { |
|
|
|
return getRowHeight(idx, false); |
|
|
|
return getRowHeight(idx, false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Gets the height of a particular row. |
|
|
|
* Gets the height of a particular row. |
|
|
|
* |
|
|
|
* |
|
|
@ -846,7 +876,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
public float getRowHeight(int idx, boolean firsttime) { |
|
|
|
public float getRowHeight(int idx, boolean firsttime) { |
|
|
|
if (totalWidth <= 0 || idx < 0 || idx >= rows.size()) |
|
|
|
if (totalWidth <= 0 || idx < 0 || idx >= rows.size()) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
PdfPRow row = (PdfPRow)rows.get(idx); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(idx); |
|
|
|
if (row == null) |
|
|
|
if (row == null) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
if (firsttime) |
|
|
|
if (firsttime) |
|
|
@ -855,16 +885,14 @@ public class PdfPTable implements LargeElement{ |
|
|
|
PdfPCell cell; |
|
|
|
PdfPCell cell; |
|
|
|
PdfPRow tmprow; |
|
|
|
PdfPRow tmprow; |
|
|
|
for (int i = 0; i < relativeWidths.length; i++) { |
|
|
|
for (int i = 0; i < relativeWidths.length; i++) { |
|
|
|
if(!rowSpanAbove(idx, i)) |
|
|
|
if (!rowSpanAbove(idx, i)) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
int rs = 1; |
|
|
|
int rs = 1; |
|
|
|
while (rowSpanAbove(idx - rs, i)) { |
|
|
|
while (rowSpanAbove(idx - rs, i)) { |
|
|
|
rs++; |
|
|
|
rs++; |
|
|
|
} |
|
|
|
} |
|
|
|
tmprow = (PdfPRow)rows.get(idx - rs); |
|
|
|
tmprow = (PdfPRow) rows.get(idx - rs); |
|
|
|
cell = tmprow.getCells()[i]; |
|
|
|
cell = tmprow.getCells()[i]; |
|
|
|
// @change null就不继续了,这个版本没考虑到rowSpan和colSpan都大于1的情况
|
|
|
|
|
|
|
|
if (cell == null) break; |
|
|
|
|
|
|
|
float tmp = 0; |
|
|
|
float tmp = 0; |
|
|
|
if (cell.getRowspan() == rs + 1) { |
|
|
|
if (cell.getRowspan() == rs + 1) { |
|
|
|
tmp = cell.getMaxHeight(); |
|
|
|
tmp = cell.getMaxHeight(); |
|
|
@ -884,15 +912,15 @@ public class PdfPTable implements LargeElement{ |
|
|
|
* Gets the maximum height of a cell in a particular row (will only be different |
|
|
|
* Gets the maximum height of a cell in a particular row (will only be different |
|
|
|
* from getRowHeight is one of the cells in the row has a rowspan > 1). |
|
|
|
* from getRowHeight is one of the cells in the row has a rowspan > 1). |
|
|
|
* |
|
|
|
* |
|
|
|
|
|
|
|
* @return the height of a particular row including rowspan |
|
|
|
* @param rowIndex the row index |
|
|
|
* @param rowIndex the row index |
|
|
|
* @param cellIndex the cell index |
|
|
|
* @param cellIndex the cell index |
|
|
|
* @return the height of a particular row including rowspan |
|
|
|
|
|
|
|
* @since 2.1.6 |
|
|
|
* @since 2.1.6 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public float getRowspanHeight(int rowIndex, int cellIndex) { |
|
|
|
public float getRowspanHeight(int rowIndex, int cellIndex) { |
|
|
|
if (totalWidth <= 0 || rowIndex < 0 || rowIndex >= rows.size()) |
|
|
|
if (totalWidth <= 0 || rowIndex < 0 || rowIndex >= rows.size()) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
PdfPRow row = (PdfPRow)rows.get(rowIndex); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(rowIndex); |
|
|
|
if (row == null || cellIndex >= row.getCells().length) |
|
|
|
if (row == null || cellIndex >= row.getCells().length) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
PdfPCell cell = row.getCells()[cellIndex]; |
|
|
|
PdfPCell cell = row.getCells()[cellIndex]; |
|
|
@ -915,7 +943,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
float total = 0; |
|
|
|
float total = 0; |
|
|
|
int size = Math.min(rows.size(), headerRows); |
|
|
|
int size = Math.min(rows.size(), headerRows); |
|
|
|
for (int k = 0; k < size; ++k) { |
|
|
|
for (int k = 0; k < size; ++k) { |
|
|
|
PdfPRow row = (PdfPRow)rows.get(k); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(k); |
|
|
|
if (row != null) |
|
|
|
if (row != null) |
|
|
|
total += row.getMaxHeights(); |
|
|
|
total += row.getMaxHeights(); |
|
|
|
} |
|
|
|
} |
|
|
@ -934,7 +962,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
int start = Math.max(0, headerRows - footerRows); |
|
|
|
int start = Math.max(0, headerRows - footerRows); |
|
|
|
int size = Math.min(rows.size(), headerRows); |
|
|
|
int size = Math.min(rows.size(), headerRows); |
|
|
|
for (int k = start; k < size; ++k) { |
|
|
|
for (int k = start; k < size; ++k) { |
|
|
|
PdfPRow row = (PdfPRow)rows.get(k); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(k); |
|
|
|
if (row != null) |
|
|
|
if (row != null) |
|
|
|
total += row.getMaxHeights(); |
|
|
|
total += row.getMaxHeights(); |
|
|
|
} |
|
|
|
} |
|
|
@ -951,7 +979,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
if (rowNumber < 0 || rowNumber >= rows.size()) |
|
|
|
if (rowNumber < 0 || rowNumber >= rows.size()) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
if (totalWidth > 0) { |
|
|
|
if (totalWidth > 0) { |
|
|
|
PdfPRow row = (PdfPRow)rows.get(rowNumber); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(rowNumber); |
|
|
|
if (row != null) |
|
|
|
if (row != null) |
|
|
|
totalHeight -= row.getMaxHeights(); |
|
|
|
totalHeight -= row.getMaxHeights(); |
|
|
|
} |
|
|
|
} |
|
|
@ -1037,16 +1065,16 @@ public class PdfPTable implements LargeElement{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @see com.fr.third.com.lowagie.text.Element#isContent() |
|
|
|
|
|
|
|
* @since iText 2.0.8 |
|
|
|
* @since iText 2.0.8 |
|
|
|
|
|
|
|
* @see Element#isContent() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean isContent() { |
|
|
|
public boolean isContent() { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @see com.fr.third.com.lowagie.text.Element#isNestable() |
|
|
|
|
|
|
|
* @since iText 2.0.8 |
|
|
|
* @since iText 2.0.8 |
|
|
|
|
|
|
|
* @see Element#isNestable() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean isNestable() { |
|
|
|
public boolean isNestable() { |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -1062,8 +1090,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
public boolean process(ElementListener listener) { |
|
|
|
public boolean process(ElementListener listener) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
return listener.add(this); |
|
|
|
return listener.add(this); |
|
|
|
} |
|
|
|
} catch (DocumentException de) { |
|
|
|
catch(DocumentException de) { |
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1114,7 +1141,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
* @return the row at position idx |
|
|
|
* @return the row at position idx |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public PdfPRow getRow(int idx) { |
|
|
|
public PdfPRow getRow(int idx) { |
|
|
|
return (PdfPRow)rows.get(idx); |
|
|
|
return (PdfPRow) rows.get(idx); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -1128,6 +1155,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Gets an arraylist with a selection of rows. |
|
|
|
* Gets an arraylist with a selection of rows. |
|
|
|
|
|
|
|
* |
|
|
|
* @param start the first row in the selection |
|
|
|
* @param start the first row in the selection |
|
|
|
* @param end the first row that isn't part of the selection |
|
|
|
* @param end the first row that isn't part of the selection |
|
|
|
* @return a selection of rows |
|
|
|
* @return a selection of rows |
|
|
@ -1176,6 +1204,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Calculates the extra height needed in a row because of rowspans. |
|
|
|
* Calculates the extra height needed in a row because of rowspans. |
|
|
|
|
|
|
|
* |
|
|
|
* @param start the index of the start row (the one to adjust) |
|
|
|
* @param start the index of the start row (the one to adjust) |
|
|
|
* @param end the index of the end row on the page |
|
|
|
* @param end the index of the end row on the page |
|
|
|
* @since 2.1.6 |
|
|
|
* @since 2.1.6 |
|
|
@ -1199,7 +1228,9 @@ public class PdfPTable implements LargeElement{ |
|
|
|
return row; |
|
|
|
return row; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** Sets the table event for this table. |
|
|
|
/** |
|
|
|
|
|
|
|
* Sets the table event for this table. |
|
|
|
|
|
|
|
* |
|
|
|
* @param event the table event for this table |
|
|
|
* @param event the table event for this table |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setTableEvent(PdfPTableEvent event) { |
|
|
|
public void setTableEvent(PdfPTableEvent event) { |
|
|
@ -1208,7 +1239,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
else if (this.tableEvent == null) |
|
|
|
else if (this.tableEvent == null) |
|
|
|
this.tableEvent = event; |
|
|
|
this.tableEvent = event; |
|
|
|
else if (this.tableEvent instanceof PdfPTableEventForwarder) |
|
|
|
else if (this.tableEvent instanceof PdfPTableEventForwarder) |
|
|
|
((PdfPTableEventForwarder)this.tableEvent).addTableEvent(event); |
|
|
|
((PdfPTableEventForwarder) this.tableEvent).addTableEvent(event); |
|
|
|
else { |
|
|
|
else { |
|
|
|
PdfPTableEventForwarder forward = new PdfPTableEventForwarder(); |
|
|
|
PdfPTableEventForwarder forward = new PdfPTableEventForwarder(); |
|
|
|
forward.addTableEvent(this.tableEvent); |
|
|
|
forward.addTableEvent(this.tableEvent); |
|
|
@ -1235,7 +1266,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
return absoluteWidths; |
|
|
|
return absoluteWidths; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
float [][] getEventWidths(float xPos, int firstRow, int lastRow, boolean includeHeaders) { |
|
|
|
float[][] getEventWidths(float xPos, int firstRow, int lastRow, boolean includeHeaders) { |
|
|
|
if (includeHeaders) { |
|
|
|
if (includeHeaders) { |
|
|
|
firstRow = Math.max(firstRow, headerRows); |
|
|
|
firstRow = Math.max(firstRow, headerRows); |
|
|
|
lastRow = Math.max(lastRow, headerRows); |
|
|
|
lastRow = Math.max(lastRow, headerRows); |
|
|
@ -1245,7 +1276,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
int n = 0; |
|
|
|
int n = 0; |
|
|
|
if (includeHeaders) { |
|
|
|
if (includeHeaders) { |
|
|
|
for (int k = 0; k < headerRows; ++k) { |
|
|
|
for (int k = 0; k < headerRows; ++k) { |
|
|
|
PdfPRow row = (PdfPRow)rows.get(k); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(k); |
|
|
|
if (row == null) |
|
|
|
if (row == null) |
|
|
|
++n; |
|
|
|
++n; |
|
|
|
else |
|
|
|
else |
|
|
@ -1253,14 +1284,13 @@ public class PdfPTable implements LargeElement{ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
for (; firstRow < lastRow; ++firstRow) { |
|
|
|
for (; firstRow < lastRow; ++firstRow) { |
|
|
|
PdfPRow row = (PdfPRow)rows.get(firstRow); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(firstRow); |
|
|
|
if (row == null) |
|
|
|
if (row == null) |
|
|
|
++n; |
|
|
|
++n; |
|
|
|
else |
|
|
|
else |
|
|
|
widths[n++] = row.getEventWidth(xPos); |
|
|
|
widths[n++] = row.getEventWidth(xPos); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
else { |
|
|
|
|
|
|
|
int numCols = getNumberOfColumns(); |
|
|
|
int numCols = getNumberOfColumns(); |
|
|
|
float width[] = new float[numCols + 1]; |
|
|
|
float width[] = new float[numCols + 1]; |
|
|
|
width[0] = xPos; |
|
|
|
width[0] = xPos; |
|
|
@ -1540,7 +1570,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @since iText 2.0.8 |
|
|
|
* @since iText 2.0.8 |
|
|
|
* @see com.fr.third.com.lowagie.text.LargeElement#flushContent() |
|
|
|
* @see LargeElement#flushContent() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void flushContent() { |
|
|
|
public void flushContent() { |
|
|
|
deleteBodyRows(); |
|
|
|
deleteBodyRows(); |
|
|
@ -1549,7 +1579,7 @@ public class PdfPTable implements LargeElement{ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @since iText 2.0.8 |
|
|
|
* @since iText 2.0.8 |
|
|
|
* @see com.fr.third.com.lowagie.text.LargeElement#isComplete() |
|
|
|
* @see LargeElement#isComplete() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean isComplete() { |
|
|
|
public boolean isComplete() { |
|
|
|
return complete; |
|
|
|
return complete; |
|
|
@ -1557,9 +1587,11 @@ public class PdfPTable implements LargeElement{ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @since iText 2.0.8 |
|
|
|
* @since iText 2.0.8 |
|
|
|
* @see com.fr.third.com.lowagie.text.LargeElement#setComplete(boolean) |
|
|
|
* @see LargeElement#setComplete(boolean) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setComplete(boolean complete) { |
|
|
|
public void setComplete(boolean complete) { |
|
|
|
this.complete = complete; |
|
|
|
this.complete = complete; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |