Browse Source

Merge pull request #106 in CORE/base-third from ~KERRY/base-third:feature/10.0 to feature/10.0

* commit '2075bce909584c147b6ce46b812ee38f3d62678f':
  代码修改
  wu
  无
  WU
research/11.0
ju 6 years ago
parent
commit
73983c9393
  1. 12
      fine-itext/src/com/fr/Container.java
  2. 1
      fine-itext/src/com/fr/third/v2/lowagie/text/html/CSS.java
  3. 14
      fine-itext/src/com/fr/third/v2/lowagie/text/html/CSSUtils.java
  4. 80
      fine-itext/src/com/fr/third/v2/lowagie/text/html/SpaceWithPunctuationBreakIterator.java
  5. 6
      fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/ChainedProperties.java
  6. 10
      fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java
  7. 45
      fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/IncCell.java
  8. 98
      fine-itext/src/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java
  9. 58
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/BorderStyle.java
  10. 10
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/ColumnText.java
  11. 121
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfChunk.java
  12. 2
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfDocument.java
  13. 8
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfLine.java
  14. 47
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfPCell.java
  15. 17
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfPRow.java
  16. 1072
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java
  17. 52
      fine-itext/src/com/fr/third/v2/lowagie/text/pdf/TableProperties.java

12
fine-itext/src/com/fr/Container.java

@ -0,0 +1,12 @@
package com.fr;
/**
* @author kerry
* @date 2018/8/20
*/
public interface Container {
String getHtmlContent(double lineStartY, double lineEndY);
float getHeight();
}

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_POSITION = "background-position";
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_TYPE = "list-style-type";
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;
}
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;
}
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) {
for (int k = chain.size() - 1; k >= 0; --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.Rectangle;
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.pdf.draw.LineSeparator;
import com.fr.third.v2.lowagie.text.xml.simpleparser.SimpleXMLDocHandler;
@ -648,6 +649,8 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
if (pendingTD)
endElement("td");
pendingTR = false;
String rowHeightPx = cprops.getLastChainProperty("height");
cprops.removeChain("tr");
ArrayList cells = new ArrayList();
IncTable table = null;
@ -661,8 +664,13 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
break;
}
}
float rowHeight = 0.0f;
if(rowHeightPx!=null){
rowHeight = CSSUtils.parseFloat(rowHeightPx);
}
table.addCols(cells);
table.endRow();
table.endRow(rowHeight);
stack.push(table);
skipText = true;
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;
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.ElementListener;
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.pdf.PdfPCell;
import com.fr.third.v2.lowagie.text.Phrase;
@ -95,14 +98,52 @@ public class IncCell implements TextElementArray {
value = props.getProperty("border");
float border = 0;
if (value != null)
border = Float.parseFloat(value);
border = CSSUtils.parseFloat(value);
cell.setBorderWidth(border);
value = props.getProperty("cellpadding");
if (value != null)
cell.setPadding(Float.parseFloat(value));
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){
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) {

98
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.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.PdfPCell;
import com.fr.third.v2.lowagie.text.pdf.TableProperties;
/**
*
@ -62,6 +66,8 @@ public class IncTable {
private HashMap props = new HashMap();
private ArrayList rows = new ArrayList();
private ArrayList cols;
private ArrayList<Float> rowHeights = new ArrayList<Float>();
/** Creates a new instance of IncTable */
public IncTable(HashMap props) {
this.props.putAll(props);
@ -80,7 +86,8 @@ public class IncTable {
cols.addAll(ncols);
}
public void endRow() {
public void endRow(float rowHeight) {
rowHeights.add(rowHeight);
if (cols != null) {
Collections.reverse(cols);
rows.add(cols);
@ -97,27 +104,88 @@ public class IncTable {
return new PdfPTable(1);
int ncol = 0;
ArrayList c0 = (ArrayList)rows.get(0);
ArrayList<Float> colWidths = new ArrayList<Float>();
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);
String width = (String)props.get("width");
if (width == null)
table.setWidthPercentage(100);
else {
if (width.endsWith("%"))
table.setWidthPercentage(Float.parseFloat(width.substring(0, width.length() - 1)));
try {
TableProperties tableProperties = parseTableProperties();
table.setTableProperties(tableProperties);
String width = (String)props.get("width");
if (width == null)
table.setWidthPercentage(100);
else {
table.setTotalWidth(Float.parseFloat(width));
table.setLockedWidth(true);
if (width.endsWith("%"))
table.setWidthPercentage(CSSUtils.parseFloat(width));
else {
//解析单元格宽度
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);
}
}
}
for (int row = 0; row < rows.size(); ++row) {
ArrayList col = (ArrayList)rows.get(row);
for (int k = 0; k < col.size(); ++k) {
table.addCell((PdfPCell)col.get(k));
for (int row = 0; row < rows.size(); ++row) {
ArrayList col = (ArrayList)rows.get(row);
for (int k = 0; k < col.size(); ++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;
}
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;
}
}

10
fine-itext/src/com/fr/third/v2/lowagie/text/pdf/ColumnText.java

@ -242,7 +242,15 @@ public class ColumnText {
protected ColumnText compositeColumn;
protected LinkedList compositeElements;
public LinkedList getCompositeElements() {
return compositeElements;
}
public void setCompositeElements(LinkedList compositeElements) {
this.compositeElements = compositeElements;
}
protected int listIdx = 0;
private boolean splittedRow;

121
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.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
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.Utilities;
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.html.IndentAttribute;
import com.fr.third.v2.lowagie.text.html.ParseIndentAttrUtils;
import com.fr.third.v2.lowagie.text.html.SpaceWithPunctuationBreakIterator;
import sun.font.FontDesignMetrics;
/**
@ -100,6 +103,17 @@ public class PdfChunk {
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 {
keysAttributes.put(Chunk.ACTION, null);
keysAttributes.put(Chunk.UNDERLINE, null);
@ -298,7 +312,7 @@ public class PdfChunk {
* @return the Unicode equivalent
*/
public int getUnicodeEquivalent(int c) {
return 0;
return c;
}
protected int getWord(String text, int start) {
@ -319,7 +333,7 @@ public class PdfChunk {
* @param width a given width
* @return the <CODE>PdfChunk</CODE> that doesn't fit into the width.
*/
PdfChunk split(float width) {
newlineSplit = false;
if (image != null) {
@ -330,88 +344,61 @@ public class PdfChunk {
image = null;
font = PdfFont.getDefaultFont();
return pc;
}
else
} else
return null;
}
HyphenationEvent hyphenationEvent = (HyphenationEvent)noStroke.get(Chunk.HYPHENATION);
int currentPosition = 0;
int splitPosition = -1;
int start = 0;
float currentWidth = indent.getLeft();
// loop over all the characters of a string
// or until the totalWidth is reached
int lastSpace = -1;
float lastSpaceWidth = 0;
int length = value.length();
char valueArray[] = value.toCharArray();
BreakIterator iterator = BreakIterator.getLineInstance(Locale.getDefault());
BreakIterator iterator1 = new SpaceWithPunctuationBreakIterator(value, iterator);
char character = 0;
boolean surrogate = false;
while (currentPosition < length) {
// the width of every character is added to the currentWidth
character = valueArray[currentPosition];
// if a newLine or carriageReturn is encountered
if (character == '\r' || character == '\n') {
newlineSplit = true;
int inc = 1;
if (character == '\r' && currentPosition + 1 < length && valueArray[currentPosition + 1] == '\n')
inc = 2;
String returnValue = value.substring(currentPosition + inc);
value = value.substring(0, currentPosition);
PdfChunk pc = new PdfChunk(returnValue, this);
return pc;
}
surrogate = Utilities.isSurrogatePair(valueArray, currentPosition);
if (surrogate)
currentWidth += font.width(Utilities.convertToUtf32(valueArray[currentPosition], valueArray[currentPosition + 1]));
else
currentWidth += font.width(character);
if (character == ' ') {
lastSpace = currentPosition + 1;
lastSpaceWidth = currentWidth;
}
if (surrogate)
currentPosition++;
if (currentWidth + indent.getRight()> width)
break;
// if a split-character is encountered, the splitPosition is altered
if (splitCharacter.isSplitCharacter(0, currentPosition, length, valueArray, null))
splitPosition = currentPosition + 1;
currentPosition++;
while (currentPosition < length) {
int next = iterator1.next();
if(next < 1){
break;
}
currentPosition = next - 1;
// the width of every character is added to the currentWidth
character = valueArray[currentPosition];
// if a newLine or carriageReturn is encountered
if (character == '\r' || character == '\n') {
newlineSplit = true;
int inc = 1;
if (character == '\r' && currentPosition + 1 < length && valueArray[currentPosition + 1] == '\n')
inc = 2;
String returnValue = value.substring(currentPosition + inc);
value = value.substring(0, currentPosition);
PdfChunk pc = new PdfChunk(returnValue, this);
return pc;
}
String substring = value.substring(start, next);
currentWidth += font.width(substring);
if (currentWidth + indent.getRight() > width){
currentPosition = start - 1;
break;
}
start = next;
}
// 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;
}
// otherwise, the string has to be truncated
if (splitPosition < 0) {
String returnValue = value;
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));
String returnValue = value.substring(start);
value = trim(value.substring(0, start));
PdfChunk pc = new PdfChunk(returnValue, this);
return pc;
}
/**
* Truncates this <CODE>PdfChunk</CODE> if it's too long for the given width.
* <P>
@ -808,7 +795,7 @@ public class PdfChunk {
}
//todo 需要添加其他样式属性
htmlString.append("<span style='");
htmlString.append("").append(getStyleAttributes()).append("'");
htmlString.append(getStyleAttributes()).append("'");
htmlString.append(">");
htmlString.append(value);
htmlString.append("</span>");

2
fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfDocument.java

@ -1357,7 +1357,7 @@ public class PdfDocument extends Document {
* @param ratio
* @throws DocumentException on error
*/
void writeLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, Object currentValues[], float ratio) throws DocumentException {
void writeLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, Object currentValues[], float ratio) throws DocumentException {
PdfFont currentFont = (PdfFont)(currentValues[0]);
float lastBaseFactor = ((Float)(currentValues[1])).floatValue();
PdfChunk chunk;

8
fine-itext/src/com/fr/third/v2/lowagie/text/pdf/PdfLine.java

@ -255,7 +255,7 @@ public class PdfLine {
* @return a value
*/
float indentLeft() {
public float indentLeft() {
if (isRTL) {
switch (alignment) {
case Element.ALIGN_LEFT:
@ -312,7 +312,7 @@ public class PdfLine {
* @return a value
*/
float widthLeft() {
public float widthLeft() {
return width;
}
@ -460,7 +460,7 @@ public class PdfLine {
* @return an extra leading for images
* @since 2.1.5
*/
float[] getMaxSize() {
public float[] getMaxSize() {
float normal_leading = 0;
float image_leading = -10000;
PdfChunk chunk;
@ -476,7 +476,7 @@ public class PdfLine {
return new float[]{normal_leading, image_leading};
}
boolean isRTL() {
public boolean isRTL() {
return isRTL;
}

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

@ -50,7 +50,9 @@
package com.fr.third.v2.lowagie.text.pdf;
import java.util.List;
import java.util.Map;
import com.fr.Container;
import com.fr.third.v2.lowagie.text.Chunk;
import com.fr.third.v2.lowagie.text.DocumentException;
import com.fr.third.v2.lowagie.text.Element;
@ -65,7 +67,37 @@ import com.fr.third.v2.lowagie.text.Phrase;
*/
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);
/** Vertical alignment of the cell. */
@ -256,6 +288,9 @@ public class PdfPCell extends Rectangle {
column = ColumnText.duplicate(cell.column);
useBorderPadding = cell.useBorderPadding;
rotation = cell.rotation;
background = cell.background;
styleWidth = cell.styleWidth;
styleHeight = cell.styleHeight;
}
/**
@ -1010,4 +1045,14 @@ public class PdfPCell extends Rectangle {
height = getMinimumHeight();
return height;
}
private Container container;
public Container getContainer() {
return container;
}
public void addContent(Container container){
this.container = container;
}
}

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

@ -75,7 +75,17 @@ public class PdfPRow {
protected PdfPCell cells[];
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.
* @since 2.1.6
@ -186,15 +196,16 @@ public class PdfPRow {
continue;
}
else {
height = cell.getMaxHeight();
height = cell.getStyleHeight() == 0 ? cell.getContainer().getHeight() : cell.getStyleHeight();
if ((height > maxHeight) && (cell.getRowspan() == 1))
maxHeight = height;
}
}
calculated = true;
return maxHeight;
return maxHeight = Math.max(styleHeight, maxHeight);
}
/**
* Writes the border and background of one cell in the row.
*

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

File diff suppressed because it is too large Load Diff

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