Browse Source

REPORT-13464 [10.0.2回归]表单导出排版混乱,背景未导出

bugfix/10.0
kerry 6 years ago
parent
commit
d4323d8e43
  1. 4
      fine-itext/src/com/fr/third/v2/lowagie/text/html/CSSUtils.java
  2. 62
      fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/IncCell.java
  3. 16
      fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java

4
fine-itext/src/com/fr/third/v2/lowagie/text/html/CSSUtils.java

@ -94,7 +94,9 @@ public class CSSUtils {
try {
if(str.endsWith("px") || str.endsWith("pt")){
result = Float.parseFloat(str.substring(0, str.length() - 2));
}else{
}else if(str.endsWith("%")){
result = Float.parseFloat(str.substring(0, str.length() - 1));
}else {
result = Float.parseFloat(str);
}
}catch (NumberFormatException e){

62
fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/IncCell.java

@ -60,17 +60,18 @@ import com.fr.third.v2.lowagie.text.pdf.PdfPCell;
import com.fr.third.v2.lowagie.text.Phrase;
/**
*
* @author psoares
* @author psoares
*/
public class IncCell implements TextElementArray {
private ArrayList chunks = new ArrayList();
private PdfPCell cell;
/** Creates a new instance of IncCell */
/**
* Creates a new instance of IncCell
*/
public IncCell(String tag, ChainedProperties props) {
cell = new PdfPCell((Phrase)null);
cell = new PdfPCell((Phrase) null);
String value = props.getProperty("colspan");
if (value != null)
cell.setColspan(Integer.parseInt(value));
@ -104,43 +105,46 @@ public class IncCell implements TextElementArray {
if (value != null)
cell.setPadding(CSSUtils.parseFloat(value));
cell.setUseDescender(true);
value = props.getProperty("bgcolor");
cell.setBackgroundColor(Markup.decodeColor(value));
//解析td上声明的width
value = props.getLastChainProperty("width");
if(value != null){
if (value != null) {
cell.setStyleWidth(CSSUtils.parseFloat(value));
}
//解析td上声明的height
value = props.getLastChainProperty("height");
if(value != null){
if (value != null) {
cell.setStyleHeight(CSSUtils.parseFloat(value));
}
//解析background相关属性并保存到cell对象
Map<String, String> backgroundRules = new HashMap<String, String>();
value = props.getProperty("bgcolor");
if (value != null) {
backgroundRules.put("background-color", value);
}
value = props.getLastChainProperty("background-size");
if(value!=null){
if (value != null) {
backgroundRules.put("background-size", value);
}
value = props.getLastChainProperty("background");
if(value!=null){
if (value != null) {
Map<String, String> backgroundStyles = CSSUtils.processBackground(value);
backgroundRules.putAll(backgroundStyles);
}
value = props.getLastChainProperty("background-color");
if(value!=null){
if (value != null) {
backgroundRules.put("background-color", value);
}
value = props.getLastChainProperty("background-position");
if(value!=null){
if (value != null) {
backgroundRules.put("background-position", value);
}
value = props.getLastChainProperty("background-repeat");
if(value!=null){
if (value != null) {
backgroundRules.put("background-repeat", value);
}
value = props.getLastChainProperty("background-image");
if(value!=null){
if (value != null) {
backgroundRules.put("background-image", value);
}
cell.setBackground(backgroundRules);
@ -149,7 +153,7 @@ public class IncCell implements TextElementArray {
public boolean add(Object o) {
if (!(o instanceof Element))
return false;
cell.addElement((Element)o);
cell.addElement((Element) o);
return true;
}
@ -169,19 +173,19 @@ public class IncCell implements TextElementArray {
return cell;
}
/**
* @see Element#isContent()
* @since iText 2.0.8
*/
public boolean isContent() {
return true;
}
/**
* @since iText 2.0.8
* @see Element#isContent()
*/
public boolean isContent() {
return true;
}
/**
* @see Element#isNestable()
* @since iText 2.0.8
*/
public boolean isNestable() {
return true;
}
/**
* @since iText 2.0.8
* @see Element#isNestable()
*/
public boolean isNestable() {
return true;
}
}

16
fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java

@ -151,10 +151,9 @@ public class IncTable {
table.addCell((PdfPCell)col.get(k));
}
}
//调整行高
for(int a = 0; a < rowHeights.size(); a++){
table.getRow(a).setStyleHeight(rowHeights.get(a));
}
processRowHeight(table);
}catch (Exception e){
e.printStackTrace();
@ -162,6 +161,15 @@ public class IncTable {
return table;
}
public void processRowHeight(PdfPTable table){
Float height = CSSUtils.parseFloat((String)props.get("height"));
Float eachHeight = height / table.getRows().size();
//调整行高
for(int a = 0; a < rowHeights.size(); a++){
table.getRow(a).setStyleHeight(Math.max(eachHeight, rowHeights.get(a)));
}
}
public TableProperties parseTableProperties(){
TableProperties tableProperties = new TableProperties();
BorderStyle borderStyle = new BorderStyle();

Loading…
Cancel
Save