|
|
|
@ -50,6 +50,7 @@ package com.fr.third.v2.lowagie.text.html.simpleparser;
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
import com.fr.third.v2.lowagie.text.html.CSSUtils; |
|
|
|
|
import com.fr.third.v2.lowagie.text.html.Markup; |
|
|
|
@ -66,6 +67,7 @@ public class IncTable {
|
|
|
|
|
private HashMap props = new HashMap(); |
|
|
|
|
private ArrayList rows = new ArrayList(); |
|
|
|
|
private ArrayList cols; |
|
|
|
|
private List<Integer> rowIndex4ZeroHeight = new ArrayList(); |
|
|
|
|
|
|
|
|
|
private ArrayList<Float> rowHeights = new ArrayList<Float>(); |
|
|
|
|
private ArrayList<Float> relativeColWidths = new ArrayList<Float>(); |
|
|
|
@ -88,6 +90,9 @@ public class IncTable {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void endRow(float rowHeight) { |
|
|
|
|
if (rowHeight == 0) { |
|
|
|
|
rowIndex4ZeroHeight.add(rowHeights.size()); |
|
|
|
|
} |
|
|
|
|
rowHeights.add(rowHeight); |
|
|
|
|
if (cols != null) { |
|
|
|
|
Collections.reverse(cols); |
|
|
|
@ -204,12 +209,53 @@ public class IncTable {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void processRowHeight(PdfPTable table) { |
|
|
|
|
Float height = CSSUtils.parseFloat((String) props.get("height")); |
|
|
|
|
Float eachHeight = height / table.getRows().size(); |
|
|
|
|
adjustRowHeight(CSSUtils.parseFloat((String) props.get("height"))); |
|
|
|
|
//调整行高
|
|
|
|
|
for (int a = 0; a < rowHeights.size(); a++) { |
|
|
|
|
table.getRow(a).setStyleHeight(Math.max(eachHeight, rowHeights.get(a))); |
|
|
|
|
for (int i = 0; i < rowHeights.size(); i++) { |
|
|
|
|
table.getRow(i).setStyleHeight(rowHeights.get(i)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 调整行高 |
|
|
|
|
* 1、若 tableHeight < rowHeightSum , return ,每行扔取取指定的 height (该行的最大值) |
|
|
|
|
* 2、若 tableHeight > rowHeightSum ,每行都有指定 height (该行的最大值),则按比例平分tableHeight |
|
|
|
|
* 3、若 tableHeight > rowHeightSum ,有些行没有指定 height ,则将tableHeight - rowHeightSum ,平分给这些行 |
|
|
|
|
* 最后,若计算出的内容高度大于上述计算出的行高,则取内容高度 |
|
|
|
|
* |
|
|
|
|
* @param tableHeight |
|
|
|
|
*/ |
|
|
|
|
private void adjustRowHeight(Float tableHeight) { |
|
|
|
|
if (0 > tableHeight) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
float totalHeight = getRowHeightSum(); |
|
|
|
|
if (tableHeight < totalHeight) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
float extraHeight = tableHeight - totalHeight; |
|
|
|
|
int size = rowIndex4ZeroHeight.size(); |
|
|
|
|
//多出来的高度平分给没有设置高度的行
|
|
|
|
|
if (size > 0) { |
|
|
|
|
float eachHeight = extraHeight / size; |
|
|
|
|
for (int i = 0; i < size; i++) { |
|
|
|
|
rowHeights.set(rowIndex4ZeroHeight.get(i), eachHeight); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//按比例分
|
|
|
|
|
else { |
|
|
|
|
for (int i = 0; i < rowHeights.size(); i++) { |
|
|
|
|
rowHeights.set(i, tableHeight * rowHeights.get(i) / totalHeight); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private float getRowHeightSum() { |
|
|
|
|
float sum = 0; |
|
|
|
|
for (int i = 0; i < rowHeights.size(); i++) { |
|
|
|
|
sum += rowHeights.get(i); |
|
|
|
|
} |
|
|
|
|
return sum; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public TableProperties parseTableProperties(){ |
|
|
|
|