Browse Source

research/11.0
kerry 6 years ago
parent
commit
f8c3aeed1d
  1. 1
      fine-itext/src/com/fr/third/v2/lowagie/text/html/CSS.java
  2. 14
      fine-itext/src/com/fr/third/v2/lowagie/text/html/CSSUtils.java
  3. 80
      fine-itext/src/com/fr/third/v2/lowagie/text/html/SpaceWithPunctuationBreakIterator.java
  4. 6
      fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/ChainedProperties.java
  5. 10
      fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java
  6. 45
      fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/IncCell.java
  7. 76
      fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java
  8. 58
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/BorderStyle.java
  9. 12
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfBlock.java
  10. 83
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java
  11. 34
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfPCell.java
  12. 30
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfPRow.java
  13. 138
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java
  14. 52
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/TableProperties.java

1
fine-itext/src/com/fr/third/v2/lowagie/text/html/CSS.java

@ -109,6 +109,7 @@ public class CSS{
public static final String BACKGROUND_ATTACHMENT = "background-attachment"; public static final String BACKGROUND_ATTACHMENT = "background-attachment";
public static final String BACKGROUND_POSITION = "background-position"; public static final String BACKGROUND_POSITION = "background-position";
public static final String BACKGROUND_COLOR = "background-color"; public static final String BACKGROUND_COLOR = "background-color";
public static final String BACKGROUND_SIZE = "background-size";
public static final String LIST_STYLE = "list-style"; public static final String LIST_STYLE = "list-style";
public static final String LIST_STYLE_TYPE = "list-style-type"; public static final String LIST_STYLE_TYPE = "list-style-type";
public static final String LIST_STYLE_POSITION = "list-style-position"; public static final String LIST_STYLE_POSITION = "list-style-position";

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

@ -88,4 +88,18 @@ public class CSSUtils {
} }
return str; return str;
} }
public static Float parseFloat(String str){
float result = 0.0f;
try {
if(str.endsWith("px") || str.endsWith("pt")){
result = Float.parseFloat(str.substring(0, str.length() - 2));
}else{
result = Float.parseFloat(str);
}
}catch (NumberFormatException e){
}
return result;
}
} }

80
fine-itext/src/com/fr/third/v2/lowagie/text/html/SpaceWithPunctuationBreakIterator.java

@ -0,0 +1,80 @@
package com.fr.third.v2.lowagie.text.html;
import com.fr.third.ibm.icu.text.BreakIterator;
import java.text.CharacterIterator;
/**
* 之前性能插件里面的考虑空格和标点符号的分词iterator
*/
public class SpaceWithPunctuationBreakIterator extends BreakIterator {
private BreakIterator iterator;
private int currentPos = -1;
private int currentIndex = -1;
private boolean[] spaceIndex;
public SpaceWithPunctuationBreakIterator(String text, BreakIterator iterator){
this.iterator = iterator;
iterator.setText(text);
this.spaceIndex = new boolean[text.length()];
int ilen = text.length() - 1;
if(ilen > 0) {
for (int i = 0; i < ilen; i++) {
char c = text.charAt(i);
spaceIndex[i + 1] = (c == ' ' && isPunctuation(text.charAt(i + 1)) )|| c == '-' || c == '\u2010' || c== '\n';
}
}
}
public boolean isPunctuation(char c) {
int code = Character.getType(c);
return code == 24 || code == 20 || code == 21 || code == 22 || code == 23;
}
public int first() {
throw new UnsupportedOperationException();
}
public int last() {
throw new UnsupportedOperationException();
}
public int next(int n) {
throw new UnsupportedOperationException();
}
public int next() {
if(currentIndex == currentPos) {
currentPos = this.iterator.next();
}
for(int i = currentIndex + 1; i < currentPos; i++){
if(spaceIndex[i]){
currentIndex = i;
return currentIndex;
}
}
currentIndex = currentPos;
return currentIndex;
}
public int previous() {
throw new UnsupportedOperationException();
}
public int following(int offset) {
throw new UnsupportedOperationException();
}
public int current() {
throw new UnsupportedOperationException();
}
public CharacterIterator getText() {
throw new UnsupportedOperationException();
}
public void setText(CharacterIterator newText) {
throw new UnsupportedOperationException();
}
}

6
fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/ChainedProperties.java

@ -76,6 +76,12 @@ public class ChainedProperties {
return null; return null;
} }
public String getLastChainProperty(String key){
Object obj[] = (Object[]) chain.get(chain.size()-1);
HashMap prop = (HashMap) obj[1];
return (String) prop.get(key);
}
public boolean hasProperty(String key) { public boolean hasProperty(String key) {
for (int k = chain.size() - 1; k >= 0; --k) { for (int k = chain.size() - 1; k >= 0; --k) {
Object obj[] = (Object[]) chain.get(k); Object obj[] = (Object[]) chain.get(k);

10
fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java

@ -72,6 +72,7 @@ import com.fr.third.v2.lowagie.text.List;
import com.fr.third.v2.lowagie.text.ListItem; import com.fr.third.v2.lowagie.text.ListItem;
import com.fr.third.v2.lowagie.text.Rectangle; import com.fr.third.v2.lowagie.text.Rectangle;
import com.fr.third.v2.lowagie.text.TextElementArray; import com.fr.third.v2.lowagie.text.TextElementArray;
import com.fr.third.v2.lowagie.text.html.CSSUtils;
import com.fr.third.v2.lowagie.text.html.HtmlTags; import com.fr.third.v2.lowagie.text.html.HtmlTags;
import com.fr.third.v2.lowagie.text.pdf.draw.LineSeparator; import com.fr.third.v2.lowagie.text.pdf.draw.LineSeparator;
import com.fr.third.v2.lowagie.text.xml.simpleparser.SimpleXMLDocHandler; import com.fr.third.v2.lowagie.text.xml.simpleparser.SimpleXMLDocHandler;
@ -648,6 +649,8 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
if (pendingTD) if (pendingTD)
endElement("td"); endElement("td");
pendingTR = false; pendingTR = false;
String rowHeightPx = cprops.getLastChainProperty("height");
cprops.removeChain("tr"); cprops.removeChain("tr");
ArrayList cells = new ArrayList(); ArrayList cells = new ArrayList();
IncTable table = null; IncTable table = null;
@ -661,8 +664,13 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
break; break;
} }
} }
float rowHeight = 0.0f;
if(rowHeightPx!=null){
rowHeight = CSSUtils.parseFloat(rowHeightPx);
}
table.addCols(cells); table.addCols(cells);
table.endRow(); table.endRow(rowHeight);
stack.push(table); stack.push(table);
skipText = true; skipText = true;
return; return;

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

@ -48,10 +48,13 @@
package com.fr.third.v2.lowagie.text.html.simpleparser; package com.fr.third.v2.lowagie.text.html.simpleparser;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import com.fr.third.v2.lowagie.text.Element; import com.fr.third.v2.lowagie.text.Element;
import com.fr.third.v2.lowagie.text.ElementListener; import com.fr.third.v2.lowagie.text.ElementListener;
import com.fr.third.v2.lowagie.text.TextElementArray; import com.fr.third.v2.lowagie.text.TextElementArray;
import com.fr.third.v2.lowagie.text.html.CSSUtils;
import com.fr.third.v2.lowagie.text.html.Markup; import com.fr.third.v2.lowagie.text.html.Markup;
import com.fr.third.v2.lowagie.text.pdf.PdfPCell; import com.fr.third.v2.lowagie.text.pdf.PdfPCell;
import com.fr.third.v2.lowagie.text.Phrase; import com.fr.third.v2.lowagie.text.Phrase;
@ -95,14 +98,52 @@ public class IncCell implements TextElementArray {
value = props.getProperty("border"); value = props.getProperty("border");
float border = 0; float border = 0;
if (value != null) if (value != null)
border = Float.parseFloat(value); border = CSSUtils.parseFloat(value);
cell.setBorderWidth(border); cell.setBorderWidth(border);
value = props.getProperty("cellpadding"); value = props.getProperty("cellpadding");
if (value != null) if (value != null)
cell.setPadding(Float.parseFloat(value)); cell.setPadding(CSSUtils.parseFloat(value));
cell.setUseDescender(true); cell.setUseDescender(true);
value = props.getProperty("bgcolor"); value = props.getProperty("bgcolor");
cell.setBackgroundColor(Markup.decodeColor(value)); cell.setBackgroundColor(Markup.decodeColor(value));
//解析td上声明的width
value = props.getLastChainProperty("width");
if(value != null){
cell.setStyleWidth(CSSUtils.parseFloat(value));
}
//解析td上声明的height
value = props.getLastChainProperty("height");
if(value != null){
cell.setStyleHeight(CSSUtils.parseFloat(value));
}
//解析background相关属性并保存到cell对象
Map<String, String> backgroundRules = new HashMap<String, String>();
value = props.getLastChainProperty("background-size");
if(value!=null){
backgroundRules.put("background-size", value);
}
value = props.getLastChainProperty("background");
if(value!=null){
Map<String, String> backgroundStyles = CSSUtils.processBackground(value);
backgroundRules.putAll(backgroundStyles);
}
value = props.getLastChainProperty("background-color");
if(value!=null){
backgroundRules.put("background-color", value);
}
value = props.getLastChainProperty("background-position");
if(value!=null){
backgroundRules.put("background-position", value);
}
value = props.getLastChainProperty("background-repeat");
if(value!=null){
backgroundRules.put("background-repeat", value);
}
value = props.getLastChainProperty("background-image");
if(value!=null){
backgroundRules.put("background-image", value);
}
cell.setBackground(backgroundRules);
} }
public boolean add(Object o) { public boolean add(Object o) {

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

@ -51,8 +51,12 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import com.fr.third.v2.lowagie.text.html.CSSUtils;
import com.fr.third.v2.lowagie.text.html.Markup;
import com.fr.third.v2.lowagie.text.pdf.BorderStyle;
import com.fr.third.v2.lowagie.text.pdf.PdfPTable; import com.fr.third.v2.lowagie.text.pdf.PdfPTable;
import com.fr.third.v2.lowagie.text.pdf.PdfPCell; import com.fr.third.v2.lowagie.text.pdf.PdfPCell;
import com.fr.third.v2.lowagie.text.pdf.TableProperties;
/** /**
* *
@ -62,6 +66,8 @@ public class IncTable {
private HashMap props = new HashMap(); private HashMap props = new HashMap();
private ArrayList rows = new ArrayList(); private ArrayList rows = new ArrayList();
private ArrayList cols; private ArrayList cols;
private ArrayList<Float> rowHeights = new ArrayList<Float>();
/** Creates a new instance of IncTable */ /** Creates a new instance of IncTable */
public IncTable(HashMap props) { public IncTable(HashMap props) {
this.props.putAll(props); this.props.putAll(props);
@ -80,7 +86,8 @@ public class IncTable {
cols.addAll(ncols); cols.addAll(ncols);
} }
public void endRow() { public void endRow(float rowHeight) {
rowHeights.add(rowHeight);
if (cols != null) { if (cols != null) {
Collections.reverse(cols); Collections.reverse(cols);
rows.add(cols); rows.add(cols);
@ -97,18 +104,44 @@ public class IncTable {
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>();
for (int k = 0; k < c0.size(); ++k) { for (int k = 0; k < c0.size(); ++k) {
ncol += ((PdfPCell)c0.get(k)).getColspan(); PdfPCell pCell = ((PdfPCell)c0.get(k));
int cellCols = pCell.getColspan();
ncol += cellCols;
if(cellCols > 1){
for(int a = 0; a < cellCols ; a++){
colWidths.add(pCell.getStyleWidth()/cellCols);
}
}else {
colWidths.add(pCell.getStyleWidth());
} }
}
PdfPTable table = new PdfPTable(ncol); PdfPTable table = new PdfPTable(ncol);
try {
TableProperties tableProperties = parseTableProperties();
table.setTableProperties(tableProperties);
String width = (String)props.get("width"); String width = (String)props.get("width");
if (width == null) if (width == null)
table.setWidthPercentage(100); table.setWidthPercentage(100);
else { else {
if (width.endsWith("%")) if (width.endsWith("%"))
table.setWidthPercentage(Float.parseFloat(width.substring(0, width.length() - 1))); table.setWidthPercentage(CSSUtils.parseFloat(width));
else { else {
table.setTotalWidth(Float.parseFloat(width)); //解析单元格宽度
float totalWidth = CSSUtils.parseFloat(width);
float[] floats = new float[colWidths.size()];
for (int a = 0; a < colWidths.size(); a++){
floats[a] = colWidths.get(a);
}
//解析px数值
table.setTotalWidth(totalWidth);
try {
table.setWidths(floats);
}catch (Exception e){
e.printStackTrace();
}
table.setLockedWidth(true); table.setLockedWidth(true);
} }
} }
@ -118,6 +151,41 @@ public class IncTable {
table.addCell((PdfPCell)col.get(k)); table.addCell((PdfPCell)col.get(k));
} }
} }
//调整行高
for(int a = 0; a < rowHeights.size(); a++){
table.getRow(a).setStyleHeight(rowHeights.get(a));
}
}catch (Exception e){
e.printStackTrace();
}
return table; return table;
} }
public TableProperties parseTableProperties(){
TableProperties tableProperties = new TableProperties();
BorderStyle borderStyle = new BorderStyle();
tableProperties.setBorderStyle(borderStyle);
String value = (String)props.get("border");
if(value != null){
borderStyle.setBorderWidth(CSSUtils.parseFloat(value));
}
value = (String)props.get("border-color");
if(value != null){
borderStyle.setBorderColor(Markup.decodeColor(value));
}
value = (String)props.get("border-collapse");
if(value != null){
tableProperties.setCollapse(value.equals("collapse"));
}
value = (String)props.get("cellspacing");
if(value != null){
tableProperties.setCellspacing(CSSUtils.parseFloat(value));
}
value = (String)props.get("cellpadding");
if(value != null){
tableProperties.setCellpadding(CSSUtils.parseFloat(value));
}
return tableProperties;
}
} }

58
fine-itext/src/com/fr/third/v2/lowagie/text/pdf/BorderStyle.java

@ -0,0 +1,58 @@
package com.fr.third.v2.lowagie.text.pdf;
import com.fr.third.v2.lowagie.text.DocumentException;
import com.fr.third.v2.lowagie.text.html.CSSUtils;
import com.fr.third.v2.lowagie.text.html.Markup;
import java.awt.Color;
public class BorderStyle {
private float borderWidth = 0.0f;
private Color borderColor = Color.black;
private String borderPattern = "solid";
public float getBorderWidth() {
return borderWidth;
}
public void setBorderWidth(float borderWidth) {
this.borderWidth = borderWidth;
}
public Color getBorderColor() {
return borderColor;
}
public void setBorderColor(Color borderColor) {
this.borderColor = borderColor;
}
public String getBorderPattern() {
return borderPattern;
}
public void setBorderPattern(String borderPattern) {
this.borderPattern = borderPattern;
}
public BorderStyle() {
}
public BorderStyle(int borderWidth, String borderPattern, Color borderColor) {
this.borderWidth = borderWidth;
this.borderPattern = borderPattern;
this.borderWidth = borderWidth;
}
public static BorderStyle parseBorderStyle(String borderString) throws DocumentException {
BorderStyle borderStyle = new BorderStyle();
String[] borderPros = borderString.split(" ");
borderStyle.setBorderWidth(CSSUtils.parseFloat(borderPros[0]));
borderStyle.setBorderPattern(borderPros[1]);
borderStyle.setBorderColor(Markup.decodeColor(borderPros[2]));
return borderStyle;
}
}

12
fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfBlock.java

@ -1,12 +0,0 @@
package com.fr.third.v2.lowagie.text.pdf;
/**
* @author kerry
* @date 2018/8/10
*/
public interface PdfBlock {
float getHeight();
void calculateHeight();
String toHtmlString(double startY, double endY);
}

83
fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java

@ -53,8 +53,10 @@ import java.awt.Color;
import java.awt.FontMetrics; import java.awt.FontMetrics;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import com.fr.third.ibm.icu.text.BreakIterator;
import com.fr.third.v2.lowagie.text.SplitCharacter; import com.fr.third.v2.lowagie.text.SplitCharacter;
import com.fr.third.v2.lowagie.text.Utilities; import com.fr.third.v2.lowagie.text.Utilities;
import com.fr.third.v2.lowagie.text.Chunk; import com.fr.third.v2.lowagie.text.Chunk;
@ -62,6 +64,7 @@ import com.fr.third.v2.lowagie.text.Font;
import com.fr.third.v2.lowagie.text.Image; import com.fr.third.v2.lowagie.text.Image;
import com.fr.third.v2.lowagie.text.html.IndentAttribute; import com.fr.third.v2.lowagie.text.html.IndentAttribute;
import com.fr.third.v2.lowagie.text.html.ParseIndentAttrUtils; import com.fr.third.v2.lowagie.text.html.ParseIndentAttrUtils;
import com.fr.third.v2.lowagie.text.html.SpaceWithPunctuationBreakIterator;
import sun.font.FontDesignMetrics; import sun.font.FontDesignMetrics;
/** /**
@ -100,6 +103,17 @@ public class PdfChunk {
private IndentAttribute indent = new IndentAttribute(); private IndentAttribute indent = new IndentAttribute();
public Map<String, String> background ;
public Map<String, String> getBackground() {
return background;
}
public void setBackground(Map<String, String> background) {
this.background = background;
}
static { static {
keysAttributes.put(Chunk.ACTION, null); keysAttributes.put(Chunk.ACTION, null);
keysAttributes.put(Chunk.UNDERLINE, null); keysAttributes.put(Chunk.UNDERLINE, null);
@ -330,24 +344,26 @@ public class PdfChunk {
image = null; image = null;
font = PdfFont.getDefaultFont(); font = PdfFont.getDefaultFont();
return pc; return pc;
} } else
else
return null; return null;
} }
HyphenationEvent hyphenationEvent = (HyphenationEvent)noStroke.get(Chunk.HYPHENATION);
int currentPosition = 0; int currentPosition = 0;
int splitPosition = -1; int start = 0;
float currentWidth = indent.getLeft(); float currentWidth = indent.getLeft();
// loop over all the characters of a string // loop over all the characters of a string
// or until the totalWidth is reached // or until the totalWidth is reached
int lastSpace = -1;
float lastSpaceWidth = 0;
int length = value.length(); int length = value.length();
char valueArray[] = value.toCharArray(); char valueArray[] = value.toCharArray();
BreakIterator iterator = BreakIterator.getLineInstance(Locale.getDefault());
BreakIterator iterator1 = new SpaceWithPunctuationBreakIterator(value, iterator);
char character = 0; char character = 0;
boolean surrogate = false;
while (currentPosition < length) { while (currentPosition < length) {
int next = iterator1.next();
if(next < 1){
break;
}
currentPosition = next - 1;
// the width of every character is added to the currentWidth // the width of every character is added to the currentWidth
character = valueArray[currentPosition]; character = valueArray[currentPosition];
// if a newLine or carriageReturn is encountered // if a newLine or carriageReturn is encountered
@ -361,53 +377,24 @@ public class PdfChunk {
PdfChunk pc = new PdfChunk(returnValue, this); PdfChunk pc = new PdfChunk(returnValue, this);
return pc; return pc;
} }
surrogate = Utilities.isSurrogatePair(valueArray, currentPosition); String substring = value.substring(start, next);
if (surrogate) currentWidth += font.width(substring);
currentWidth += font.width(Utilities.convertToUtf32(valueArray[currentPosition], valueArray[currentPosition + 1])); if (currentWidth + indent.getRight() > width){
else currentPosition = start - 1;
currentWidth += font.width(character);
if (character == ' ') {
lastSpace = currentPosition + 1;
lastSpaceWidth = currentWidth;
}
if (surrogate)
currentPosition++;
if (currentWidth + indent.getRight()> width)
break; break;
// if a split-character is encountered, the splitPosition is altered }
if (splitCharacter.isSplitCharacter(0, currentPosition, length, valueArray, null))
splitPosition = currentPosition + 1; start = next;
currentPosition++;
} }
// if all the characters fit in the total width, null is returned (there is no overflow) // if all the characters fit in the total width, null is returned (there is no overflow)
if (currentPosition == length) { if (currentPosition == length-1) {
return null; return null;
} }
// otherwise, the string has to be truncated // otherwise, the string has to be truncated
if (splitPosition < 0) { String returnValue = value.substring(start);
String returnValue = value; value = trim(value.substring(0, start));
value = "";
PdfChunk pc = new PdfChunk(returnValue, this);
return pc;
}
if (lastSpace > splitPosition && splitCharacter.isSplitCharacter(0, 0, 1, singleSpace, null))
splitPosition = lastSpace;
if (hyphenationEvent != null && lastSpace >= 0 && lastSpace < currentPosition) {
int wordIdx = getWord(value, lastSpace);
if (wordIdx > lastSpace) {
String pre = hyphenationEvent.getHyphenatedWordPre(value.substring(lastSpace, wordIdx), font.getFont(), font.size(), width - lastSpaceWidth);
String post = hyphenationEvent.getHyphenatedWordPost();
if (pre.length() > 0) {
String returnValue = post + value.substring(wordIdx);
value = trim(value.substring(0, lastSpace) + pre);
PdfChunk pc = new PdfChunk(returnValue, this);
return pc;
}
}
}
String returnValue = value.substring(splitPosition);
value = trim(value.substring(0, splitPosition));
PdfChunk pc = new PdfChunk(returnValue, this); PdfChunk pc = new PdfChunk(returnValue, this);
return pc; return pc;
} }
@ -808,7 +795,7 @@ public class PdfChunk {
} }
//todo 需要添加其他样式属性 //todo 需要添加其他样式属性
htmlString.append("<span style='"); htmlString.append("<span style='");
htmlString.append("").append(getStyleAttributes()).append("'"); htmlString.append(getStyleAttributes()).append("'");
htmlString.append(">"); htmlString.append(">");
htmlString.append(value); htmlString.append(value);
htmlString.append("</span>"); htmlString.append("</span>");

34
fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfPCell.java

@ -50,6 +50,7 @@
package com.fr.third.v2.lowagie.text.pdf; package com.fr.third.v2.lowagie.text.pdf;
import java.util.List; import java.util.List;
import java.util.Map;
import com.fr.Container; import com.fr.Container;
import com.fr.third.v2.lowagie.text.Chunk; import com.fr.third.v2.lowagie.text.Chunk;
@ -67,6 +68,36 @@ import com.fr.third.v2.lowagie.text.Phrase;
public class PdfPCell extends Rectangle { public class PdfPCell extends Rectangle {
private float styleWidth = 0.0f;
private float styleHeight = 0.0f;
public float getStyleHeight() {
return styleHeight;
}
public void setStyleHeight(float styleHeight) {
this.styleHeight = styleHeight;
}
public float getStyleWidth() {
return styleWidth;
}
public Map<String, String> background ;
public Map<String, String> getBackground() {
return background;
}
public void setBackground(Map<String, String> background) {
this.background = background;
}
public void setStyleWidth(float styleWidth) {
this.styleWidth = styleWidth;
}
private ColumnText column = new ColumnText(null); private ColumnText column = new ColumnText(null);
/** Vertical alignment of the cell. */ /** Vertical alignment of the cell. */
@ -257,6 +288,9 @@ public class PdfPCell extends Rectangle {
column = ColumnText.duplicate(cell.column); column = ColumnText.duplicate(cell.column);
useBorderPadding = cell.useBorderPadding; useBorderPadding = cell.useBorderPadding;
rotation = cell.rotation; rotation = cell.rotation;
background = cell.background;
styleWidth = cell.styleWidth;
styleHeight = cell.styleHeight;
} }
/** /**

30
fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfPRow.java

@ -76,6 +76,16 @@ public class PdfPRow {
protected float widths[]; protected float widths[];
private float styleHeight;
public float getStyleHeight() {
return styleHeight;
}
public void setStyleHeight(float styleHeight) {
this.styleHeight = styleHeight;
}
/** /**
* extra heights that needs to be added to a cell because of rowspans. * extra heights that needs to be added to a cell because of rowspans.
* @since 2.1.6 * @since 2.1.6
@ -186,31 +196,15 @@ public class PdfPRow {
continue; continue;
} }
else { else {
height = cell.getMaxHeight(); height = cell.getStyleHeight() == 0 ? cell.getContainer().getHeight() : cell.getStyleHeight();
if ((height > maxHeight) && (cell.getRowspan() == 1)) if ((height > maxHeight) && (cell.getRowspan() == 1))
maxHeight = height; maxHeight = height;
} }
} }
calculated = true; calculated = true;
return maxHeight; return maxHeight = Math.max(styleHeight, maxHeight);
} }
public float getMaxHeight2(){
float aMaxHeight = 0.0f;
for (int k = 0; k < cells.length; ++k) {
PdfPCell cell = cells[k];
float height = 0;
if (cell == null) {
continue;
}
else {
height = cell.getContainer().getHeight();
if ((height > aMaxHeight) && (cell.getRowspan() == 1))
aMaxHeight = height;
}
}
return aMaxHeight;
}
/** /**
* Writes the border and background of one cell in the row. * Writes the border and background of one cell in the row.

138
fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java

@ -65,13 +65,14 @@ import com.fr.third.v2.lowagie.text.pdf.events.PdfPTableEventForwarder;
* 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, PdfBlock { public class PdfPTable implements LargeElement {
/** /**
* The index of the original <CODE>PdfcontentByte</CODE>. * The index of the original <CODE>PdfcontentByte</CODE>.
@ -97,11 +98,20 @@ public class PdfPTable implements LargeElement, PdfBlock {
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.
@ -124,6 +134,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
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;
@ -187,6 +198,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
/** /**
* 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;
@ -242,7 +254,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
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);
@ -295,6 +307,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
horizontalAlignment = sourceTable.horizontalAlignment; horizontalAlignment = sourceTable.horizontalAlignment;
keepTogether = sourceTable.keepTogether; keepTogether = sourceTable.keepTogether;
complete = sourceTable.complete; complete = sourceTable.complete;
tableProperties = sourceTable.tableProperties;
} }
/** /**
@ -312,7 +325,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
absoluteWidths = new float[relativeWidths.length]; absoluteWidths = new float[relativeWidths.length];
totalHeight = 0; totalHeight = 0;
calculateWidths(); calculateWidths();
calculateHeights(true); // calculateHeights(true);
} }
/** /**
@ -337,10 +350,12 @@ public class PdfPTable implements LargeElement, PdfBlock {
return; return;
float total = 0; float total = 0;
int numCols = getNumberOfColumns(); int numCols = getNumberOfColumns();
float cellSpacings = tableProperties.isCollapse() ? 0 : tableProperties.getCellspacing();
float borderWidth = tableProperties.getBorderStyle().getBorderWidth();
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-(cellSpacings+ borderWidth)*(numCols+1)) * relativeWidths[k] / total;
} }
/** /**
@ -354,7 +369,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
this.totalWidth = totalWidth; this.totalWidth = totalWidth;
totalHeight = 0; totalHeight = 0;
calculateWidths(); calculateWidths();
calculateHeights(true); // calculateHeights(true);
} }
/** /**
@ -414,9 +429,13 @@ public class PdfPTable implements LargeElement, PdfBlock {
if (totalWidth <= 0) if (totalWidth <= 0)
return 0; return 0;
totalHeight = 0; totalHeight = 0;
BorderStyle borderStyle = tableProperties.getBorderStyle();
float borderWidth = borderStyle.getBorderWidth();
float cellspacing = tableProperties.getCellspacing();
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 += (borderWidth + cellspacing) * (rows.size() + 1);
return totalHeight; return totalHeight;
} }
@ -486,7 +505,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
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];
@ -503,6 +522,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
/** /**
* 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() {
@ -515,6 +535,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
/** /**
* 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
@ -528,34 +549,34 @@ public class PdfPTable implements LargeElement, PdfBlock {
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;
@ -669,7 +690,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
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();
@ -680,7 +701,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
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();
@ -834,6 +855,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
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.
* *
@ -845,7 +867,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
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)
@ -854,13 +876,13 @@ public class PdfPTable implements LargeElement, PdfBlock {
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];
float tmp = 0; float tmp = 0;
if (cell.getRowspan() == rs + 1) { if (cell.getRowspan() == rs + 1) {
@ -881,15 +903,15 @@ public class PdfPTable implements LargeElement, PdfBlock {
* 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];
@ -912,7 +934,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
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();
} }
@ -931,7 +953,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
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();
} }
@ -948,7 +970,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
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();
} }
@ -1034,16 +1056,16 @@ public class PdfPTable implements LargeElement, PdfBlock {
} }
/** /**
* @see 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 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;
@ -1059,8 +1081,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
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;
} }
} }
@ -1111,7 +1132,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
* @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);
} }
/** /**
@ -1125,6 +1146,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
/** /**
* 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
@ -1173,6 +1195,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
/** /**
* 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
@ -1196,7 +1219,9 @@ public class PdfPTable implements LargeElement, PdfBlock {
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) {
@ -1205,7 +1230,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
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);
@ -1232,7 +1257,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
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);
@ -1242,7 +1267,7 @@ public class PdfPTable implements LargeElement, PdfBlock {
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
@ -1250,14 +1275,13 @@ public class PdfPTable implements LargeElement, PdfBlock {
} }
} }
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;
@ -1560,41 +1584,5 @@ public class PdfPTable implements LargeElement, PdfBlock {
this.complete = complete; this.complete = complete;
} }
@Override
public float getHeight() {
return getTotalHeight();
}
@Override
public void calculateHeight() {
}
@Override
public String toHtmlString(double startY, double endY) {
StringBuffer a = new StringBuffer();
float currentHeight = 0.0f;
a.append("<table>");
for(Object r : rows){
PdfPRow row = (PdfPRow) r;
if(currentHeight>=startY && currentHeight+ row.getMaxHeights() <= endY){
a.append("<tr>");
for(PdfPCell cell : row.getCells()){
a.append(cell.getContainer().getHtmlContent(0, cell.getHeight()));
}
a.append("</tr>");
}
currentHeight+=row.getMaxHeights();
//
// if(currentHeight <= y && currentHeight + row.getMaxHeights() >x){
//
// }else{
// break;
// }
}
a.append("</table>");
return a.toString();
}
} }

52
fine-itext/src/com/fr/third/v2/lowagie/text/pdf/TableProperties.java

@ -0,0 +1,52 @@
package com.fr.third.v2.lowagie.text.pdf;
/**
* 描述table的属性类
* 包括cellspacingcellpaddingborder等
*/
public class TableProperties {
private BorderStyle borderStyle = new BorderStyle();
private float cellspacing = 2.0f;
private float cellpadding = 1.0f;
private boolean collapse = false;
public BorderStyle getBorderStyle() {
return borderStyle;
}
public void setBorderStyle(BorderStyle borderStyle) {
this.borderStyle = borderStyle;
}
public float getCellspacing() {
return cellspacing;
}
public void setCellspacing(float cellspacing) {
this.cellspacing = cellspacing;
}
public float getCellpadding() {
return cellpadding;
}
public void setCellpadding(float cellpadding) {
this.cellpadding = cellpadding;
}
public boolean isCollapse() {
return collapse;
}
public void setCollapse(boolean collapse) {
this.collapse = collapse;
}
public String toHtmlString(){
StringBuffer sb = new StringBuffer();
sb.append("cellspacing").append("=").append(cellspacing).append(" ");
sb.append("cellpadding").append("=").append(cellpadding).append(" ");
sb.append("border").append("=").append(borderStyle.getBorderWidth()).append(" ");
return sb.toString();
}
}
Loading…
Cancel
Save