|
|
@ -108,7 +108,7 @@ public class PdfPTable implements LargeElement { |
|
|
|
protected PdfPTableEvent tableEvent; |
|
|
|
protected PdfPTableEvent tableEvent; |
|
|
|
private TableProperties tableProperties; |
|
|
|
private TableProperties tableProperties; |
|
|
|
|
|
|
|
|
|
|
|
private String[] firstColWidths; |
|
|
|
private List<String> firstLineColWidths; |
|
|
|
|
|
|
|
|
|
|
|
public TableProperties getTableProperties() { |
|
|
|
public TableProperties getTableProperties() { |
|
|
|
return tableProperties; |
|
|
|
return tableProperties; |
|
|
@ -118,8 +118,8 @@ public class PdfPTable implements LargeElement { |
|
|
|
this.tableProperties = tableProperties; |
|
|
|
this.tableProperties = tableProperties; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setFirstColWidths(String[] firstColWidths) { |
|
|
|
public void setFirstLineColWidths(List<String> firstLineColWidths) { |
|
|
|
this.firstColWidths = firstColWidths; |
|
|
|
this.firstLineColWidths = firstLineColWidths; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -389,7 +389,7 @@ public class PdfPTable implements LargeElement { |
|
|
|
private void adjustRowWidth() { |
|
|
|
private void adjustRowWidth() { |
|
|
|
for (int k = 0; k < rows.size(); ++k) { |
|
|
|
for (int k = 0; k < rows.size(); ++k) { |
|
|
|
PdfPRow row = (PdfPRow) rows.get(k); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(k); |
|
|
|
row.setWidths(absoluteWidths); |
|
|
|
row.setWidths(absoluteWidths, tableProperties); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -400,8 +400,10 @@ public class PdfPTable implements LargeElement { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private float calOutOfContentWidth() { |
|
|
|
private float calOutOfContentWidth() { |
|
|
|
int numCols = getNumberOfColumns(); |
|
|
|
int numCols = getNumberOfColumns(); |
|
|
|
float borderWidth = tableProperties.getBorderWidth(); |
|
|
|
float allCellspacingWidth = tableProperties.getCellspacing() * (numCols + 1); |
|
|
|
return tableProperties.getCellspacing() * (numCols + 1) + numCols * 2 * (borderWidth + tableProperties.getCellpadding()) + 2 * borderWidth; |
|
|
|
float allCellpaddingWidth = numCols * 2 * tableProperties.getCellpadding(); |
|
|
|
|
|
|
|
float allCellBorderWidth = (numCols + 1) * 2 * tableProperties.getBorderWidth(); |
|
|
|
|
|
|
|
return allCellspacingWidth + allCellpaddingWidth + allCellBorderWidth; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -429,7 +431,7 @@ public class PdfPTable implements LargeElement { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//第一行列宽
|
|
|
|
//第一行列宽
|
|
|
|
float[] colWidths = new float[firstColWidths.length]; |
|
|
|
float[] colWidths = new float[firstLineColWidths.size()]; |
|
|
|
//绝对宽度和
|
|
|
|
//绝对宽度和
|
|
|
|
float absWidthSum = 0; |
|
|
|
float absWidthSum = 0; |
|
|
|
//相对宽度和
|
|
|
|
//相对宽度和
|
|
|
@ -440,10 +442,11 @@ public class PdfPTable implements LargeElement { |
|
|
|
ArrayList<Integer> relIndex = new ArrayList<Integer>(); |
|
|
|
ArrayList<Integer> relIndex = new ArrayList<Integer>(); |
|
|
|
|
|
|
|
|
|
|
|
//初始化一下上述字段
|
|
|
|
//初始化一下上述字段
|
|
|
|
for (int i = 0; i < firstColWidths.length; i++) { |
|
|
|
for (int i = 0; i < firstLineColWidths.size(); i++) { |
|
|
|
float w = CSSUtils.parseFloat(firstColWidths[i]); |
|
|
|
String widthStr = firstLineColWidths.get(i); |
|
|
|
if (null != firstColWidths[i]) { |
|
|
|
float w = CSSUtils.parseFloat(widthStr); |
|
|
|
if (firstColWidths[i].endsWith("%")) { |
|
|
|
if (null != widthStr) { |
|
|
|
|
|
|
|
if (widthStr.endsWith("%")) { |
|
|
|
w = w / 100 * contentWidth; |
|
|
|
w = w / 100 * contentWidth; |
|
|
|
relWidthSum += w; |
|
|
|
relWidthSum += w; |
|
|
|
relIndex.add(i); |
|
|
|
relIndex.add(i); |
|
|
@ -591,7 +594,7 @@ public class PdfPTable implements LargeElement { |
|
|
|
} |
|
|
|
} |
|
|
|
float invalidColWidth = invalidColNum * tableProperties.getCellspacing() + 2 * invalidColNum * (tableProperties.getCellpadding() + tableProperties.getBorderWidth()); |
|
|
|
float invalidColWidth = invalidColNum * tableProperties.getCellspacing() + 2 * invalidColNum * (tableProperties.getCellpadding() + tableProperties.getBorderWidth()); |
|
|
|
float avgWidth = invalidColWidth / validIndexList.size(); |
|
|
|
float avgWidth = invalidColWidth / validIndexList.size(); |
|
|
|
for (int i = 0; i < validIndexList.size() && i < absoluteWidths.length; i++) { |
|
|
|
for (int i = 0; i < validIndexList.size() && validIndexList.get(i) < absoluteWidths.length; i++) { |
|
|
|
Integer index = validIndexList.get(i); |
|
|
|
Integer index = validIndexList.get(i); |
|
|
|
absoluteWidths[index] += avgWidth; |
|
|
|
absoluteWidths[index] += avgWidth; |
|
|
|
} |
|
|
|
} |
|
|
@ -604,7 +607,7 @@ public class PdfPTable implements LargeElement { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private boolean dealFirstLineHasNoWidth(float contentWidth) { |
|
|
|
private boolean dealFirstLineHasNoWidth(float contentWidth) { |
|
|
|
if (null != firstColWidths && 0 != firstColWidths.length) { |
|
|
|
if (null != firstLineColWidths && 0 != firstLineColWidths.size()) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
//第一行的td都没有设置width属性,则所有列平分table宽度
|
|
|
|
//第一行的td都没有设置width属性,则所有列平分table宽度
|
|
|
@ -747,7 +750,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, tableProperties); |
|
|
|
// totalHeight += row.getMaxHeights();
|
|
|
|
// totalHeight += row.getMaxHeights();
|
|
|
|
} |
|
|
|
} |
|
|
|
rows.add(row); |
|
|
|
rows.add(row); |
|
|
@ -1114,7 +1117,7 @@ public class PdfPTable implements LargeElement { |
|
|
|
if (row == null) |
|
|
|
if (row == null) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
if (firsttime) |
|
|
|
if (firsttime) |
|
|
|
row.setWidths(absoluteWidths); |
|
|
|
row.setWidths(absoluteWidths, tableProperties); |
|
|
|
float height = row.getMaxHeights(); |
|
|
|
float height = row.getMaxHeights(); |
|
|
|
PdfPCell cell; |
|
|
|
PdfPCell cell; |
|
|
|
PdfPRow tmprow; |
|
|
|
PdfPRow tmprow; |
|
|
|