|
|
@ -72,20 +72,20 @@ public class IncTable { |
|
|
|
public IncTable(HashMap props) { |
|
|
|
public IncTable(HashMap props) { |
|
|
|
this.props.putAll(props); |
|
|
|
this.props.putAll(props); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void addCol(PdfPCell cell) { |
|
|
|
public void addCol(PdfPCell cell) { |
|
|
|
if (cols == null) |
|
|
|
if (cols == null) |
|
|
|
cols = new ArrayList(); |
|
|
|
cols = new ArrayList(); |
|
|
|
cols.add(cell); |
|
|
|
cols.add(cell); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void addCols(ArrayList ncols) { |
|
|
|
public void addCols(ArrayList ncols) { |
|
|
|
if (cols == null) |
|
|
|
if (cols == null) |
|
|
|
cols = new ArrayList(ncols); |
|
|
|
cols = new ArrayList(ncols); |
|
|
|
else |
|
|
|
else |
|
|
|
cols.addAll(ncols); |
|
|
|
cols.addAll(ncols); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void endRow(float rowHeight) { |
|
|
|
public void endRow(float rowHeight) { |
|
|
|
rowHeights.add(rowHeight); |
|
|
|
rowHeights.add(rowHeight); |
|
|
|
if (cols != null) { |
|
|
|
if (cols != null) { |
|
|
@ -94,27 +94,35 @@ public class IncTable { |
|
|
|
cols = null; |
|
|
|
cols = null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ArrayList getRows() { |
|
|
|
public ArrayList getRows() { |
|
|
|
return rows; |
|
|
|
return rows; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public PdfPTable buildTable() { |
|
|
|
public PdfPTable buildTable() { |
|
|
|
if (rows.isEmpty()) |
|
|
|
if (rows.isEmpty()) |
|
|
|
return new PdfPTable(1); |
|
|
|
return new PdfPTable(1); |
|
|
|
int ncol = 0; |
|
|
|
int ncol = 0; |
|
|
|
ArrayList c0 = (ArrayList)rows.get(0); |
|
|
|
ArrayList c0 = (ArrayList)rows.get(0); |
|
|
|
ArrayList<Float> colWidths = new ArrayList<Float>(); |
|
|
|
ArrayList<Float> colWidths = new ArrayList<Float>(); |
|
|
|
|
|
|
|
float widthSum = 0; |
|
|
|
for (int k = 0; k < c0.size(); ++k) { |
|
|
|
for (int k = 0; k < c0.size(); ++k) { |
|
|
|
PdfPCell pCell = ((PdfPCell)c0.get(k)); |
|
|
|
PdfPCell pCell = ((PdfPCell)c0.get(k)); |
|
|
|
int cellCols = pCell.getColspan(); |
|
|
|
int cellCols = pCell.getColspan(); |
|
|
|
ncol += cellCols; |
|
|
|
ncol += cellCols; |
|
|
|
|
|
|
|
//不取 0 ,后面可能需要求比值
|
|
|
|
|
|
|
|
float styleWidth = pCell.getStyleWidth(); |
|
|
|
if(cellCols > 1){ |
|
|
|
if(cellCols > 1){ |
|
|
|
|
|
|
|
float avgWidth = styleWidth / cellCols; |
|
|
|
|
|
|
|
float width = 0 == avgWidth ? 1 : avgWidth; |
|
|
|
|
|
|
|
widthSum = width * cellCols; |
|
|
|
for(int a = 0; a < cellCols ; a++){ |
|
|
|
for(int a = 0; a < cellCols ; a++){ |
|
|
|
colWidths.add(pCell.getStyleWidth()/cellCols); |
|
|
|
colWidths.add(width); |
|
|
|
} |
|
|
|
} |
|
|
|
}else { |
|
|
|
}else { |
|
|
|
colWidths.add(pCell.getStyleWidth()); |
|
|
|
float width = 0 == styleWidth ? 1 : styleWidth; |
|
|
|
|
|
|
|
widthSum += width; |
|
|
|
|
|
|
|
colWidths.add(width); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -132,8 +140,8 @@ public class IncTable { |
|
|
|
//解析单元格宽度
|
|
|
|
//解析单元格宽度
|
|
|
|
float totalWidth = CSSUtils.parseFloat(width); |
|
|
|
float totalWidth = CSSUtils.parseFloat(width); |
|
|
|
float[] floats = new float[colWidths.size()]; |
|
|
|
float[] floats = new float[colWidths.size()]; |
|
|
|
for (int a = 0; a < colWidths.size(); a++){ |
|
|
|
for (int a = 0; a < colWidths.size(); a++) { |
|
|
|
floats[a] = colWidths.get(a); |
|
|
|
floats[a] = totalWidth * colWidths.get(a) / widthSum; |
|
|
|
} |
|
|
|
} |
|
|
|
//解析px数值
|
|
|
|
//解析px数值
|
|
|
|
table.setTotalWidth(totalWidth); |
|
|
|
table.setTotalWidth(totalWidth); |
|
|
@ -161,11 +169,11 @@ public class IncTable { |
|
|
|
return table; |
|
|
|
return table; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void processRowHeight(PdfPTable table){ |
|
|
|
public void processRowHeight(PdfPTable table) { |
|
|
|
Float height = CSSUtils.parseFloat((String)props.get("height")); |
|
|
|
Float height = CSSUtils.parseFloat((String) props.get("height")); |
|
|
|
Float eachHeight = height / table.getRows().size(); |
|
|
|
Float eachHeight = height / table.getRows().size(); |
|
|
|
//调整行高
|
|
|
|
//调整行高
|
|
|
|
for(int a = 0; a < rowHeights.size(); a++){ |
|
|
|
for (int a = 0; a < rowHeights.size(); a++) { |
|
|
|
table.getRow(a).setStyleHeight(Math.max(eachHeight, rowHeights.get(a))); |
|
|
|
table.getRow(a).setStyleHeight(Math.max(eachHeight, rowHeights.get(a))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|