Browse Source

REPORT-11624 Excel和Word导出的html解析(third部分)

research/11.0
kerry 6 years ago
parent
commit
9ed5213d06
  1. 158
      fine-itext-old/src/com/fr/third/com/lowagie/text/Chunk.java
  2. 33
      fine-itext-old/src/com/fr/third/com/lowagie/text/Font.java
  3. 689
      fine-itext-old/src/com/fr/third/com/lowagie/text/Image.java
  4. 399
      fine-itext-old/src/com/fr/third/com/lowagie/text/List.java
  5. 140
      fine-itext-old/src/com/fr/third/com/lowagie/text/Paragraph.java
  6. 2
      fine-itext-old/src/com/fr/third/com/lowagie/text/factories/ElementFactory.java
  7. 200
      fine-itext-old/src/com/fr/third/com/lowagie/text/html/CSS.java
  8. 108
      fine-itext-old/src/com/fr/third/com/lowagie/text/html/CSSUtils.java
  9. 55
      fine-itext-old/src/com/fr/third/com/lowagie/text/html/IndentAttribute.java
  10. 139
      fine-itext-old/src/com/fr/third/com/lowagie/text/html/Markup.java
  11. 84
      fine-itext-old/src/com/fr/third/com/lowagie/text/html/ParseIndentAttrUtils.java
  12. 4
      fine-itext-old/src/com/fr/third/com/lowagie/text/html/WebColors.java
  13. 67
      fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/ChainedProperties.java
  14. 82
      fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/FactoryProperties.java
  15. 103
      fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/HTMLWorker.java
  16. 45
      fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/HtmlConstants.java
  17. 94
      fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/IncCell.java
  18. 110
      fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/IncTable.java
  19. 58
      fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/BorderStyle.java
  20. 539
      fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfPCell.java
  21. 490
      fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfPRow.java
  22. 1084
      fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfPTable.java
  23. 54
      fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/TableProperties.java
  24. 3
      fine-itext-old/src/com/fr/third/com/lowagie/text/rtf/text/RtfChunk.java

158
fine-itext-old/src/com/fr/third/com/lowagie/text/Chunk.java

@ -49,16 +49,18 @@
package com.fr.third.com.lowagie.text; package com.fr.third.com.lowagie.text;
import java.awt.Color;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import com.fr.third.com.lowagie.text.pdf.HyphenationEvent; import com.fr.third.com.lowagie.text.pdf.HyphenationEvent;
import com.fr.third.com.lowagie.text.pdf.PdfAction; import com.fr.third.com.lowagie.text.pdf.PdfAction;
import com.fr.third.com.lowagie.text.pdf.PdfAnnotation; import com.fr.third.com.lowagie.text.pdf.PdfAnnotation;
import com.fr.third.com.lowagie.text.pdf.PdfContentByte; import com.fr.third.com.lowagie.text.pdf.PdfContentByte;
import com.fr.third.com.lowagie.text.pdf.draw.DrawInterface; import com.fr.third.com.lowagie.text.pdf.draw.DrawInterface;
import sun.font.FontDesignMetrics;
import java.awt.Color;
import java.awt.FontMetrics;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
/** /**
* This is the smallest significant part of text that can be added to a * This is the smallest significant part of text that can be added to a
@ -122,7 +124,7 @@ public class Chunk implements Element {
/** /**
* A <CODE>Chunk</CODE> copy constructor. * A <CODE>Chunk</CODE> copy constructor.
* @param ck the <CODE>Chunk</CODE> to be copied * @param ck the <CODE>Chunk</CODE> to be copied
*/ */
public Chunk(Chunk ck) { public Chunk(Chunk ck) {
if (ck.content != null) { if (ck.content != null) {
content = new StringBuffer(ck.content.toString()); content = new StringBuffer(ck.content.toString());
@ -134,11 +136,11 @@ public class Chunk implements Element {
attributes = new HashMap(ck.attributes); attributes = new HashMap(ck.attributes);
} }
} }
/** /**
* Constructs a chunk of text with a certain content and a certain <CODE> * Constructs a chunk of text with a certain content and a certain <CODE>
* Font</CODE>. * Font</CODE>.
* *
* @param content * @param content
* the content * the content
* @param font * @param font
@ -152,7 +154,7 @@ public class Chunk implements Element {
/** /**
* Constructs a chunk of text with a certain content, without specifying a * Constructs a chunk of text with a certain content, without specifying a
* <CODE>Font</CODE>. * <CODE>Font</CODE>.
* *
* @param content * @param content
* the content * the content
*/ */
@ -162,7 +164,7 @@ public class Chunk implements Element {
/** /**
* Constructs a chunk of text with a char and a certain <CODE>Font</CODE>. * Constructs a chunk of text with a char and a certain <CODE>Font</CODE>.
* *
* @param c * @param c
* the content * the content
* @param font * @param font
@ -177,7 +179,7 @@ public class Chunk implements Element {
/** /**
* Constructs a chunk of text with a char, without specifying a <CODE>Font * Constructs a chunk of text with a char, without specifying a <CODE>Font
* </CODE>. * </CODE>.
* *
* @param c * @param c
* the content * the content
*/ */
@ -187,7 +189,7 @@ public class Chunk implements Element {
/** /**
* Constructs a chunk containing an <CODE>Image</CODE>. * Constructs a chunk containing an <CODE>Image</CODE>.
* *
* @param image * @param image
* the image * the image
* @param offsetX * @param offsetX
@ -208,7 +210,7 @@ public class Chunk implements Element {
* @since 2.1.2 * @since 2.1.2
*/ */
public static final String SEPARATOR = "SEPARATOR"; public static final String SEPARATOR = "SEPARATOR";
/** /**
* Creates a separator Chunk. * Creates a separator Chunk.
* Note that separator chunks can't be used in combination with tab chunks! * Note that separator chunks can't be used in combination with tab chunks!
@ -217,8 +219,8 @@ public class Chunk implements Element {
*/ */
public Chunk(DrawInterface separator) { public Chunk(DrawInterface separator) {
this(separator, false); this(separator, false);
} }
/** /**
* Creates a separator Chunk. * Creates a separator Chunk.
* Note that separator chunks can't be used in combination with tab chunks! * Note that separator chunks can't be used in combination with tab chunks!
@ -236,7 +238,7 @@ public class Chunk implements Element {
* @since 2.1.2 * @since 2.1.2
*/ */
public static final String TAB = "TAB"; public static final String TAB = "TAB";
/** /**
* Creates a tab Chunk. * Creates a tab Chunk.
* Note that separator chunks can't be used in combination with tab chunks! * Note that separator chunks can't be used in combination with tab chunks!
@ -247,7 +249,7 @@ public class Chunk implements Element {
public Chunk(DrawInterface separator, float tabPosition) { public Chunk(DrawInterface separator, float tabPosition) {
this(separator, tabPosition, false); this(separator, tabPosition, false);
} }
/** /**
* Creates a tab Chunk. * Creates a tab Chunk.
* Note that separator chunks can't be used in combination with tab chunks! * Note that separator chunks can't be used in combination with tab chunks!
@ -266,7 +268,7 @@ public class Chunk implements Element {
/** /**
* Constructs a chunk containing an <CODE>Image</CODE>. * Constructs a chunk containing an <CODE>Image</CODE>.
* *
* @param image * @param image
* the image * the image
* @param offsetX * @param offsetX
@ -277,7 +279,7 @@ public class Chunk implements Element {
* true if the leading has to be adapted to the image * true if the leading has to be adapted to the image
*/ */
public Chunk(Image image, float offsetX, float offsetY, public Chunk(Image image, float offsetX, float offsetY,
boolean changeLeading) { boolean changeLeading) {
this(OBJECT_REPLACEMENT_CHARACTER, new Font()); this(OBJECT_REPLACEMENT_CHARACTER, new Font());
setAttribute(IMAGE, new Object[] { image, new Float(offsetX), setAttribute(IMAGE, new Object[] { image, new Float(offsetX),
new Float(offsetY), Boolean.valueOf(changeLeading) }); new Float(offsetY), Boolean.valueOf(changeLeading) });
@ -288,7 +290,7 @@ public class Chunk implements Element {
/** /**
* Processes the element by adding it (or the different parts) to an <CODE> * Processes the element by adding it (or the different parts) to an <CODE>
* ElementListener</CODE>. * ElementListener</CODE>.
* *
* @param listener * @param listener
* an <CODE>ElementListener</CODE> * an <CODE>ElementListener</CODE>
* @return <CODE>true</CODE> if the element was processed successfully * @return <CODE>true</CODE> if the element was processed successfully
@ -303,7 +305,7 @@ public class Chunk implements Element {
/** /**
* Gets the type of the text element. * Gets the type of the text element.
* *
* @return a type * @return a type
*/ */
public int type() { public int type() {
@ -312,7 +314,7 @@ public class Chunk implements Element {
/** /**
* Gets all the chunks in this element. * Gets all the chunks in this element.
* *
* @return an <CODE>ArrayList</CODE> * @return an <CODE>ArrayList</CODE>
*/ */
public ArrayList getChunks() { public ArrayList getChunks() {
@ -325,7 +327,7 @@ public class Chunk implements Element {
/** /**
* appends some text to this <CODE>Chunk</CODE>. * appends some text to this <CODE>Chunk</CODE>.
* *
* @param string * @param string
* <CODE>String</CODE> * <CODE>String</CODE>
* @return a <CODE>StringBuffer</CODE> * @return a <CODE>StringBuffer</CODE>
@ -336,7 +338,7 @@ public class Chunk implements Element {
/** /**
* Sets the font of this <CODE>Chunk</CODE>. * Sets the font of this <CODE>Chunk</CODE>.
* *
* @param font * @param font
* a <CODE>Font</CODE> * a <CODE>Font</CODE>
*/ */
@ -348,7 +350,7 @@ public class Chunk implements Element {
/** /**
* Gets the font of this <CODE>Chunk</CODE>. * Gets the font of this <CODE>Chunk</CODE>.
* *
* @return a <CODE>Font</CODE> * @return a <CODE>Font</CODE>
*/ */
public Font getFont() { public Font getFont() {
@ -357,7 +359,7 @@ public class Chunk implements Element {
/** /**
* Returns the content of this <CODE>Chunk</CODE>. * Returns the content of this <CODE>Chunk</CODE>.
* *
* @return a <CODE>String</CODE> * @return a <CODE>String</CODE>
*/ */
public String getContent() { public String getContent() {
@ -366,7 +368,7 @@ public class Chunk implements Element {
/** /**
* Returns the content of this <CODE>Chunk</CODE>. * Returns the content of this <CODE>Chunk</CODE>.
* *
* @return a <CODE>String</CODE> * @return a <CODE>String</CODE>
*/ */
public String toString() { public String toString() {
@ -375,7 +377,7 @@ public class Chunk implements Element {
/** /**
* Checks is this <CODE>Chunk</CODE> is empty. * Checks is this <CODE>Chunk</CODE> is empty.
* *
* @return <CODE>false</CODE> if the Chunk contains other characters than * @return <CODE>false</CODE> if the Chunk contains other characters than
* space. * space.
*/ */
@ -387,23 +389,23 @@ public class Chunk implements Element {
/** /**
* Gets the width of the Chunk in points. * Gets the width of the Chunk in points.
* *
* @return a width in points * @return a width in points
*/ */
public float getWidthPoint() { public float getWidthPoint() {
if (getImage() != null) { if (getImage() != null) {
return getImage().getScaledWidth(); return getImage().getScaledWidth();
} }
return font.getCalculatedBaseFont(true).getWidthPoint(getContent(), java.awt.Font awtFont = new java.awt.Font(font.getFontName(), font.getStyle(), (int)font.getSize());
font.getCalculatedSize()) FontMetrics metrics = FontDesignMetrics.getMetrics(awtFont);
* getHorizontalScaling(); return metrics.stringWidth(getContent())* getHorizontalScaling();
} }
// attributes // attributes
/** /**
* Checks the attributes of this <CODE>Chunk</CODE>. * Checks the attributes of this <CODE>Chunk</CODE>.
* *
* @return false if there aren't any. * @return false if there aren't any.
*/ */
@ -415,7 +417,7 @@ public class Chunk implements Element {
* Gets the attributes for this <CODE>Chunk</CODE>. * Gets the attributes for this <CODE>Chunk</CODE>.
* <P> * <P>
* It may be null. * It may be null.
* *
* @return the attributes for this <CODE>Chunk</CODE> * @return the attributes for this <CODE>Chunk</CODE>
*/ */
@ -433,7 +435,7 @@ public class Chunk implements Element {
/** /**
* Sets an arbitrary attribute. * Sets an arbitrary attribute.
* *
* @param name * @param name
* the key for the attribute * the key for the attribute
* @param obj * @param obj
@ -441,7 +443,7 @@ public class Chunk implements Element {
* @return this <CODE>Chunk</CODE> * @return this <CODE>Chunk</CODE>
*/ */
private Chunk setAttribute(String name, Object obj) { public Chunk setAttribute(String name, Object obj) {
if (attributes == null) if (attributes == null)
attributes = new HashMap(); attributes = new HashMap();
attributes.put(name, obj); attributes.put(name, obj);
@ -456,7 +458,7 @@ public class Chunk implements Element {
/** /**
* Sets the text horizontal scaling. A value of 1 is normal and a value of * Sets the text horizontal scaling. A value of 1 is normal and a value of
* 0.5f shrinks the text to half it's width. * 0.5f shrinks the text to half it's width.
* *
* @param scale * @param scale
* the horizontal scaling factor * the horizontal scaling factor
* @return this <CODE>Chunk</CODE> * @return this <CODE>Chunk</CODE>
@ -467,7 +469,7 @@ public class Chunk implements Element {
/** /**
* Gets the horizontal scaling. * Gets the horizontal scaling.
* *
* @return a percentage in float * @return a percentage in float
*/ */
public float getHorizontalScaling() { public float getHorizontalScaling() {
@ -487,7 +489,7 @@ public class Chunk implements Element {
* Actually, the line can be anywhere vertically and has always the <CODE> * Actually, the line can be anywhere vertically and has always the <CODE>
* Chunk</CODE> width. Multiple call to this method will produce multiple * Chunk</CODE> width. Multiple call to this method will produce multiple
* lines. * lines.
* *
* @param thickness * @param thickness
* the absolute thickness of the line * the absolute thickness of the line
* @param yPosition * @param yPosition
@ -504,7 +506,7 @@ public class Chunk implements Element {
* Actually, the line can be anywhere vertically and has always the <CODE> * Actually, the line can be anywhere vertically and has always the <CODE>
* Chunk</CODE> width. Multiple call to this method will produce multiple * Chunk</CODE> width. Multiple call to this method will produce multiple
* lines. * lines.
* *
* @param color * @param color
* the color of the line or <CODE>null</CODE> to follow the * the color of the line or <CODE>null</CODE> to follow the
* text color * text color
@ -523,7 +525,7 @@ public class Chunk implements Element {
* @return this <CODE>Chunk</CODE> * @return this <CODE>Chunk</CODE>
*/ */
public Chunk setUnderline(Color color, float thickness, float thicknessMul, public Chunk setUnderline(Color color, float thickness, float thicknessMul,
float yPosition, float yPositionMul, int cap) { float yPosition, float yPositionMul, int cap) {
if (attributes == null) if (attributes == null)
attributes = new HashMap(); attributes = new HashMap();
Object obj[] = { Object obj[] = {
@ -533,16 +535,16 @@ public class Chunk implements Element {
obj); obj);
return setAttribute(UNDERLINE, unders); return setAttribute(UNDERLINE, unders);
} }
/** Key for sub/superscript. */ /** Key for sub/superscript. */
public static final String SUBSUPSCRIPT = "SUBSUPSCRIPT"; public static final String SUBSUPSCRIPT = "SUBSUPSCRIPT";
/** /**
* Sets the text displacement relative to the baseline. Positive values rise * Sets the text displacement relative to the baseline. Positive values rise
* the text, negative values lower the text. * the text, negative values lower the text.
* <P> * <P>
* It can be used to implement sub/superscript. * It can be used to implement sub/superscript.
* *
* @param rise * @param rise
* the displacement in points * the displacement in points
* @return this <CODE>Chunk</CODE> * @return this <CODE>Chunk</CODE>
@ -554,7 +556,7 @@ public class Chunk implements Element {
/** /**
* Gets the text displacement relative to the baseline. * Gets the text displacement relative to the baseline.
* *
* @return a displacement in points * @return a displacement in points
*/ */
public float getTextRise() { public float getTextRise() {
@ -571,7 +573,7 @@ public class Chunk implements Element {
/** /**
* Skews the text to simulate italic and other effects. Try <CODE>alpha=0 * Skews the text to simulate italic and other effects. Try <CODE>alpha=0
* </CODE> and <CODE>beta=12</CODE>. * </CODE> and <CODE>beta=12</CODE>.
* *
* @param alpha * @param alpha
* the first angle in degrees * the first angle in degrees
* @param beta * @param beta
@ -589,19 +591,19 @@ public class Chunk implements Element {
/** /**
* Sets the color of the background <CODE>Chunk</CODE>. * Sets the color of the background <CODE>Chunk</CODE>.
* *
* @param color * @param background
* the color of the background * the color of the background
* @return this <CODE>Chunk</CODE> * @return this <CODE>Chunk</CODE>
*/ */
public Chunk setBackground(Color color) { public Chunk setBackground(String background) {
return setBackground(color, 0, 0, 0, 0); return setBackground(background, 0, 0, 0, 0);
} }
/** /**
* Sets the color and the size of the background <CODE>Chunk</CODE>. * Sets the color and the size of the background <CODE>Chunk</CODE>.
* *
* @param color * @param background
* the color of the background * the color of the background
* @param extraLeft * @param extraLeft
* increase the size of the rectangle in the left * increase the size of the rectangle in the left
@ -613,9 +615,9 @@ public class Chunk implements Element {
* increase the size of the rectangle in the top * increase the size of the rectangle in the top
* @return this <CODE>Chunk</CODE> * @return this <CODE>Chunk</CODE>
*/ */
public Chunk setBackground(Color color, float extraLeft, float extraBottom, public Chunk setBackground(String background, float extraLeft, float extraBottom,
float extraRight, float extraTop) { float extraRight, float extraTop) {
return setAttribute(BACKGROUND, new Object[] { color, return setAttribute(BACKGROUND, new Object[] { background,
new float[] { extraLeft, extraBottom, extraRight, extraTop } }); new float[] { extraLeft, extraBottom, extraRight, extraTop } });
} }
@ -625,7 +627,7 @@ public class Chunk implements Element {
/** /**
* Sets the text rendering mode. It can outline text, simulate bold and make * Sets the text rendering mode. It can outline text, simulate bold and make
* text invisible. * text invisible.
* *
* @param mode * @param mode
* the text rendering mode. It can be <CODE> * the text rendering mode. It can be <CODE>
* PdfContentByte.TEXT_RENDER_MODE_FILL</CODE>,<CODE> * PdfContentByte.TEXT_RENDER_MODE_FILL</CODE>,<CODE>
@ -642,7 +644,7 @@ public class Chunk implements Element {
* @return this <CODE>Chunk</CODE> * @return this <CODE>Chunk</CODE>
*/ */
public Chunk setTextRenderMode(int mode, float strokeWidth, public Chunk setTextRenderMode(int mode, float strokeWidth,
Color strokeColor) { Color strokeColor) {
return setAttribute(TEXTRENDERMODE, new Object[] { new Integer(mode), return setAttribute(TEXTRENDERMODE, new Object[] { new Integer(mode),
new Float(strokeWidth), strokeColor }); new Float(strokeWidth), strokeColor });
} }
@ -652,7 +654,7 @@ public class Chunk implements Element {
/** /**
* Sets the split characters. * Sets the split characters.
* *
* @param splitCharacter * @param splitCharacter
* the <CODE>SplitCharacter</CODE> interface * the <CODE>SplitCharacter</CODE> interface
* @return this <CODE>Chunk</CODE> * @return this <CODE>Chunk</CODE>
@ -664,10 +666,10 @@ public class Chunk implements Element {
/** Key for hyphenation. */ /** Key for hyphenation. */
public static final String HYPHENATION = "HYPHENATION"; public static final String HYPHENATION = "HYPHENATION";
/** /**
* sets the hyphenation engine to this <CODE>Chunk</CODE>. * sets the hyphenation engine to this <CODE>Chunk</CODE>.
* *
* @param hyphenation * @param hyphenation
* the hyphenation engine * the hyphenation engine
* @return this <CODE>Chunk</CODE> * @return this <CODE>Chunk</CODE>
@ -681,7 +683,7 @@ public class Chunk implements Element {
/** /**
* Sets a goto for a remote destination for this <CODE>Chunk</CODE>. * Sets a goto for a remote destination for this <CODE>Chunk</CODE>.
* *
* @param filename * @param filename
* the file name of the destination document * the file name of the destination document
* @param name * @param name
@ -695,7 +697,7 @@ public class Chunk implements Element {
/** /**
* Sets a goto for a remote destination for this <CODE>Chunk</CODE>. * Sets a goto for a remote destination for this <CODE>Chunk</CODE>.
* *
* @param filename * @param filename
* the file name of the destination document * the file name of the destination document
* @param page * @param page
@ -710,12 +712,12 @@ public class Chunk implements Element {
/** Key for local goto. */ /** Key for local goto. */
public static final String LOCALGOTO = "LOCALGOTO"; public static final String LOCALGOTO = "LOCALGOTO";
/** /**
* Sets a local goto for this <CODE>Chunk</CODE>. * Sets a local goto for this <CODE>Chunk</CODE>.
* <P> * <P>
* There must be a local destination matching the name. * There must be a local destination matching the name.
* *
* @param name * @param name
* the name of the destination to go to * the name of the destination to go to
* @return this <CODE>Chunk</CODE> * @return this <CODE>Chunk</CODE>
@ -730,7 +732,7 @@ public class Chunk implements Element {
/** /**
* Sets a local destination for this <CODE>Chunk</CODE>. * Sets a local destination for this <CODE>Chunk</CODE>.
* *
* @param name * @param name
* the name for this destination * the name for this destination
* @return this <CODE>Chunk</CODE> * @return this <CODE>Chunk</CODE>
@ -746,7 +748,7 @@ public class Chunk implements Element {
* Sets the generic tag <CODE>Chunk</CODE>. * Sets the generic tag <CODE>Chunk</CODE>.
* <P> * <P>
* The text for this tag can be retrieved with <CODE>PdfPageEvent</CODE>. * The text for this tag can be retrieved with <CODE>PdfPageEvent</CODE>.
* *
* @param text * @param text
* the text for the tag * the text for the tag
* @return this <CODE>Chunk</CODE> * @return this <CODE>Chunk</CODE>
@ -755,13 +757,13 @@ public class Chunk implements Element {
public Chunk setGenericTag(String text) { public Chunk setGenericTag(String text) {
return setAttribute(GENERICTAG, text); return setAttribute(GENERICTAG, text);
} }
/** Key for image. */ /** Key for image. */
public static final String IMAGE = "IMAGE"; public static final String IMAGE = "IMAGE";
/** /**
* Returns the image. * Returns the image.
* *
* @return the image * @return the image
*/ */
@ -775,13 +777,13 @@ public class Chunk implements Element {
return (Image) obj[0]; return (Image) obj[0];
} }
} }
/** Key for Action. */ /** Key for Action. */
public static final String ACTION = "ACTION"; public static final String ACTION = "ACTION";
/** /**
* Sets an action for this <CODE>Chunk</CODE>. * Sets an action for this <CODE>Chunk</CODE>.
* *
* @param action * @param action
* the action * the action
* @return this <CODE>Chunk</CODE> * @return this <CODE>Chunk</CODE>
@ -793,7 +795,7 @@ public class Chunk implements Element {
/** /**
* Sets an anchor for this <CODE>Chunk</CODE>. * Sets an anchor for this <CODE>Chunk</CODE>.
* *
* @param url * @param url
* the <CODE>URL</CODE> to link to * the <CODE>URL</CODE> to link to
* @return this <CODE>Chunk</CODE> * @return this <CODE>Chunk</CODE>
@ -805,7 +807,7 @@ public class Chunk implements Element {
/** /**
* Sets an anchor for this <CODE>Chunk</CODE>. * Sets an anchor for this <CODE>Chunk</CODE>.
* *
* @param url * @param url
* the url to link to * the url to link to
* @return this <CODE>Chunk</CODE> * @return this <CODE>Chunk</CODE>
@ -814,13 +816,13 @@ public class Chunk implements Element {
public Chunk setAnchor(String url) { public Chunk setAnchor(String url) {
return setAttribute(ACTION, new PdfAction(url)); return setAttribute(ACTION, new PdfAction(url));
} }
/** Key for newpage. */ /** Key for newpage. */
public static final String NEWPAGE = "NEWPAGE"; public static final String NEWPAGE = "NEWPAGE";
/** /**
* Sets a new page tag.. * Sets a new page tag..
* *
* @return this <CODE>Chunk</CODE> * @return this <CODE>Chunk</CODE>
*/ */
@ -833,7 +835,7 @@ public class Chunk implements Element {
/** /**
* Sets a generic annotation to this <CODE>Chunk</CODE>. * Sets a generic annotation to this <CODE>Chunk</CODE>.
* *
* @param annotation * @param annotation
* the annotation * the annotation
* @return this <CODE>Chunk</CODE> * @return this <CODE>Chunk</CODE>
@ -841,9 +843,9 @@ public class Chunk implements Element {
public Chunk setAnnotation(PdfAnnotation annotation) { public Chunk setAnnotation(PdfAnnotation annotation) {
return setAttribute(PDFANNOTATION, annotation); return setAttribute(PDFANNOTATION, annotation);
} }
/** /**
* @see com.fr.third.com.lowagie.text.Element#isContent() * @see Element#isContent()
* @since iText 2.0.8 * @since iText 2.0.8
*/ */
public boolean isContent() { public boolean isContent() {
@ -851,7 +853,7 @@ public class Chunk implements Element {
} }
/** /**
* @see com.fr.third.com.lowagie.text.Element#isNestable() * @see Element#isNestable()
* @since iText 2.0.8 * @since iText 2.0.8
*/ */
public boolean isNestable() { public boolean isNestable() {

33
fine-itext-old/src/com/fr/third/com/lowagie/text/Font.java

@ -350,35 +350,7 @@ public class Font implements Comparable {
* @return the familyname * @return the familyname
*/ */
public String getFamilyname() { public String getFamilyname() {
String tmp = "unknown"; return getFontName();
switch (getFamily()) {
case Font.COURIER:
return FontFactory.COURIER;
case Font.HELVETICA:
return FontFactory.HELVETICA;
case Font.TIMES_ROMAN:
return FontFactory.TIMES_ROMAN;
case Font.SYMBOL:
return FontFactory.SYMBOL;
case Font.ZAPFDINGBATS:
return FontFactory.ZAPFDINGBATS;
default:
if (baseFont != null) {
String[][] names = baseFont.getFamilyFontName();
for (int i = 0; i < names.length; i++) {
if ("0".equals(names[i][2])) {
return names[i][3];
}
if ("1033".equals(names[i][2])) {
tmp = names[i][3];
}
if ("".equals(names[i][2])) {
tmp = names[i][3];
}
}
}
}
return tmp;
} }
/** /**
@ -389,9 +361,10 @@ public class Font implements Comparable {
* A <CODE>String</CODE> representing a certain font-family. * A <CODE>String</CODE> representing a certain font-family.
*/ */
public void setFamily(String family) { public void setFamily(String family) {
this.family = getFamilyIndex(family); this.fontName = family;
} }
/** /**
* Translates a <CODE>String</CODE> -value of a certain family into the * Translates a <CODE>String</CODE> -value of a certain family into the
* index that is used for this family in this class. * index that is used for this family in this class.

689
fine-itext-old/src/com/fr/third/com/lowagie/text/Image.java

File diff suppressed because it is too large Load Diff

399
fine-itext-old/src/com/fr/third/com/lowagie/text/List.java

@ -49,11 +49,11 @@
package com.fr.third.com.lowagie.text; package com.fr.third.com.lowagie.text;
import com.fr.third.com.lowagie.text.factories.RomanAlphabetFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import com.fr.third.com.lowagie.text.factories.RomanAlphabetFactory;
/** /**
* A <CODE>List</CODE> contains several <CODE>ListItem</CODE>s. * A <CODE>List</CODE> contains several <CODE>ListItem</CODE>s.
* <P> * <P>
@ -100,38 +100,47 @@ import com.fr.third.com.lowagie.text.factories.RomanAlphabetFactory;
*/ */
public class List implements TextElementArray { public class List implements TextElementArray {
// constants // constants
/** a possible value for the numbered parameter */ /** a possible value for the numbered parameter */
public static final boolean ORDERED = true; public static final boolean ORDERED = true;
/** a possible value for the numbered parameter */ /** a possible value for the numbered parameter */
public static final boolean UNORDERED = false; public static final boolean UNORDERED = false;
/** a possible value for the lettered parameter */ /** a possible value for the lettered parameter */
public static final boolean NUMERICAL = false; public static final boolean NUMERICAL = false;
/** a possible value for the lettered parameter */ /** a possible value for the lettered parameter */
public static final boolean ALPHABETICAL = true; public static final boolean ALPHABETICAL = true;
/** a possible value for the lettered parameter */ /** a possible value for the lettered parameter */
public static final boolean UPPERCASE = false; public static final boolean UPPERCASE = false;
/** a possible value for the lettered parameter */ /** a possible value for the lettered parameter */
public static final boolean LOWERCASE = true; public static final boolean LOWERCASE = true;
// member variables // member variables
/** This is the <CODE>ArrayList</CODE> containing the different <CODE>ListItem</CODE>s. */ /** This is the <CODE>ArrayList</CODE> containing the different <CODE>ListItem</CODE>s. */
protected ArrayList list = new ArrayList(); protected ArrayList list = new ArrayList();
/** Indicates if the list has to be numbered. */ /** Indicates if the list has to be numbered. */
protected boolean numbered = false; protected boolean numbered = false;
/** Indicates if the listsymbols are numerical or alphabetical. */ /** Indicates if the listsymbols are numerical or alphabetical. */
protected boolean lettered = false; protected boolean lettered = false;
/** Indicates if the listsymbols are lowercase or uppercase. */ /** Indicates if the listsymbols are lowercase or uppercase. */
protected boolean lowercase = false; protected boolean lowercase = false;
public ArrayList getList() {
return list;
}
public void setList(ArrayList list) {
this.list = list;
}
/** Indicates if the indentation has to be set automatically. */ /** Indicates if the indentation has to be set automatically. */
protected boolean autoindent = false; protected boolean autoindent = false;
/** Indicates if the indentation of all the items has to be aligned. */ /** Indicates if the indentation of all the items has to be aligned. */
protected boolean alignindent = false; protected boolean alignindent = false;
/** This variable indicates the first number of a numbered list. */ /** This variable indicates the first number of a numbered list. */
protected int first = 1; protected int first = 1;
/** This is the listsymbol of a list that is not numbered. */ /** This is the listsymbol of a list that is not numbered. */
@ -142,54 +151,54 @@ public class List implements TextElementArray {
*/ */
protected String preSymbol = ""; protected String preSymbol = "";
/** /**
* In case you are using numbered/lettered lists, this String is added after the number/letter. * In case you are using numbered/lettered lists, this String is added after the number/letter.
* @since iText 2.1.1 * @since iText 2.1.1
*/ */
protected String postSymbol = ". "; protected String postSymbol = ". ";
/** The indentation of this list on the left side. */ /** The indentation of this list on the left side. */
protected float indentationLeft = 0; protected float indentationLeft = 0;
/** The indentation of this list on the right side. */ /** The indentation of this list on the right side. */
protected float indentationRight = 0; protected float indentationRight = 0;
/** The indentation of the listitems. */ /** The indentation of the listitems. */
protected float symbolIndent = 0; protected float symbolIndent = 0;
// constructors // constructors
/** Constructs a <CODE>List</CODE>. */ /** Constructs a <CODE>List</CODE>. */
public List() { public List() {
this(false, false); this(false, false);
} }
/** /**
* Constructs a <CODE>List</CODE> with a specific symbol indentation. * Constructs a <CODE>List</CODE> with a specific symbol indentation.
* @param symbolIndent the symbol indentation * @param symbolIndent the symbol indentation
* @since iText 2.0.8 * @since iText 2.0.8
*/ */
public List(float symbolIndent) { public List(float symbolIndent) {
this.symbolIndent = symbolIndent; this.symbolIndent = symbolIndent;
} }
/** /**
* Constructs a <CODE>List</CODE>. * Constructs a <CODE>List</CODE>.
* @param numbered a boolean * @param numbered a boolean
*/ */
public List(boolean numbered) { public List(boolean numbered) {
this(numbered, false); this(numbered, false);
} }
/** /**
* Constructs a <CODE>List</CODE>. * Constructs a <CODE>List</CODE>.
* @param numbered a boolean * @param numbered a boolean
* @param lettered has the list to be 'numbered' with letters * @param lettered has the list to be 'numbered' with letters
*/ */
public List(boolean numbered, boolean lettered) { public List(boolean numbered, boolean lettered) {
this.numbered = numbered; this.numbered = numbered;
this.lettered = lettered; this.lettered = lettered;
this.autoindent = true; this.autoindent = true;
this.alignindent = true; this.alignindent = true;
} }
/** /**
* Constructs a <CODE>List</CODE>. * Constructs a <CODE>List</CODE>.
* <P> * <P>
@ -203,7 +212,7 @@ public class List implements TextElementArray {
public List(boolean numbered, float symbolIndent) { public List(boolean numbered, float symbolIndent) {
this(numbered, false, symbolIndent); this(numbered, false, symbolIndent);
} }
/** /**
* Creates a list * Creates a list
* @param numbered has the list to be numbered? * @param numbered has the list to be numbered?
@ -215,9 +224,9 @@ public class List implements TextElementArray {
this.lettered = lettered; this.lettered = lettered;
this.symbolIndent = symbolIndent; this.symbolIndent = symbolIndent;
} }
// implementation of the Element-methods // implementation of the Element-methods
/** /**
* Processes the element by adding it (or the different parts) to an * Processes the element by adding it (or the different parts) to an
* <CODE>ElementListener</CODE>. * <CODE>ElementListener</CODE>.
@ -236,16 +245,16 @@ public class List implements TextElementArray {
return false; return false;
} }
} }
/** /**
* Gets the type of the text element. * Gets the type of the text element.
* *
* @return a type * @return a type
*/ */
public int type() { public int type() {
return Element.LIST; return LIST;
} }
/** /**
* Gets all the chunks in this element. * Gets all the chunks in this element.
* *
@ -258,9 +267,9 @@ public class List implements TextElementArray {
} }
return tmp; return tmp;
} }
// methods to set the membervariables // methods to set the membervariables
/** /**
* Adds an <CODE>Object</CODE> to the <CODE>List</CODE>. * Adds an <CODE>Object</CODE> to the <CODE>List</CODE>.
* *
@ -287,8 +296,8 @@ public class List implements TextElementArray {
item.setIndentationRight(0); item.setIndentationRight(0);
return list.add(item); return list.add(item);
} }
else if (o instanceof List) { else if (o instanceof com.fr.third.com.lowagie.text.List) {
List nested = (List) o; com.fr.third.com.lowagie.text.List nested = (com.fr.third.com.lowagie.text.List) o;
nested.setIndentationLeft(nested.getIndentationLeft() + symbolIndent); nested.setIndentationLeft(nested.getIndentationLeft() + symbolIndent);
first--; first--;
return list.add(nested); return list.add(nested);
@ -298,63 +307,63 @@ public class List implements TextElementArray {
} }
return false; return false;
} }
// extra methods // extra methods
/** Makes sure all the items in the list have the same indentation. */ /** Makes sure all the items in the list have the same indentation. */
public void normalizeIndentation() { public void normalizeIndentation() {
float max = 0; float max = 0;
Element o; Element o;
for (Iterator i = list.iterator(); i.hasNext(); ) { for (Iterator i = list.iterator(); i.hasNext(); ) {
o = (Element)i.next(); o = (Element)i.next();
if (o instanceof ListItem) { if (o instanceof ListItem) {
max = Math.max(max, ((ListItem)o).getIndentationLeft()); max = Math.max(max, ((ListItem)o).getIndentationLeft());
} }
} }
for (Iterator i = list.iterator(); i.hasNext(); ) { for (Iterator i = list.iterator(); i.hasNext(); ) {
o = (Element)i.next(); o = (Element)i.next();
if (o instanceof ListItem) { if (o instanceof ListItem) {
((ListItem)o).setIndentationLeft(max); ((ListItem)o).setIndentationLeft(max);
} }
} }
} }
// setters // setters
/** /**
* @param numbered the numbered to set * @param numbered the numbered to set
*/ */
public void setNumbered(boolean numbered) { public void setNumbered(boolean numbered) {
this.numbered = numbered; this.numbered = numbered;
} }
/** /**
* @param lettered the lettered to set * @param lettered the lettered to set
*/ */
public void setLettered(boolean lettered) { public void setLettered(boolean lettered) {
this.lettered = lettered; this.lettered = lettered;
} }
/** /**
* @param uppercase the uppercase to set * @param uppercase the uppercase to set
*/ */
public void setLowercase(boolean uppercase) { public void setLowercase(boolean uppercase) {
this.lowercase = uppercase; this.lowercase = uppercase;
} }
/** /**
* @param autoindent the autoindent to set * @param autoindent the autoindent to set
*/ */
public void setAutoindent(boolean autoindent) { public void setAutoindent(boolean autoindent) {
this.autoindent = autoindent; this.autoindent = autoindent;
} }
/** /**
* @param alignindent the alignindent to set * @param alignindent the alignindent to set
*/ */
public void setAlignindent(boolean alignindent) { public void setAlignindent(boolean alignindent) {
this.alignindent = alignindent; this.alignindent = alignindent;
} }
/** /**
* Sets the number that has to come first in the list. * Sets the number that has to come first in the list.
* *
@ -363,7 +372,7 @@ public class List implements TextElementArray {
public void setFirst(int first) { public void setFirst(int first) {
this.first = first; this.first = first;
} }
/** /**
* Sets the listsymbol. * Sets the listsymbol.
* *
@ -372,7 +381,7 @@ public class List implements TextElementArray {
public void setListSymbol(Chunk symbol) { public void setListSymbol(Chunk symbol) {
this.symbol = symbol; this.symbol = symbol;
} }
/** /**
* Sets the listsymbol. * Sets the listsymbol.
* <P> * <P>
@ -383,7 +392,7 @@ public class List implements TextElementArray {
public void setListSymbol(String symbol) { public void setListSymbol(String symbol) {
this.symbol = new Chunk(symbol); this.symbol = new Chunk(symbol);
} }
/** /**
* Sets the indentation of this paragraph on the left side. * Sets the indentation of this paragraph on the left side.
* *
@ -392,7 +401,7 @@ public class List implements TextElementArray {
public void setIndentationLeft(float indentation) { public void setIndentationLeft(float indentation) {
this.indentationLeft = indentation; this.indentationLeft = indentation;
} }
/** /**
* Sets the indentation of this paragraph on the right side. * Sets the indentation of this paragraph on the right side.
* *
@ -402,15 +411,15 @@ public class List implements TextElementArray {
this.indentationRight = indentation; this.indentationRight = indentation;
} }
/** /**
* @param symbolIndent the symbolIndent to set * @param symbolIndent the symbolIndent to set
*/ */
public void setSymbolIndent(float symbolIndent) { public void setSymbolIndent(float symbolIndent) {
this.symbolIndent = symbolIndent; this.symbolIndent = symbolIndent;
} }
// methods to retrieve information // methods to retrieve information
/** /**
* Gets all the items in the list. * Gets all the items in the list.
* *
@ -419,7 +428,7 @@ public class List implements TextElementArray {
public ArrayList getItems() { public ArrayList getItems() {
return list; return list;
} }
/** /**
* Gets the size of the list. * Gets the size of the list.
* *
@ -431,11 +440,11 @@ public class List implements TextElementArray {
/** /**
* Returns <CODE>true</CODE> if the list is empty. * Returns <CODE>true</CODE> if the list is empty.
* *
* @return <CODE>true</CODE> if the list is empty * @return <CODE>true</CODE> if the list is empty
*/ */
public boolean isEmpty() { public boolean isEmpty() {
return list.isEmpty(); return list.isEmpty();
} }
/** /**
@ -450,14 +459,14 @@ public class List implements TextElementArray {
ListItem item = (ListItem) list.get(0); ListItem item = (ListItem) list.get(0);
return item.getTotalLeading(); return item.getTotalLeading();
} }
// getters // getters
/** /**
* Checks if the list is numbered. * Checks if the list is numbered.
* @return <CODE>true</CODE> if the list is numbered, <CODE>false</CODE> otherwise. * @return <CODE>true</CODE> if the list is numbered, <CODE>false</CODE> otherwise.
*/ */
public boolean isNumbered() { public boolean isNumbered() {
return numbered; return numbered;
} }
@ -477,112 +486,112 @@ public class List implements TextElementArray {
public boolean isLowercase() { public boolean isLowercase() {
return lowercase; return lowercase;
} }
/** /**
* Checks if the indentation of list items is done automatically. * Checks if the indentation of list items is done automatically.
* @return the autoindent * @return the autoindent
*/ */
public boolean isAutoindent() { public boolean isAutoindent() {
return autoindent; return autoindent;
} }
/** /**
* Checks if all the listitems should be aligned. * Checks if all the listitems should be aligned.
* @return the alignindent * @return the alignindent
*/ */
public boolean isAlignindent() { public boolean isAlignindent() {
return alignindent; return alignindent;
} }
/** /**
* Gets the first number . * Gets the first number .
* @return a number * @return a number
*/ */
public int getFirst() { public int getFirst() {
return first; return first;
} }
/** /**
* Gets the Chunk containing the symbol. * Gets the Chunk containing the symbol.
* @return a Chunk with a symbol * @return a Chunk with a symbol
*/ */
public Chunk getSymbol() { public Chunk getSymbol() {
return symbol; return symbol;
} }
/** /**
* Gets the indentation of this paragraph on the left side. * Gets the indentation of this paragraph on the left side.
* @return the indentation * @return the indentation
*/ */
public float getIndentationLeft() { public float getIndentationLeft() {
return indentationLeft; return indentationLeft;
} }
/** /**
* Gets the indentation of this paragraph on the right side. * Gets the indentation of this paragraph on the right side.
* @return the indentation * @return the indentation
*/ */
public float getIndentationRight() { public float getIndentationRight() {
return indentationRight; return indentationRight;
} }
/** /**
* Gets the symbol indentation. * Gets the symbol indentation.
* @return the symbol indentation * @return the symbol indentation
*/ */
public float getSymbolIndent() { public float getSymbolIndent() {
return symbolIndent; return symbolIndent;
} }
/** /**
* @see com.fr.third.com.lowagie.text.Element#isContent() * @see Element#isContent()
* @since iText 2.0.8 * @since iText 2.0.8
*/ */
public boolean isContent() { public boolean isContent() {
return true; return true;
} }
/** /**
* @see com.fr.third.com.lowagie.text.Element#isNestable() * @see Element#isNestable()
* @since iText 2.0.8 * @since iText 2.0.8
*/ */
public boolean isNestable() { public boolean isNestable() {
return true; return true;
} }
/** /**
* Returns the String that is after a number or letter in the list symbol. * Returns the String that is after a number or letter in the list symbol.
* @return the String that is after a number or letter in the list symbol * @return the String that is after a number or letter in the list symbol
* @since iText 2.1.1 * @since iText 2.1.1
*/ */
public String getPostSymbol() { public String getPostSymbol() {
return postSymbol; return postSymbol;
} }
/** /**
* Sets the String that has to be added after a number or letter in the list symbol. * Sets the String that has to be added after a number or letter in the list symbol.
* @since iText 2.1.1 * @since iText 2.1.1
* @param postSymbol the String that has to be added after a number or letter in the list symbol. * @param postSymbol the String that has to be added after a number or letter in the list symbol.
*/ */
public void setPostSymbol(String postSymbol) { public void setPostSymbol(String postSymbol) {
this.postSymbol = postSymbol; this.postSymbol = postSymbol;
} }
/** /**
* Returns the String that is before a number or letter in the list symbol. * Returns the String that is before a number or letter in the list symbol.
* @return the String that is before a number or letter in the list symbol * @return the String that is before a number or letter in the list symbol
* @since iText 2.1.1 * @since iText 2.1.1
*/ */
public String getPreSymbol() { public String getPreSymbol() {
return preSymbol; return preSymbol;
} }
/** /**
* Sets the String that has to be added before a number or letter in the list symbol. * Sets the String that has to be added before a number or letter in the list symbol.
* @since iText 2.1.1 * @since iText 2.1.1
* @param preSymbol the String that has to be added before a number or letter in the list symbol. * @param preSymbol the String that has to be added before a number or letter in the list symbol.
*/ */
public void setPreSymbol(String preSymbol) { public void setPreSymbol(String preSymbol) {
this.preSymbol = preSymbol; this.preSymbol = preSymbol;
} }
} }

140
fine-itext-old/src/com/fr/third/com/lowagie/text/Paragraph.java

@ -49,6 +49,8 @@
package com.fr.third.com.lowagie.text; package com.fr.third.com.lowagie.text;
import java.util.HashMap;
/** /**
* A <CODE>Paragraph</CODE> is a series of <CODE>Chunk</CODE>s and/or <CODE>Phrases</CODE>. * A <CODE>Paragraph</CODE> is a series of <CODE>Chunk</CODE>s and/or <CODE>Phrases</CODE>.
* <P> * <P>
@ -72,13 +74,13 @@ package com.fr.third.com.lowagie.text;
public class Paragraph extends Phrase { public class Paragraph extends Phrase {
// constants // constants
private static final long serialVersionUID = 7852314969733375514L; private static final long serialVersionUID = 7852314969733375514L;
// membervariables // membervariables
/** The alignment of the text. */ /** The alignment of the text. */
protected int alignment = Element.ALIGN_UNDEFINED; protected int alignment = ALIGN_UNDEFINED;
/** The text leading that is multiplied by the biggest font size in the line. */ /** The text leading that is multiplied by the biggest font size in the line. */
protected float multipliedLeading = 0; protected float multipliedLeading = 0;
@ -106,6 +108,22 @@ public class Paragraph extends Phrase {
protected String background; protected String background;
protected HashMap attributes = new HashMap();
public HashMap getAttributes() {
return attributes;
}
public void setAttributes(HashMap attributes) {
this.attributes = attributes;
}
public void setAttribute(String name, Object obj) {
if (attributes == null)
attributes = new HashMap();
attributes.put(name, obj);
}
// constructors // constructors
/** /**
@ -195,15 +213,15 @@ public class Paragraph extends Phrase {
public Paragraph(Phrase phrase) { public Paragraph(Phrase phrase) {
super(phrase); super(phrase);
if (phrase instanceof Paragraph) { if (phrase instanceof Paragraph) {
Paragraph p = (Paragraph)phrase; Paragraph p = (Paragraph)phrase;
setAlignment(p.alignment); setAlignment(p.alignment);
setLeading(phrase.getLeading(), p.multipliedLeading); setLeading(phrase.getLeading(), p.multipliedLeading);
setIndentationLeft(p.getIndentationLeft()); setIndentationLeft(p.getIndentationLeft());
setIndentationRight(p.getIndentationRight()); setIndentationRight(p.getIndentationRight());
setFirstLineIndent(p.getFirstLineIndent()); setFirstLineIndent(p.getFirstLineIndent());
setSpacingAfter(p.spacingAfter()); setSpacingAfter(p.spacingAfter());
setSpacingBefore(p.spacingBefore()); setSpacingBefore(p.spacingBefore());
setExtraParagraphSpace(p.getExtraParagraphSpace()); setExtraParagraphSpace(p.getExtraParagraphSpace());
} }
} }
@ -215,7 +233,7 @@ public class Paragraph extends Phrase {
* @return a type * @return a type
*/ */
public int type() { public int type() {
return Element.PARAGRAPH; return PARAGRAPH;
} }
// methods // methods
@ -241,11 +259,11 @@ public class Paragraph extends Phrase {
super.add(o); super.add(o);
java.util.List chunks = getChunks(); java.util.List chunks = getChunks();
if (!chunks.isEmpty()) { if (!chunks.isEmpty()) {
Chunk tmp = ((Chunk) chunks.get(chunks.size() - 1)); Chunk tmp = ((Chunk) chunks.get(chunks.size() - 1));
super.add(new Chunk("\n", tmp.getFont())); super.add(new Chunk("\n", tmp.getFont()));
} }
else { else {
super.add(Chunk.NEWLINE); super.add(Chunk.NEWLINE);
} }
return true; return true;
} }
@ -270,32 +288,32 @@ public class Paragraph extends Phrase {
*/ */
public void setAlignment(String alignment) { public void setAlignment(String alignment) {
if (ElementTags.ALIGN_CENTER.equalsIgnoreCase(alignment)) { if (ElementTags.ALIGN_CENTER.equalsIgnoreCase(alignment)) {
this.alignment = Element.ALIGN_CENTER; this.alignment = ALIGN_CENTER;
return; return;
} }
if (ElementTags.ALIGN_RIGHT.equalsIgnoreCase(alignment)) { if (ElementTags.ALIGN_RIGHT.equalsIgnoreCase(alignment)) {
this.alignment = Element.ALIGN_RIGHT; this.alignment = ALIGN_RIGHT;
return; return;
} }
if (ElementTags.ALIGN_JUSTIFIED.equalsIgnoreCase(alignment)) { if (ElementTags.ALIGN_JUSTIFIED.equalsIgnoreCase(alignment)) {
this.alignment = Element.ALIGN_JUSTIFIED; this.alignment = ALIGN_JUSTIFIED;
return; return;
} }
if (ElementTags.ALIGN_JUSTIFIED_ALL.equalsIgnoreCase(alignment)) { if (ElementTags.ALIGN_JUSTIFIED_ALL.equalsIgnoreCase(alignment)) {
this.alignment = Element.ALIGN_JUSTIFIED_ALL; this.alignment = ALIGN_JUSTIFIED_ALL;
return; return;
} }
this.alignment = Element.ALIGN_LEFT; this.alignment = ALIGN_LEFT;
} }
/** /**
* @see com.fr.third.com.lowagie.text.Phrase#setLeading(float) * @see Phrase#setLeading(float)
*/ */
public void setLeading(float fixedLeading) { public void setLeading(float fixedLeading) {
this.leading = fixedLeading; this.leading = fixedLeading;
this.multipliedLeading = 0; this.multipliedLeading = 0;
} }
/** /**
* Sets the variable leading. The resultant leading will be * Sets the variable leading. The resultant leading will be
* multipliedLeading*maxFontSize where maxFontSize is the * multipliedLeading*maxFontSize where maxFontSize is the
@ -306,7 +324,7 @@ public class Paragraph extends Phrase {
this.leading = 0; this.leading = 0;
this.multipliedLeading = multipliedLeading; this.multipliedLeading = multipliedLeading;
} }
/** /**
* Sets the leading fixed and variable. The resultant leading will be * Sets the leading fixed and variable. The resultant leading will be
* fixedLeading+multipliedLeading*maxFontSize where maxFontSize is the * fixedLeading+multipliedLeading*maxFontSize where maxFontSize is the
@ -318,7 +336,7 @@ public class Paragraph extends Phrase {
this.leading = fixedLeading; this.leading = fixedLeading;
this.multipliedLeading = multipliedLeading; this.multipliedLeading = multipliedLeading;
} }
/** /**
* Sets the indentation of this paragraph on the left side. * Sets the indentation of this paragraph on the left side.
* *
@ -327,7 +345,7 @@ public class Paragraph extends Phrase {
public void setIndentationLeft(float indentation) { public void setIndentationLeft(float indentation) {
this.indentationLeft = indentation; this.indentationLeft = indentation;
} }
/** /**
* Sets the indentation of this paragraph on the right side. * Sets the indentation of this paragraph on the right side.
* *
@ -336,7 +354,7 @@ public class Paragraph extends Phrase {
public void setIndentationRight(float indentation) { public void setIndentationRight(float indentation) {
this.indentationRight = indentation; this.indentationRight = indentation;
} }
/** /**
* Setter for property firstLineIndent. * Setter for property firstLineIndent.
* @param firstLineIndent New value of property firstLineIndent. * @param firstLineIndent New value of property firstLineIndent.
@ -344,7 +362,7 @@ public class Paragraph extends Phrase {
public void setFirstLineIndent(float firstLineIndent) { public void setFirstLineIndent(float firstLineIndent) {
this.firstLineIndent = firstLineIndent; this.firstLineIndent = firstLineIndent;
} }
/** /**
* Sets the spacing before this paragraph. * Sets the spacing before this paragraph.
* *
@ -353,7 +371,7 @@ public class Paragraph extends Phrase {
public void setSpacingBefore(float spacing) { public void setSpacingBefore(float spacing) {
this.spacingBefore = spacing; this.spacingBefore = spacing;
} }
/** /**
* Sets the spacing after this paragraph. * Sets the spacing after this paragraph.
* *
@ -362,7 +380,7 @@ public class Paragraph extends Phrase {
public void setSpacingAfter(float spacing) { public void setSpacingAfter(float spacing) {
this.spacingAfter = spacing; this.spacingAfter = spacing;
} }
/** /**
* Indicates that the paragraph has to be kept together on one page. * Indicates that the paragraph has to be kept together on one page.
* *
@ -371,7 +389,7 @@ public class Paragraph extends Phrase {
public void setKeepTogether(boolean keeptogether) { public void setKeepTogether(boolean keeptogether) {
this.keeptogether = keeptogether; this.keeptogether = keeptogether;
} }
/** /**
* Checks if this paragraph has to be kept together on one page. * Checks if this paragraph has to be kept together on one page.
* *
@ -383,7 +401,7 @@ public class Paragraph extends Phrase {
// methods to retrieve information // methods to retrieve information
/** /**
* Gets the alignment of this paragraph. * Gets the alignment of this paragraph.
* *
* @return alignment * @return alignment
@ -391,7 +409,7 @@ public class Paragraph extends Phrase {
public int getAlignment() { public int getAlignment() {
return alignment; return alignment;
} }
/** /**
* Gets the variable leading * Gets the variable leading
* @return the leading * @return the leading
@ -399,7 +417,7 @@ public class Paragraph extends Phrase {
public float getMultipliedLeading() { public float getMultipliedLeading() {
return multipliedLeading; return multipliedLeading;
} }
/** /**
* Gets the total leading. * Gets the total leading.
* This method is based on the assumption that the * This method is based on the assumption that the
@ -409,15 +427,15 @@ public class Paragraph extends Phrase {
* @return the total leading (fixed and multiplied) * @return the total leading (fixed and multiplied)
*/ */
public float getTotalLeading() { public float getTotalLeading() {
float m = font == null ? float m = font == null ?
Font.DEFAULTSIZE * multipliedLeading : font.getCalculatedLeading(multipliedLeading); Font.DEFAULTSIZE * multipliedLeading : font.getCalculatedLeading(multipliedLeading);
if (m > 0 && !hasLeading()) { if (m > 0 && !hasLeading()) {
return m; return m;
} }
return getLeading() + m; return getLeading() + m;
} }
/** /**
* Gets the indentation of this paragraph on the left side. * Gets the indentation of this paragraph on the left side.
* *
* @return the indentation * @return the indentation
@ -426,15 +444,15 @@ public class Paragraph extends Phrase {
return indentationLeft; return indentationLeft;
} }
/** /**
* Gets the indentation of this paragraph on the right side. * Gets the indentation of this paragraph on the right side.
* *
* @return the indentation * @return the indentation
*/ */
public float getIndentationRight() { public float getIndentationRight() {
return indentationRight; return indentationRight;
} }
/** /**
* Getter for property firstLineIndent. * Getter for property firstLineIndent.
* @return Value of property firstLineIndent. * @return Value of property firstLineIndent.
@ -442,25 +460,25 @@ public class Paragraph extends Phrase {
public float getFirstLineIndent() { public float getFirstLineIndent() {
return this.firstLineIndent; return this.firstLineIndent;
} }
/** /**
* Gets the spacing before this paragraph. * Gets the spacing before this paragraph.
* @return the spacing * @return the spacing
* @since 2.1.5 * @since 2.1.5
*/ */
public float getSpacingBefore() { public float getSpacingBefore() {
return spacingBefore; return spacingBefore;
} }
/** /**
* Gets the spacing after this paragraph. * Gets the spacing after this paragraph.
* @return the spacing * @return the spacing
* @since 2.1.5 * @since 2.1.5
*/ */
public float getSpacingAfter() { public float getSpacingAfter() {
return spacingAfter; return spacingAfter;
} }
/** /**
* Getter for property extraParagraphSpace. * Getter for property extraParagraphSpace.
* @return Value of property extraParagraphSpace. * @return Value of property extraParagraphSpace.
@ -468,7 +486,7 @@ public class Paragraph extends Phrase {
public float getExtraParagraphSpace() { public float getExtraParagraphSpace() {
return this.extraParagraphSpace; return this.extraParagraphSpace;
} }
/** /**
* Setter for property extraParagraphSpace. * Setter for property extraParagraphSpace.
* @param extraParagraphSpace New value of property extraParagraphSpace. * @param extraParagraphSpace New value of property extraParagraphSpace.
@ -476,9 +494,9 @@ public class Paragraph extends Phrase {
public void setExtraParagraphSpace(float extraParagraphSpace) { public void setExtraParagraphSpace(float extraParagraphSpace) {
this.extraParagraphSpace = extraParagraphSpace; this.extraParagraphSpace = extraParagraphSpace;
} }
// scheduled for removal // scheduled for removal
/** /**
* Gets the spacing before this paragraph. * Gets the spacing before this paragraph.
* *
@ -508,5 +526,5 @@ public class Paragraph extends Phrase {
public String getBackground(){ public String getBackground(){
return this.background; return this.background;
} }
} }

2
fine-itext-old/src/com/fr/third/com/lowagie/text/factories/ElementFactory.java

@ -135,7 +135,7 @@ public class ElementFactory {
} }
value = attributes.getProperty(ElementTags.BACKGROUNDCOLOR); value = attributes.getProperty(ElementTags.BACKGROUNDCOLOR);
if (value != null) { if (value != null) {
chunk.setBackground(Markup.decodeColor(value)); chunk.setBackground(value);
} }
return chunk; return chunk;
} }

200
fine-itext-old/src/com/fr/third/com/lowagie/text/html/CSS.java

@ -0,0 +1,200 @@
package com.fr.third.com.lowagie.text.html;
/**
* @author kerry
* @date 2018/5/11
*/
public class CSS {
public final class Value {
private Value(){};
public static final String THIN = "thin";
public static final String MEDIUM = "medium";
public static final String THICK = "thick";
public static final String NONE = "none";
public static final String HIDDEN = "hidden";
public static final String DOTTED = "dotted";
public static final String DASHED = "dashed";
public static final String SOLID = "solid";
public static final String DOUBLE = "double";
public static final String GROOVE = "groove";
public static final String RIDGE = "ridge";
public static final String INSET = "inset";
public static final String OUTSET = "outset";
public static final String LEFT = "left";
public static final String CENTER = "center";
public static final String JUSTIFY = "justify";
public static final String BOTTOM = "bottom";
public static final String TOP = "top";
public static final String RIGHT = "right";
public static final String REPEAT = "repeat";
public static final String NO_REPEAT = "no-repeat";
public static final String REPEAT_X = "repeat-x";
public static final String REPEAT_Y = "repeat-y";
public static final String FIXED = "fixed";
public static final String SCROLL = "scroll";
public static final String DISC = "disc";
public static final String SQUARE = "square";
public static final String CIRCLE = "circle";
public static final String DECIMAL = "decimal";
public static final String LOWER_ROMAN = "lower-roman";
public static final String UPPER_ROMAN = "upper-roman";
public static final String LOWER_GREEK = "lower-greek";
public static final String UPPER_GREEK = "upper-greek";
public static final String LOWER_ALPHA = "lower-alpha";
public static final String UPPER_ALPHA = "upper-alpha";
public static final String LOWER_LATIN = "lower-latin";
public static final String UPPER_LATIN = "upper-latin";
public static final String INSIDE = "inside";
public static final String OUTSIDE = "outside";
public static final String INHERIT = "inherit";
public static final String UNDERLINE = "underline";
public static final String BOLD = "bold";
public static final String ITALIC = "italic";
public static final String OBLIQUE = "oblique";
public static final String SUPER = "super";
public static final String SUB = "sub";
public static final String TEXT_TOP = "text-top";
public static final String TEXT_BOTTOM = "text-bottom";
public static final String LINE_THROUGH = "line-through";
public static final String RELATIVE = "relative";
public static final String HIDE = "hide";
public static final String XX_SMALL = "xx-small";
public static final String X_SMALL = "x-small";
public static final String SMALL = "small";
public static final String LARGE = "large";
public static final String X_LARGE = "x-large";
public static final String XX_LARGE = "xx-large";
public static final String SMALLER = "smaller";
public static final String LARGER = "larger";
public static final String PX = "px";
public static final String IN = "in";
public static final String CM = "cm";
public static final String MM = "mm";
public static final String PT = "pt";
public static final String PC = "pc";
public static final String PERCENTAGE = "%";
public static final String EM = "em";
public static final String EX = "ex";
public static final String ALWAYS = "always";
public static final String AVOID = "avoid";
public static final String ABSOLUTE = "absolute";
public static final String AUTO = "auto";
public static final String INLINE = "inline";
public static final String BLOCK = "block";
public static final String SEPARATE = "separate";
public static final String COLLAPSE = "collapse";
public static final String RTL = "rtl";
public static final String LTR = "ltr";
public static final String INLINE_BLOCK = "inline-block";
public static final String INLINE_TABLE = "inline-table";
public static final String LIST_ITEM = "list-item";
public static final String RUN_IN = "run-in";
public static final String TABLE = "table";
public static final String TABLE_CAPTION = "table-caption";
public static final String TABLE_CELL = "table-cell";
public static final String TABLE_COLUMN_GROUP = "table-column-group";
public static final String TABLE_COLUMN = "table-column";
public static final String TABLE_FOOTER_GROUP = "table-footer-group";
public static final String TABLE_HEADER_GROUP = "table-header-group";
public static final String TABLE_ROW = "table-row";
public static final String TABLE_ROW_GROUP = "table-row-group";
}
public final class Property {
private Property() {};
public static final String BACKGROUND = "background";
public static final String BACKGROUND_IMAGE = "background-image";
public static final String BACKGROUND_REPEAT = "background-repeat";
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";
public static final String LIST_STYLE_IMAGE = "list-style-image";
public static final String MARGIN = "margin";
public static final String TOP = "top";
public static final String MARGIN_LEFT = "margin-left";
public static final String MARGIN_RIGHT = "margin-right";
public static final String MARGIN_TOP = "margin-top";
public static final String MARGIN_BOTTOM = "margin-bottom";
public static final String BORDER = "border";
public static final String BORDER_LEFT = "border-left";
public static final String BORDER_TOP = "border-top";
public static final String BORDER_RIGHT = "border-right";
public static final String BORDER_BOTTOM = "border-bottom";
public static final String BORDER_WIDTH = "border-width";
public static final String BORDER_STYLE = "border-style";
public static final String BORDER_COLOR = "border-color";
public static final String BORDER_COLLAPSE = "border-collapse";
public static final String BORDER_SPACING = "border-spacing";
public static final String BORDER_TOP_WIDTH = "border-top-width";
public static final String BORDER_BOTTOM_WIDTH = "border-bottom-width";
public static final String BORDER_LEFT_WIDTH = "border-left-width";
public static final String BORDER_RIGHT_WIDTH = "border-right-width";
public static final String BORDER_TOP_COLOR = "border-top-color";
public static final String BORDER_BOTTOM_COLOR = "border-bottom-color";
public static final String BORDER_LEFT_COLOR = "border-left-color";
public static final String BORDER_RIGHT_COLOR = "border-right-color";
public static final String BORDER_TOP_STYLE = "border-top-style";
public static final String BORDER_BOTTOM_STYLE = "border-bottom-style";
public static final String BORDER_LEFT_STYLE = "border-left-style";
public static final String BORDER_RIGHT_STYLE = "border-right-style";
public static final String PADDING = "padding";
public static final String PADDING_TOP = "padding-top";
public static final String PADDING_BOTTOM = "padding-bottom";
public static final String PADDING_LEFT = "padding-left";
public static final String PADDING_RIGHT = "padding-right";
public static final String FONT = "font";
public static final String FONT_WEIGHT = "font-weight";
public static final String FONT_SIZE = "font-size";
public static final String FONT_STYLE = "font-style";
public static final String FONT_FAMILY = "font-family";
public static final String TEXT_DECORATION = "text-decoration";
public static final String COLOR = "color";
public static final String TAB_INTERVAL = "tab-interval";
public static final String XFA_TAB_COUNT = "xfa-tab-count";
public static final String XFA_FONT_HORIZONTAL_SCALE = "xfa-font-horizontal-scale";
public static final String XFA_FONT_VERTICAL_SCALE = "xfa-font-vertical-scale";
public static final String BEFORE = "before";
public static final String AFTER = "after";
public static final String HEIGHT = "height";
public static final String WIDTH = "width";
public static final String LETTER_SPACING = "letter-spacing";
public static final String VERTICAL_ALIGN = "vertical-align";
public static final String LINE_HEIGHT = "line-height";
public static final String TEXT_ALIGN = "text-align";
public static final String TEXT_VALIGN = "text-valign";
public static final String TEXT_INDENT = "text-indent";
public static final String POSITION = "position";
public static final String EMPTY_CELLS = "empty-cells";
public static final String CELLPADDING = "cellpadding";
//deprecated
public static final String CELLPADDING_LEFT = "cellpadding-left";
public static final String CELLPADDING_TOP = "cellpadding-top";
public static final String CELLPADDING_RIGHT = "cellpadding-right";
public static final String CELLPADDING_BOTTOM = "cellpadding-bottom";
public static final String CAPTION_SIDE = "caption-side";
public static final String TAB_STOPS = "tab-stops";
public static final String XFA_TAB_STOPS = "xfa-tab-stops";
public static final String PAGE_BREAK_BEFORE = "page-break-before";
public static final String PAGE_BREAK_INSIDE = "page-break-inside";
public static final String PAGE_BREAK_AFTER = "page-break-after";
public static final String REPEAT_HEADER = "repeat-header";
public static final String REPEAT_FOOTER = "repeat-footer";
public static final String LEFT = "left";
public static final String DISPLAY = "display";
public static final String MIN_WIDTH = "min-width";
public static final String MAX_WIDTH = "max-width";
public static final String MIN_HEIGHT = "min-height";
public static final String MAX_HEIGHT = "max-height";
public static final String RIGHT = "right";
public static final String BOTTOM = "bottom";
public static final String FLOAT = "float";
public static final String DIRECTION = "direction";
}
}

108
fine-itext-old/src/com/fr/third/com/lowagie/text/html/CSSUtils.java

@ -0,0 +1,108 @@
package com.fr.third.com.lowagie.text.html;
import com.fr.third.com.lowagie.text.html.CSS;
import com.fr.third.com.lowagie.text.html.WebColors;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* @author kerry
* @date 2018/4/9
*/
public class CSSUtils {
private static final Set<String> backgroundPositions = new HashSet<String>(
Arrays.asList(new String[] { CSS.Value.LEFT, CSS.Value.CENTER, CSS.Value.BOTTOM, CSS.Value.TOP, CSS.Value.RIGHT }));
public static Map<String, String> processBackground(final String background) {
Map<String, String> rules = new HashMap<String, String>();
String[] styles = splitComplexCssStyle(background);
for(String style : styles) {
if (style.contains("url(")) {
rules.put(CSS.Property.BACKGROUND_IMAGE, style);
} else if (style.equalsIgnoreCase(CSS.Value.REPEAT)
|| style.equalsIgnoreCase(CSS.Value.NO_REPEAT)
|| style.equalsIgnoreCase(CSS.Value.REPEAT_X)
|| style.equalsIgnoreCase(CSS.Value.REPEAT_Y)) {
rules.put(CSS.Property.BACKGROUND_REPEAT, style);
} else if (style.equalsIgnoreCase(CSS.Value.FIXED) || style.equalsIgnoreCase(CSS.Value.SCROLL)) {
rules.put(CSS.Property.BACKGROUND_ATTACHMENT, style);
} else if (backgroundPositions.contains(style)) {
if(rules.get(CSS.Property.BACKGROUND_POSITION) == null) {
rules.put(CSS.Property.BACKGROUND_POSITION, style);
} else {
style = style.concat(" "+rules.get(CSS.Property.BACKGROUND_POSITION));
rules.put(CSS.Property.BACKGROUND_POSITION, style);
}
} else if (isNumericValue(style) || isMetricValue(style) || isRelativeValue(style)) {
if(rules.get(CSS.Property.BACKGROUND_POSITION) == null) {
rules.put(CSS.Property.BACKGROUND_POSITION, style);
} else {
style = style.concat(" "+rules.get(CSS.Property.BACKGROUND_POSITION));
rules.put(CSS.Property.BACKGROUND_POSITION, style);
}
} else if(style.contains("rgb(") || style.contains("rgba(") || style.contains("#") || WebColors.NAMES.containsKey(style.toLowerCase())) {
rules.put(CSS.Property.BACKGROUND_COLOR, style);
}
}
return rules;
}
public static String[] splitComplexCssStyle(String s) {
s = s.replaceAll("\\s*,\\s*", ",") ;
return s.split("\\s");
}
public static boolean isMetricValue(final String value) {
return value.contains(CSS.Value.PX) || value.contains(CSS.Value.IN) || value.contains(CSS.Value.CM)
|| value.contains(CSS.Value.MM) || value.contains(CSS.Value.PC) || value.contains(CSS.Value.PT);
}
public static boolean isRelativeValue(final String value) {
return value.contains(CSS.Value.PERCENTAGE) || value.contains(CSS.Value.EM) || value.contains(CSS.Value.EX);
}
public static boolean isNumericValue(final String value) {
return value.matches("^-?\\d\\d*\\.\\d*$") || value.matches("^-?\\d\\d*$") || value.matches("^-?\\.\\d\\d*$");
}
public static String extractUrl(final String url) {
String str = null;
if (url.startsWith("url")) {
String urlString = url.substring(3).trim().replace("(", "").replace(")", "").trim();
if (urlString.startsWith("'") && urlString.endsWith("'")) {
str = urlString.substring(urlString.indexOf("'")+1, urlString.lastIndexOf("'"));
} else if ( urlString.startsWith("\"") && urlString.endsWith("\"") ) {
str = urlString.substring(urlString.indexOf('"')+1, urlString.lastIndexOf('"'));
} else {
str = urlString;
}
} else {
str = url;
}
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;
}
}

55
fine-itext-old/src/com/fr/third/com/lowagie/text/html/IndentAttribute.java

@ -0,0 +1,55 @@
package com.fr.third.com.lowagie.text.html;
/**
* @author kerry
* @date 2018/5/9
*/
public class IndentAttribute {
private float top = 0.0f;
private float bottom = 0.0f;
private float left = 0.0f;
private float right = 0.0f;
public float getTop() {
return top;
}
public void setTop(float top) {
this.top = top;
}
public float getBottom() {
return bottom;
}
public void setBottom(float bottom) {
this.bottom = bottom;
}
public float getLeft() {
return left;
}
public void setLeft(float left) {
this.left = left;
}
public float getRight() {
return right;
}
public void setRight(float right) {
this.right = right;
}
public IndentAttribute(float top, float left, float bottom, float right){
this.top = top;
this.left = left;
this.bottom = bottom;
this.right = right;
}
public IndentAttribute(){
}
}

139
fine-itext-old/src/com/fr/third/com/lowagie/text/html/Markup.java

@ -44,7 +44,7 @@
* *
* Contributions by: * Contributions by:
* Lubos Strapko * Lubos Strapko
* *
* If you didn't download this code from the following link, you should check if * If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version: * you aren't using an obsolete version:
* http://www.lowagie.com/iText/ * http://www.lowagie.com/iText/
@ -54,7 +54,6 @@ package com.fr.third.com.lowagie.text.html;
import java.awt.Color; import java.awt.Color;
import java.util.Properties; import java.util.Properties;
import java.util.StringTokenizer;
/** /**
* A class that contains all the possible tagnames and their attributes. * A class that contains all the possible tagnames and their attributes.
@ -272,14 +271,14 @@ public class Markup {
/** a CSS value for text decoration */ /** a CSS value for text decoration */
public static final String CSS_VALUE_UNDERLINE = "underline"; public static final String CSS_VALUE_UNDERLINE = "underline";
/** a default value for font-size /** a default value for font-size
* @since 2.1.3 * @since 2.1.3
*/ */
public static final float DEFAULT_FONT_SIZE = 12f; public static final float DEFAULT_FONT_SIZE = 12f;
/** /**
* Parses a length. * Parses a length.
* *
* @param string * @param string
* a length in the form of an optional + or -, followed by a * a length in the form of an optional + or -, followed by a
* number and a unit. * number and a unit.
@ -295,23 +294,23 @@ public class Markup {
boolean ok = true; boolean ok = true;
while (ok && pos < length) { while (ok && pos < length) {
switch (string.charAt(pos)) { switch (string.charAt(pos)) {
case '+': case '+':
case '-': case '-':
case '0': case '0':
case '1': case '1':
case '2': case '2':
case '3': case '3':
case '4': case '4':
case '5': case '5':
case '6': case '6':
case '7': case '7':
case '8': case '8':
case '9': case '9':
case '.': case '.':
pos++; pos++;
break; break;
default: default:
ok = false; ok = false;
} }
} }
if (pos == 0) if (pos == 0)
@ -342,7 +341,7 @@ public class Markup {
/** /**
* New method contributed by: Lubos Strapko * New method contributed by: Lubos Strapko
* *
* @since 2.1.3 * @since 2.1.3
*/ */
public static float parseLength(String string, float actualFontSize) { public static float parseLength(String string, float actualFontSize) {
@ -353,23 +352,23 @@ public class Markup {
boolean ok = true; boolean ok = true;
while (ok && pos < length) { while (ok && pos < length) {
switch (string.charAt(pos)) { switch (string.charAt(pos)) {
case '+': case '+':
case '-': case '-':
case '0': case '0':
case '1': case '1':
case '2': case '2':
case '3': case '3':
case '4': case '4':
case '5': case '5':
case '6': case '6':
case '7': case '7':
case '8': case '8':
case '9': case '9':
case '.': case '.':
pos++; pos++;
break; break;
default: default:
ok = false; ok = false;
} }
} }
if (pos == 0) if (pos == 0)
@ -410,7 +409,7 @@ public class Markup {
/** /**
* Converts a <CODE>Color</CODE> into a HTML representation of this <CODE> * Converts a <CODE>Color</CODE> into a HTML representation of this <CODE>
* Color</CODE>. * Color</CODE>.
* *
* @param s * @param s
* the <CODE>Color</CODE> that has to be converted. * the <CODE>Color</CODE> that has to be converted.
* @return the HTML representation of this <COLOR>Color </COLOR> * @return the HTML representation of this <COLOR>Color </COLOR>
@ -431,7 +430,7 @@ public class Markup {
/** /**
* This method parses a String with attributes and returns a Properties * This method parses a String with attributes and returns a Properties
* object. * object.
* *
* @param string * @param string
* a String of this form: 'key1="value1"; key2="value2";... * a String of this form: 'key1="value1"; key2="value2";...
* keyN="valueN" ' * keyN="valueN" '
@ -441,32 +440,48 @@ public class Markup {
Properties result = new Properties(); Properties result = new Properties();
if (string == null) if (string == null)
return result; return result;
StringTokenizer keyValuePairs = new StringTokenizer(string, ";");
StringTokenizer keyValuePair;
String key; String key;
String value; String value;
while (keyValuePairs.hasMoreTokens()) { //换种方式解析,style中background里面也有可能会有;符号
keyValuePair = new StringTokenizer(keyValuePairs.nextToken(), ":"); String[] styles = string.split(";");
if (keyValuePair.hasMoreTokens()) for (String s : styles) {
key = keyValuePair.nextToken().trim(); String[] part = s.split(":",2);
else if (part.length == 2) {
continue; key = stripDoubleSpacesAndTrim(part[0]).toLowerCase();
if (keyValuePair.hasMoreTokens()) value = stripDoubleSpacesAndTrim(part[1]);
value = keyValuePair.nextToken().trim(); if (value.startsWith("\"") || value.startsWith("\'") )
else value = value.substring(1);
continue; if (value.endsWith("\"") || value.endsWith("\'"))
if (value.startsWith("\"")) value = value.substring(0, value.length() - 1);
value = value.substring(1); result.setProperty(key.toLowerCase(), value);
if (value.endsWith("\"")) }
value = value.substring(0, value.length() - 1);
result.setProperty(key.toLowerCase(), value);
} }
return result; return result;
} }
public static String stripDoubleSpacesAndTrim(final String str) {
char[] charArray = str.toCharArray();
if (str.contains(" ")) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < charArray.length; i++) {
char c = charArray[i];
if (c != ' ') {
builder.append(c);
} else {
if (i + 1 < charArray.length && charArray[i + 1] != ' ') {
builder.append(' ');
}
}
}
return builder.toString().trim();
} else {
return String.valueOf(charArray).trim();
}
}
/** /**
* Removes the comments sections of a String. * Removes the comments sections of a String.
* *
* @param string * @param string
* the original String * the original String
* @param startComment * @param startComment
@ -476,7 +491,7 @@ public class Markup {
* @return the String stripped of its comment section * @return the String stripped of its comment section
*/ */
public static String removeComment(String string, String startComment, public static String removeComment(String string, String startComment,
String endComment) { String endComment) {
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();
int pos = 0; int pos = 0;
int end = endComment.length(); int end = endComment.length();

84
fine-itext-old/src/com/fr/third/com/lowagie/text/html/ParseIndentAttrUtils.java

@ -0,0 +1,84 @@
package com.fr.third.com.lowagie.text.html;
import com.fr.third.com.lowagie.text.html.CSS;
import com.fr.third.com.lowagie.text.html.IndentAttribute;
import com.fr.third.com.lowagie.text.html.Markup;
import java.util.Iterator;
import java.util.Map;
/**
* @author kerry
* @date 2018/5/14
*/
public class ParseIndentAttrUtils {
public static IndentAttribute parseSpace(String indent){
String[] a = indent.split(" ");
if(a.length == 0){
return new IndentAttribute();
}
float indentTop = Markup.parseLength(a[0]);
if(a.length == 1){
return new IndentAttribute(indentTop, indentTop, indentTop, indentTop);
}
float indentLeft = Markup.parseLength(a[1]);
if(a.length == 2){
return new IndentAttribute(indentTop, indentLeft, indentTop, indentLeft);
}
float indentBottom = Markup.parseLength(a[2]);
if(a.length == 3){
return new IndentAttribute(indentTop, indentLeft, indentBottom, indentLeft);
}
float indentRight = Markup.parseLength(a[3]);
return new IndentAttribute(indentTop, indentLeft, indentBottom, indentRight);
}
public static IndentAttribute parsePaddingAttribute(Map map){
if (map == null){
return new IndentAttribute();
}
IndentAttribute indentAttribute = new IndentAttribute();
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
String key = (String) entry.getKey();
if (CSS.Property.PADDING_LEFT.equals(key)) {
indentAttribute.setLeft(Markup.parseLength((String) entry.getValue()));
} else if (CSS.Property.PADDING_RIGHT.equals(key)) {
indentAttribute.setRight(Markup.parseLength((String) entry.getValue()));
} else if (CSS.Property.PADDING_TOP.equals(key)) {
indentAttribute.setTop(Markup.parseLength((String) entry.getValue()));
} else if (CSS.Property.PADDING_BOTTOM.equals(key)) {
indentAttribute.setBottom(Markup.parseLength((String) entry.getValue()));
}
}
return indentAttribute;
}
public static IndentAttribute parseMarginAttribute(Map map){
IndentAttribute indentAttribute = new IndentAttribute();
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
String key = (String) entry.getKey();
float val = Markup.parseLength((String) entry.getValue());
if (CSS.Property.MARGIN_LEFT.equals(key)) {
indentAttribute.setLeft(val);
} else if (CSS.Property.MARGIN_RIGHT.equals(key)) {
indentAttribute.setRight(val);
} else if (CSS.Property.MARGIN_TOP.equals(key)) {
indentAttribute.setTop(val);
} else if (CSS.Property.MARGIN_BOTTOM.equals(key)) {
indentAttribute.setBottom(val);
}
}
return indentAttribute;
}
public static void createIndent(StringBuffer stringBuffer, String attr, IndentAttribute indentAttribute){
stringBuffer.append(attr).append("-").append("left").append(":").append(indentAttribute.getLeft()).append("px;")
.append(attr).append("-").append("right").append(":").append(indentAttribute.getRight()).append("px;")
.append(attr).append("-").append("top").append(":").append(indentAttribute.getTop()).append("px;")
.append(attr).append("-").append("bottom").append(":").append(indentAttribute.getBottom()).append("px;");
}
}

4
fine-itext-old/src/com/fr/third/com/lowagie/text/html/WebColors.java

@ -221,7 +221,7 @@ public class WebColors extends HashMap {
*/ */
public static Color getRGBColor(String name) public static Color getRGBColor(String name)
throws IllegalArgumentException { throws IllegalArgumentException {
int[] c = { 0, 0, 0, 0 }; int[] c = { 0, 0, 0, 255 };
if (name.startsWith("#")) { if (name.startsWith("#")) {
if (name.length() == 4) { if (name.length() == 4) {
c[0] = Integer.parseInt(name.substring(1, 2), 16) * 16; c[0] = Integer.parseInt(name.substring(1, 2), 16) * 16;
@ -258,6 +258,6 @@ public class WebColors extends HashMap {
throw new IllegalArgumentException("Color '" + name throw new IllegalArgumentException("Color '" + name
+ "' not found."); + "' not found.");
c = (int[]) NAMES.get(name); c = (int[]) NAMES.get(name);
return new Color(c[0], c[1], c[2], c[3]); return new Color(c[0], c[1], c[2], 255);
} }
} }

67
fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/ChainedProperties.java

@ -75,6 +75,13 @@ 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);
@ -85,6 +92,66 @@ public class ChainedProperties {
return false; return false;
} }
public String getPropertyFromChain (String tag, String key) {
//块级元素不继承行内元素属性
if(HtmlConstants.BLOCK_ELEMENTS.contains(tag)){
for (int k = chain.size() - 1; k >= 0; --k) {
Object obj[] = (Object[]) chain.get(k);
if(HtmlConstants.INLINE_ELEMENTS.contains(obj[0])){
continue;
}
HashMap prop = (HashMap) obj[1];
String ret = (String) prop.get(key);
if (ret != null)
return ret;
}
}else{
for (int k = chain.size() - 1; k >= 0; --k) {
Object obj[] = (Object[]) chain.get(k);
if(HtmlConstants.BLOCK_ELEMENTS.contains(obj[0])){
return null;
}
HashMap prop = (HashMap) obj[1];
String ret = (String) prop.get(key);
if (ret != null)
return ret;
}
}
return null;
}
public boolean hasPropertyInChain(String tag, String key) {
if (HtmlConstants.BLOCK_ELEMENTS.contains(tag)) {
for (int k = chain.size() - 1; k >= 0; --k) {
Object obj[] = (Object[]) chain.get(k);
if( HtmlConstants.INLINE_ELEMENTS.contains(obj[0])){
continue;
}
HashMap prop = (HashMap) obj[1];
if (prop.containsKey(key))
return true;
}
} else {
for (int k = chain.size() - 1; k >= 0; --k) {
Object obj[] = (Object[]) chain.get(k);
if( HtmlConstants.BLOCK_ELEMENTS.contains(obj[0])){
return false;
}
HashMap prop = (HashMap) obj[1];
if (prop.containsKey(key))
return true;
}
}
return false;
}
public void addToChain(String key, HashMap prop) { public void addToChain(String key, HashMap prop) {
// adjust the font size // adjust the font size
String value = (String) prop.get(ElementTags.SIZE); String value = (String) prop.get(ElementTags.SIZE);

82
fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/FactoryProperties.java

@ -50,12 +50,6 @@
package com.fr.third.com.lowagie.text.html.simpleparser; package com.fr.third.com.lowagie.text.html.simpleparser;
import java.awt.Color;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.StringTokenizer;
import com.fr.third.com.lowagie.text.Chunk; import com.fr.third.com.lowagie.text.Chunk;
import com.fr.third.com.lowagie.text.Element; import com.fr.third.com.lowagie.text.Element;
import com.fr.third.com.lowagie.text.ElementTags; import com.fr.third.com.lowagie.text.ElementTags;
@ -64,12 +58,19 @@ import com.fr.third.com.lowagie.text.FontFactory;
import com.fr.third.com.lowagie.text.FontFactoryImp; import com.fr.third.com.lowagie.text.FontFactoryImp;
import com.fr.third.com.lowagie.text.ListItem; import com.fr.third.com.lowagie.text.ListItem;
import com.fr.third.com.lowagie.text.Paragraph; import com.fr.third.com.lowagie.text.Paragraph;
import com.fr.third.com.lowagie.text.html.Markup;
import com.fr.third.com.lowagie.text.html.HtmlTags; import com.fr.third.com.lowagie.text.html.HtmlTags;
import com.fr.third.com.lowagie.text.pdf.BaseFont; import com.fr.third.com.lowagie.text.html.IndentAttribute;
import com.fr.third.com.lowagie.text.html.Markup;
import com.fr.third.com.lowagie.text.html.ParseIndentAttrUtils;
import com.fr.third.com.lowagie.text.pdf.HyphenationAuto; import com.fr.third.com.lowagie.text.pdf.HyphenationAuto;
import com.fr.third.com.lowagie.text.pdf.HyphenationEvent; import com.fr.third.com.lowagie.text.pdf.HyphenationEvent;
import java.awt.Color;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.StringTokenizer;
/** /**
* *
* @author psoares * @author psoares
@ -85,16 +86,24 @@ public class FactoryProperties {
public Chunk createChunk(String text, ChainedProperties props) { public Chunk createChunk(String text, ChainedProperties props) {
Font font = getFont(props); Font font = getFont(props);
float size = font.getSize(); float size = font.getSize();
size /= 2; size /= 3;
Chunk ck = new Chunk(text, font); Chunk ck = new Chunk(text, font);
if (props.hasProperty("sub")) if (props.hasProperty("sub"))
ck.setTextRise(-size); ck.setTextRise(-size);
else if (props.hasProperty("sup")) else if (props.hasProperty("sup"))
ck.setTextRise(size); ck.setTextRise(size);
ck.setHyphenation(getHyphenation(props)); ck.setHyphenation(getHyphenation(props));
if(props.hasProperty("background")){
ck.setBackground(props.getProperty("background"));
}
for(String padding : HtmlConstants.PADDING){
if(props.hasPropertyInChain("span", padding)){
String ss = props.getPropertyFromChain("span", padding);
ck.setAttribute(padding, ss);
}
}
return ck; return ck;
} }
private static void setParagraphLeading(Paragraph p, String leading) { private static void setParagraphLeading(Paragraph p, String leading) {
if (leading == null) { if (leading == null) {
p.setLeading(0, 1.5f); p.setLeading(0, 1.5f);
@ -126,6 +135,34 @@ public class FactoryProperties {
else if (value.equalsIgnoreCase("justify")) else if (value.equalsIgnoreCase("justify"))
p.setAlignment(Element.ALIGN_JUSTIFIED); p.setAlignment(Element.ALIGN_JUSTIFIED);
} }
if(props.hasPropertyInChain("div", "background")){
p.setBackground(props.getPropertyFromChain("div", "background"));
}
if(props.hasProperty("line-height")){
p.setAttribute("line-height", props.getProperty("line-height"));
}
for(String margin : HtmlConstants.MARGIN){
if(props.hasPropertyInChain("div", margin)){
String ss = props.getPropertyFromChain("div", margin);
p.setAttribute(margin, ss);
}
}
for(String padding : HtmlConstants.PADDING){
if(props.hasPropertyInChain("div", padding)){
String ss = props.getPropertyFromChain("div", padding);
p.setAttribute(padding, ss);
}
}
if(props.hasPropertyInChain("div", "text-indent")){
String ss = props.getPropertyFromChain("div", "text-indent");
p.setFirstLineIndent(Markup.parseLength(ss));
}
if(props.hasPropertyInChain("div", "width")){
String ss = props.getPropertyFromChain("div", "width");
p.setAttribute("width", ss);
}
p.setHyphenation(getHyphenation(props)); p.setHyphenation(getHyphenation(props));
setParagraphLeading(p, props.getProperty("leading")); setParagraphLeading(p, props.getProperty("leading"));
value = props.getProperty("before"); value = props.getProperty("before");
@ -191,10 +228,7 @@ public class FactoryProperties {
if (value != null) if (value != null)
size = Float.parseFloat(value); size = Float.parseFloat(value);
Color color = Markup.decodeColor(props.getProperty("color")); Color color = Markup.decodeColor(props.getProperty("color"));
String encoding = props.getProperty("encoding"); return new Font(face, size, style, color);
if (encoding == null)
encoding = BaseFont.WINANSI;
return fontImp.getFont(face, encoding, true, size, style, color);
} }
/** /**
@ -309,13 +343,22 @@ public class FactoryProperties {
else { else {
h.put("leading", v + ",0"); h.put("leading", v + ",0");
} }
} else if (key.equals(Markup.CSS_KEY_TEXTALIGN)) { } else if (key.equals(Markup.CSS_KEY_PADDING)) {
String ss = prop.getProperty(key).trim().toLowerCase();
IndentAttribute indentAttribute = ParseIndentAttrUtils.parseSpace(ss);
h.put(Markup.CSS_KEY_PADDINGTOP, indentAttribute.getTop() + "px");
h.put(Markup.CSS_KEY_PADDINGLEFT, indentAttribute.getLeft() + "px");
h.put(Markup.CSS_KEY_PADDINGBOTTOM, indentAttribute.getBottom() + "px");
h.put(Markup.CSS_KEY_PADDINGRIGHT, indentAttribute.getRight() + "px");
}
else if (key.equals(Markup.CSS_KEY_TEXTALIGN)) {
String ss = prop.getProperty(key).trim().toLowerCase(); String ss = prop.getProperty(key).trim().toLowerCase();
h.put("align", ss); h.put("align", ss);
} }
} }
} }
/** /**
* New method contributed by Lubos Strapko * New method contributed by Lubos Strapko
* @param h * @param h
@ -380,12 +423,17 @@ public class FactoryProperties {
return; return;
} }
h.put("leading", v + ",0"); h.put("leading", v + ",0");
h.put("line-height", ss);
} else if (key.equals(Markup.CSS_KEY_TEXTALIGN)) { } else if (key.equals(Markup.CSS_KEY_TEXTALIGN)) {
String ss = prop.getProperty(key).trim().toLowerCase(); String ss = prop.getProperty(key).trim().toLowerCase();
h.put("align", ss); h.put("align", ss);
} else if (key.equals(Markup.CSS_KEY_PADDINGLEFT)) { } else if (key.equals(Markup.CSS_KEY_BGCOLOR)) {
String ss = prop.getProperty(key).trim().toLowerCase(); String ss = prop.getProperty(key).trim().toLowerCase();
h.put("indent", Float.toString(Markup.parseLength(ss))); h.put("background", ss);
}
else{
String ss = prop.getProperty(key).trim();
h.put(key, ss);
} }
} }
} }

103
fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/HTMLWorker.java

@ -50,16 +50,6 @@
package com.fr.third.com.lowagie.text.html.simpleparser; package com.fr.third.com.lowagie.text.html.simpleparser;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Stack;
import java.util.StringTokenizer;
import com.fr.third.com.lowagie.text.html.HtmlTags;
import com.fr.third.com.lowagie.text.html.Markup;
import com.fr.third.com.lowagie.text.Chunk; import com.fr.third.com.lowagie.text.Chunk;
import com.fr.third.com.lowagie.text.DocListener; import com.fr.third.com.lowagie.text.DocListener;
import com.fr.third.com.lowagie.text.DocumentException; import com.fr.third.com.lowagie.text.DocumentException;
@ -69,15 +59,32 @@ import com.fr.third.com.lowagie.text.ExceptionConverter;
import com.fr.third.com.lowagie.text.FontFactoryImp; import com.fr.third.com.lowagie.text.FontFactoryImp;
import com.fr.third.com.lowagie.text.HeaderFooter; import com.fr.third.com.lowagie.text.HeaderFooter;
import com.fr.third.com.lowagie.text.Image; import com.fr.third.com.lowagie.text.Image;
import com.fr.third.com.lowagie.text.List;
import com.fr.third.com.lowagie.text.ListItem; import com.fr.third.com.lowagie.text.ListItem;
import com.fr.third.com.lowagie.text.Paragraph; import com.fr.third.com.lowagie.text.Paragraph;
import com.fr.third.com.lowagie.text.Phrase; import com.fr.third.com.lowagie.text.Phrase;
import com.fr.third.com.lowagie.text.Rectangle; import com.fr.third.com.lowagie.text.Rectangle;
import com.fr.third.com.lowagie.text.TextElementArray; import com.fr.third.com.lowagie.text.TextElementArray;
import com.fr.third.com.lowagie.text.html.CSSUtils;
import com.fr.third.com.lowagie.text.html.HtmlTags;
import com.fr.third.com.lowagie.text.html.Markup;
import com.fr.third.com.lowagie.text.pdf.PdfPTable; import com.fr.third.com.lowagie.text.pdf.PdfPTable;
import com.fr.third.com.lowagie.text.pdf.draw.LineSeparator; import com.fr.third.com.lowagie.text.pdf.draw.LineSeparator;
import com.fr.third.com.lowagie.text.xml.simpleparser.SimpleXMLDocHandler; import com.fr.third.com.lowagie.text.xml.simpleparser.SimpleXMLDocHandler;
import com.fr.third.com.lowagie.text.xml.simpleparser.SimpleXMLParser; import com.fr.third.com.lowagie.text.xml.simpleparser.SimpleXMLParser;
import sun.misc.BASE64Decoder;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Stack;
import java.util.StringTokenizer;
public class HTMLWorker implements SimpleXMLDocHandler, DocListener { public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
@ -176,11 +183,16 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
cprops.addToChain("body", h); cprops.addToChain("body", h);
} }
public void startElement(String tag, HashMap h) { public void startElement(String tag, HashMap h) {
if (!tagsSupported.containsKey(tag)) if (!tagsSupported.containsKey(tag))
return; return;
try { try {
style.applyStyle(tag, h); style.applyStyle(tag, h);
if(tag.equals("p")){
h.put(Markup.CSS_KEY_MARGINTOP, "16px");
h.put(Markup.CSS_KEY_MARGINBOTTOM, "16px");
}
String follow = (String) FactoryProperties.followTags.get(tag); String follow = (String) FactoryProperties.followTags.get(tag);
if (follow != null) { if (follow != null) {
HashMap prop = new HashMap(); HashMap prop = new HashMap();
@ -226,7 +238,7 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
int hrAlign = Element.ALIGN_CENTER; int hrAlign = Element.ALIGN_CENTER;
if (align != null) { if (align != null) {
if (align.equalsIgnoreCase("left")) if (align.equalsIgnoreCase("left"))
hrAlign = Element.ALIGN_LEFT; hrAlign = Element.ALIGN_LEFT;
if (align.equalsIgnoreCase("right")) if (align.equalsIgnoreCase("right"))
hrAlign = Element.ALIGN_RIGHT; hrAlign = Element.ALIGN_RIGHT;
} }
@ -285,6 +297,14 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
} }
} }
} }
//处理base64编码图片
if(src.startsWith("data")){
BASE64Decoder decoder = new BASE64Decoder();
String[] srcArray = src.split(",");
String base64string = srcArray[srcArray.length -1];
byte[] bytes = decoder.decodeBuffer(base64string);
img = Image.getInstance(bytes);
}
if (img == null) { if (img == null) {
if (!src.startsWith("http")) { if (!src.startsWith("http")) {
String path = cprops.getProperty("image_path"); String path = cprops.getProperty("image_path");
@ -294,6 +314,10 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
} }
img = Image.getInstance(src); img = Image.getInstance(src);
} }
if(img == null){
return;
}
img.setSrcString(src);
String align = (String) h.get("align"); String align = (String) h.get("align");
String width = (String) h.get("width"); String width = (String) h.get("width");
String height = (String) h.get("height"); String height = (String) h.get("height");
@ -342,12 +366,22 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
document.add(img); document.add(img);
cprops.removeChain(tag); cprops.removeChain(tag);
} else { } else {
Chunk ck = new Chunk(img, 0, 0);
if(cprops.hasPropertyInChain("img", "padding-left")){
String ss = cprops.getPropertyFromChain("img", "padding-left");
ck.setAttribute("padding-left", Float.toString(Markup.parseLength(ss)));
}
if(cprops.hasPropertyInChain("img", "padding-right")){
String ss = cprops.getPropertyFromChain("img", "padding-right");
ck.setAttribute("padding-right", Float.toString(Markup.parseLength(ss)));
}
cprops.removeChain(tag); cprops.removeChain(tag);
if (currentParagraph == null) { if (currentParagraph == null) {
currentParagraph = FactoryProperties currentParagraph = FactoryProperties
.createParagraph(cprops); .createParagraph(cprops);
} }
currentParagraph.add(new Chunk(img, 0, 0));
currentParagraph.add(ck);
} }
return; return;
} }
@ -366,7 +400,7 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
endElement(HtmlTags.LISTITEM); endElement(HtmlTags.LISTITEM);
skipText = true; skipText = true;
cprops.addToChain(tag, h); cprops.addToChain(tag, h);
com.fr.third.com.lowagie.text.List list = new com.fr.third.com.lowagie.text.List(false); List list = new List(false);
try{ try{
list.setIndentationLeft(new Float(cprops.getProperty("indent")).floatValue()); list.setIndentationLeft(new Float(cprops.getProperty("indent")).floatValue());
}catch (Exception e) { }catch (Exception e) {
@ -381,7 +415,7 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
endElement(HtmlTags.LISTITEM); endElement(HtmlTags.LISTITEM);
skipText = true; skipText = true;
cprops.addToChain(tag, h); cprops.addToChain(tag, h);
com.fr.third.com.lowagie.text.List list = new com.fr.third.com.lowagie.text.List(true); List list = new List(true);
try{ try{
list.setIndentationLeft(new Float(cprops.getProperty("indent")).floatValue()); list.setIndentationLeft(new Float(cprops.getProperty("indent")).floatValue());
}catch (Exception e) { }catch (Exception e) {
@ -443,6 +477,30 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
} }
} }
public BufferedImage GetBufferedImage(String base64string)
{
BufferedImage image = null;
try {
InputStream stream = BaseToInputStream(base64string);
image = ImageIO.read(stream);
} catch (IOException e) {
e.printStackTrace();
}
return image;
}
public InputStream BaseToInputStream(String base64string){
ByteArrayInputStream stream = null;
try {
BASE64Decoder decoder = new BASE64Decoder();
byte[] bytes1 = decoder.decodeBuffer(base64string);
stream = new ByteArrayInputStream(bytes1);
} catch (Exception e) {
}
return stream;
}
public void endElement(String tag) { public void endElement(String tag) {
if (!tagsSupported.containsKey(tag)) if (!tagsSupported.containsKey(tag))
return; return;
@ -510,7 +568,7 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
if (stack.empty()) if (stack.empty())
return; return;
Object obj = stack.pop(); Object obj = stack.pop();
if (!(obj instanceof com.fr.third.com.lowagie.text.List)) { if (!(obj instanceof List)) {
stack.push(obj); stack.push(obj);
return; return;
} }
@ -536,12 +594,12 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
return; return;
} }
Object list = stack.pop(); Object list = stack.pop();
if (!(list instanceof com.fr.third.com.lowagie.text.List)) { if (!(list instanceof List)) {
stack.push(list); stack.push(list);
return; return;
} }
ListItem item = (ListItem) obj; ListItem item = (ListItem) obj;
((com.fr.third.com.lowagie.text.List) list).add(item); ((List) list).add(item);
ArrayList cks = item.getChunks(); ArrayList cks = item.getChunks();
if (!cks.isEmpty()) if (!cks.isEmpty())
item.getListSymbol() item.getListSymbol()
@ -588,6 +646,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;
@ -601,8 +661,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;
@ -705,7 +770,7 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
} }
/** /**
* @see com.fr.third.com.lowagie.text.DocListener#setMarginMirroring(boolean) * @see DocListener#setMarginMirroring(boolean)
* @since 2.1.6 * @since 2.1.6
*/ */
public boolean setMarginMirroringTopBottom(boolean marginMirroring) { public boolean setMarginMirroringTopBottom(boolean marginMirroring) {

45
fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/HtmlConstants.java

@ -0,0 +1,45 @@
package com.fr.third.com.lowagie.text.html.simpleparser;
import com.fr.third.com.lowagie.text.html.HtmlTags;
import com.fr.third.com.lowagie.text.html.Markup;
import java.util.ArrayList;
import java.util.List;
/**
* @author kerry
* @date 2018/5/2
*/
public class HtmlConstants {
//块级元素集合
public static final List<String> BLOCK_ELEMENTS = new ArrayList<String>();
//行内元素集合
public static final List<String> INLINE_ELEMENTS = new ArrayList<String>();
//支持解析的属性
public static final List<String> PADDING = new ArrayList<String>();
public static final List<String> MARGIN = new ArrayList<String>();
static {
BLOCK_ELEMENTS.add(HtmlTags.DIV);
BLOCK_ELEMENTS.add(HtmlTags.UNORDEREDLIST);
BLOCK_ELEMENTS.add(HtmlTags.PARAGRAPH);
BLOCK_ELEMENTS.add(HtmlTags.ORDEREDLIST);
BLOCK_ELEMENTS.add(HtmlTags.TABLE);
INLINE_ELEMENTS.add(HtmlTags.SPAN);
INLINE_ELEMENTS.add(HtmlTags.IMAGE);
INLINE_ELEMENTS.add(HtmlTags.STRONG);
INLINE_ELEMENTS.add(HtmlTags.ANCHOR);
INLINE_ELEMENTS.add(HtmlTags.SUB);
INLINE_ELEMENTS.add(HtmlTags.SUP);
INLINE_ELEMENTS.add(HtmlTags.I);
INLINE_ELEMENTS.add(HtmlTags.U);
INLINE_ELEMENTS.add(HtmlTags.EM);
PADDING.add(Markup.CSS_KEY_PADDINGLEFT);
PADDING.add(Markup.CSS_KEY_PADDINGRIGHT);
PADDING.add(Markup.CSS_KEY_PADDINGTOP);
PADDING.add(Markup.CSS_KEY_PADDINGBOTTOM);
MARGIN.add(Markup.CSS_KEY_MARGINLEFT);
MARGIN.add(Markup.CSS_KEY_MARGINRIGHT);
MARGIN.add(Markup.CSS_KEY_MARGINTOP);
MARGIN.add(Markup.CSS_KEY_MARGINBOTTOM);
}
}

94
fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/IncCell.java

@ -48,22 +48,26 @@
package com.fr.third.com.lowagie.text.html.simpleparser; package com.fr.third.com.lowagie.text.html.simpleparser;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import com.fr.third.com.lowagie.text.Element; import com.fr.third.com.lowagie.text.Element;
import com.fr.third.com.lowagie.text.ElementListener; import com.fr.third.com.lowagie.text.ElementListener;
import com.fr.third.com.lowagie.text.Phrase;
import com.fr.third.com.lowagie.text.TextElementArray; import com.fr.third.com.lowagie.text.TextElementArray;
import com.fr.third.com.lowagie.text.html.CSSUtils;
import com.fr.third.com.lowagie.text.html.Markup; import com.fr.third.com.lowagie.text.html.Markup;
import com.fr.third.com.lowagie.text.pdf.PdfPCell; import com.fr.third.com.lowagie.text.pdf.PdfPCell;
import com.fr.third.com.lowagie.text.Phrase;
/** /**
* *
* @author psoares * @author psoares
*/ */
public class IncCell implements TextElementArray { public class IncCell implements TextElementArray {
private ArrayList chunks = new ArrayList(); private ArrayList chunks = new ArrayList();
private PdfPCell cell; private PdfPCell cell;
/** Creates a new instance of IncCell */ /** Creates a new instance of IncCell */
public IncCell(String tag, ChainedProperties props) { public IncCell(String tag, ChainedProperties props) {
cell = new PdfPCell((Phrase)null); cell = new PdfPCell((Phrase)null);
@ -94,52 +98,90 @@ 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) {
if (!(o instanceof Element)) if (!(o instanceof Element))
return false; return false;
cell.addElement((Element)o); cell.addElement((Element)o);
return true; return true;
} }
public ArrayList getChunks() { public ArrayList getChunks() {
return chunks; return chunks;
} }
public boolean process(ElementListener listener) { public boolean process(ElementListener listener) {
return true; return true;
} }
public int type() { public int type() {
return Element.RECTANGLE; return Element.RECTANGLE;
} }
public PdfPCell getCell() { public PdfPCell getCell() {
return cell; return cell;
} }
/** /**
* @see com.fr.third.com.lowagie.text.Element#isContent() * @see Element#isContent()
* @since iText 2.0.8 * @since iText 2.0.8
*/ */
public boolean isContent() { public boolean isContent() {
return true; return true;
} }
/** /**
* @see com.fr.third.com.lowagie.text.Element#isNestable() * @see Element#isNestable()
* @since iText 2.0.8 * @since iText 2.0.8
*/ */
public boolean isNestable() { public boolean isNestable() {
return true; return true;
} }
} }

110
fine-itext-old/src/com/fr/third/com/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.com.lowagie.text.pdf.PdfPCell; import com.fr.third.com.lowagie.text.html.CSSUtils;
import com.fr.third.com.lowagie.text.html.Markup;
import com.fr.third.com.lowagie.text.pdf.BorderStyle;
import com.fr.third.com.lowagie.text.pdf.PdfPTable; import com.fr.third.com.lowagie.text.pdf.PdfPTable;
import com.fr.third.com.lowagie.text.pdf.PdfPCell;
import com.fr.third.com.lowagie.text.pdf.TableProperties;
/** /**
* *
@ -62,62 +66,126 @@ 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);
} }
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() { 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);
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>();
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);
String width = (String)props.get("width"); try {
if (width == null) TableProperties tableProperties = parseTableProperties();
table.setWidthPercentage(100); table.setTableProperties(tableProperties);
else { String width = (String)props.get("width");
if (width.endsWith("%")) if (width == null)
table.setWidthPercentage(Float.parseFloat(width.substring(0, width.length() - 1))); table.setWidthPercentage(100);
else { else {
table.setTotalWidth(Float.parseFloat(width)); if (width.endsWith("%"))
table.setLockedWidth(true); 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) {
for (int row = 0; row < rows.size(); ++row) { ArrayList col = (ArrayList)rows.get(row);
ArrayList col = (ArrayList)rows.get(row); for (int k = 0; k < col.size(); ++k) {
for (int k = 0; k < col.size(); ++k) { 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-old/src/com/fr/third/com/lowagie/text/pdf/BorderStyle.java

@ -0,0 +1,58 @@
package com.fr.third.com.lowagie.text.pdf;
import com.fr.third.com.lowagie.text.DocumentException;
import com.fr.third.com.lowagie.text.html.CSSUtils;
import com.fr.third.com.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;
}
}

539
fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfPCell.java

File diff suppressed because it is too large Load Diff

490
fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfPRow.java

@ -51,15 +51,15 @@ package com.fr.third.com.lowagie.text.pdf;
import java.awt.Color; import java.awt.Color;
import com.fr.third.com.lowagie.text.ExceptionConverter;
import com.fr.third.com.lowagie.text.DocumentException; import com.fr.third.com.lowagie.text.DocumentException;
import com.fr.third.com.lowagie.text.Element; import com.fr.third.com.lowagie.text.Element;
import com.fr.third.com.lowagie.text.ExceptionConverter;
import com.fr.third.com.lowagie.text.Image; import com.fr.third.com.lowagie.text.Image;
import com.fr.third.com.lowagie.text.Rectangle; import com.fr.third.com.lowagie.text.Rectangle;
/** /**
* A row in a PdfPTable. * A row in a PdfPTable.
* *
* @author Paulo Soares (psoares@consiste.pt) * @author Paulo Soares (psoares@consiste.pt)
*/ */
public class PdfPRow { public class PdfPRow {
@ -75,7 +75,17 @@ public class PdfPRow {
protected PdfPCell cells[]; protected PdfPCell cells[];
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
@ -83,15 +93,15 @@ public class PdfPRow {
protected float extraHeights[]; protected float extraHeights[];
protected float maxHeight = 0; protected float maxHeight = 0;
protected boolean calculated = false; protected boolean calculated = false;
private int[] canvasesPos; private int[] canvasesPos;
/** /**
* Constructs a new PdfPRow with the cells in the array that was passed * Constructs a new PdfPRow with the cells in the array that was passed
* as a parameter. * as a parameter.
* *
* @param cells * @param cells
*/ */
public PdfPRow(PdfPCell cells[]) { public PdfPRow(PdfPCell cells[]) {
@ -102,7 +112,7 @@ public class PdfPRow {
/** /**
* Makes a copy of an existing row. * Makes a copy of an existing row.
* *
* @param row * @param row
*/ */
public PdfPRow(PdfPRow row) { public PdfPRow(PdfPRow row) {
@ -120,7 +130,7 @@ public class PdfPRow {
/** /**
* Sets the widths of the columns in the row. * Sets the widths of the columns in the row.
* *
* @param widths * @param widths
* @return true if everything went right * @return true if everything went right
*/ */
@ -132,12 +142,12 @@ public class PdfPRow {
calculated = false; calculated = false;
for (int k = 0; k < widths.length; ++k) { for (int k = 0; k < widths.length; ++k) {
PdfPCell cell = cells[k]; PdfPCell cell = cells[k];
if (cell == null) { if (cell == null) {
total += widths[k]; total += widths[k];
continue; continue;
} }
cell.setLeft(total); cell.setLeft(total);
int last = k + cell.getColspan(); int last = k + cell.getColspan();
for (; k < last; ++k) for (; k < last; ++k)
@ -159,7 +169,7 @@ public class PdfPRow {
extraHeights[i] = 0; extraHeights[i] = 0;
} }
} }
/** /**
* Sets an extra height for a cell. * Sets an extra height for a cell.
* @param cell the index of the cell that needs an extra height * @param cell the index of the cell that needs an extra height
@ -171,48 +181,34 @@ public class PdfPRow {
return; return;
extraHeights[cell] = height; extraHeights[cell] = height;
} }
/** /**
* Calculates the heights of each cell in the row. * Calculates the heights of each cell in the row.
* *
* @return the maximum height of the row. * @return the maximum height of the row.
*/ */
public float calculateHeights() { public float calculateHeights() {
maxHeight = 0; maxHeight = 0;
// @change for (int k = 0; k < cells.length; ++k) {
int rowSpan = Integer.MAX_VALUE;
boolean hasAboveRowSpan = false;
float max_height = 0.0f;
for (int k = 0; k < cells.length;) {
PdfPCell cell = cells[k]; PdfPCell cell = cells[k];
float height = 0; float height = 0;
if (cell == null) { if (cell == null) {
hasAboveRowSpan = true;
k++;
continue; continue;
} }
else { else {
height = cell.getMaxHeight(); height = cell.getStyleHeight() == 0 ? cell.getContainer().getHeight() : cell.getStyleHeight();
if (cell.getRowspan() == rowSpan && height > max_height) { if ((height > maxHeight) && (cell.getRowspan() == 1))
max_height = height; maxHeight = height;
} else if (cell.getRowspan() < rowSpan) {
rowSpan = cell.getRowspan();
max_height = height;
}
k += cell.getColspan();
} }
} }
calculated = true; calculated = true;
// carl:假如有格子是从属于一个rowSpan的格子,而这个格子的主格不在这一行(当然这样的假设建立在格子是满的情况下。) return maxHeight = Math.max(styleHeight, maxHeight);
if (!hasAboveRowSpan || rowSpan == 1) {
maxHeight = max_height;
}
return maxHeight;
} }
/** /**
* Writes the border and background of one cell in the row. * Writes the border and background of one cell in the row.
* *
* @param xPos The x-coordinate where the table starts on the canvas * @param xPos The x-coordinate where the table starts on the canvas
* @param yPos The y-coordinate where the table starts on the canvas * @param yPos The y-coordinate where the table starts on the canvas
* @param currentMaxHeight The height of the cell to be drawn. * @param currentMaxHeight The height of the cell to be drawn.
@ -228,7 +224,7 @@ public class PdfPRow {
float top = cell.getTop() + yPos; float top = cell.getTop() + yPos;
float left = cell.getLeft() + xPos; float left = cell.getLeft() + xPos;
float bottom = top - currentMaxHeight; float bottom = top - currentMaxHeight;
if (background != null) { if (background != null) {
PdfContentByte backgr = canvases[PdfPTable.BACKGROUNDCANVAS]; PdfContentByte backgr = canvases[PdfPTable.BACKGROUNDCANVAS];
backgr.setColorFill(background); backgr.setColorFill(background);
@ -250,48 +246,48 @@ public class PdfPRow {
/** /**
* @since 2.1.6 private is now protected * @since 2.1.6 private is now protected
*/ */
protected void saveAndRotateCanvases(PdfContentByte[] canvases, float a, float b, float c, float d, float e, float f) { protected void saveAndRotateCanvases(PdfContentByte[] canvases, float a, float b, float c, float d, float e, float f) {
int last = PdfPTable.TEXTCANVAS + 1; int last = PdfPTable.TEXTCANVAS + 1;
if (canvasesPos == null) if (canvasesPos == null)
canvasesPos = new int[last * 2]; canvasesPos = new int[last * 2];
for (int k = 0; k < last; ++k) { for (int k = 0; k < last; ++k) {
ByteBuffer bb = canvases[k].getInternalBuffer(); ByteBuffer bb = canvases[k].getInternalBuffer();
canvasesPos[k * 2] = bb.size(); canvasesPos[k * 2] = bb.size();
canvases[k].saveState(); canvases[k].saveState();
canvases[k].concatCTM(a, b, c, d, e, f); canvases[k].concatCTM(a, b, c, d, e, f);
canvasesPos[k * 2 + 1] = bb.size(); canvasesPos[k * 2 + 1] = bb.size();
} }
} }
/** /**
* @since 2.1.6 private is now protected * @since 2.1.6 private is now protected
*/ */
protected void restoreCanvases(PdfContentByte[] canvases) { protected void restoreCanvases(PdfContentByte[] canvases) {
int last = PdfPTable.TEXTCANVAS + 1; int last = PdfPTable.TEXTCANVAS + 1;
for (int k = 0; k < last; ++k) { for (int k = 0; k < last; ++k) {
ByteBuffer bb = canvases[k].getInternalBuffer(); ByteBuffer bb = canvases[k].getInternalBuffer();
int p1 = bb.size(); int p1 = bb.size();
canvases[k].restoreState(); canvases[k].restoreState();
if (p1 == canvasesPos[k * 2 + 1]) if (p1 == canvasesPos[k * 2 + 1])
bb.setSize(canvasesPos[k * 2]); bb.setSize(canvasesPos[k * 2]);
} }
} }
/** /**
* @since 3.0.0 protected is now public static * @since 3.0.0 protected is now public static
*/ */
public static float setColumn(ColumnText ct, float left, float bottom, float right, float top) { public static float setColumn(ColumnText ct, float left, float bottom, float right, float top) {
if (left > right) if (left > right)
right = left; right = left;
if (bottom > top) if (bottom > top)
top = bottom; top = bottom;
ct.setSimpleColumn(left, bottom, right, top); ct.setSimpleColumn(left, bottom, right, top);
return top; return top;
} }
/** /**
* Writes a number of cells (not necessarily all cells). * Writes a number of cells (not necessarily all cells).
* *
* @param colStart The first column to be written. * @param colStart The first column to be written.
* Remember that the column index starts with 0. * Remember that the column index starts with 0.
* @param colEnd The last column to be written. * @param colEnd The last column to be written.
@ -311,7 +307,7 @@ public class PdfPRow {
colStart = 0; colStart = 0;
if (colStart >= colEnd) if (colStart >= colEnd)
return; return;
int newStart; int newStart;
for (newStart = colStart; newStart >= 0; --newStart) { for (newStart = colStart; newStart >= 0; --newStart) {
if (cells[newStart] != null) if (cells[newStart] != null)
@ -319,42 +315,42 @@ public class PdfPRow {
if (newStart > 0) if (newStart > 0)
xPos -= widths[newStart - 1]; xPos -= widths[newStart - 1];
} }
if (newStart < 0) if (newStart < 0)
newStart = 0; newStart = 0;
if (cells[newStart] != null) if (cells[newStart] != null)
xPos -= cells[newStart].getLeft(); xPos -= cells[newStart].getLeft();
for (int k = newStart; k < colEnd; ++k) { for (int k = newStart; k < colEnd; ++k) {
PdfPCell cell = cells[k]; PdfPCell cell = cells[k];
if (cell == null) if (cell == null)
continue; continue;
float currentMaxHeight = maxHeight + extraHeights[k]; float currentMaxHeight = maxHeight + extraHeights[k];
writeBorderAndBackground(xPos, yPos, currentMaxHeight, cell, canvases); writeBorderAndBackground(xPos, yPos, currentMaxHeight, cell, canvases);
Image img = cell.getImage(); Image img = cell.getImage();
float tly = cell.getTop() + yPos - cell.getEffectivePaddingTop(); float tly = cell.getTop() + yPos - cell.getEffectivePaddingTop();
if (cell.getHeight() <= currentMaxHeight) { if (cell.getHeight() <= currentMaxHeight) {
switch (cell.getVerticalAlignment()) { switch (cell.getVerticalAlignment()) {
case Element.ALIGN_BOTTOM: case Element.ALIGN_BOTTOM:
tly = cell.getTop() + yPos - currentMaxHeight + cell.getHeight() tly = cell.getTop() + yPos - currentMaxHeight + cell.getHeight()
- cell.getEffectivePaddingTop(); - cell.getEffectivePaddingTop();
break; break;
case Element.ALIGN_MIDDLE: case Element.ALIGN_MIDDLE:
tly = cell.getTop() + yPos + (cell.getHeight() - currentMaxHeight) / 2 tly = cell.getTop() + yPos + (cell.getHeight() - currentMaxHeight) / 2
- cell.getEffectivePaddingTop(); - cell.getEffectivePaddingTop();
break; break;
default: default:
break; break;
} }
} }
if (img != null) { if (img != null) {
if (cell.getRotation() != 0) { if (cell.getRotation() != 0) {
img = Image.getInstance(img); img = Image.getInstance(img);
img.setRotation(img.getImageRotation() + (float)(cell.getRotation() * Math.PI / 180.0)); img.setRotation(img.getImageRotation() + (float)(cell.getRotation() * Math.PI / 180.0));
} }
boolean vf = false; boolean vf = false;
if (cell.getHeight() > currentMaxHeight) { if (cell.getHeight() > currentMaxHeight) {
img.scalePercent(100); img.scalePercent(100);
@ -368,20 +364,20 @@ public class PdfPRow {
+ cell.getEffectivePaddingLeft(); + cell.getEffectivePaddingLeft();
if (vf) { if (vf) {
switch (cell.getHorizontalAlignment()) { switch (cell.getHorizontalAlignment()) {
case Element.ALIGN_CENTER: case Element.ALIGN_CENTER:
left = xPos left = xPos
+ (cell.getLeft() + cell.getEffectivePaddingLeft() + (cell.getLeft() + cell.getEffectivePaddingLeft()
+ cell.getRight() + cell.getRight()
- cell.getEffectivePaddingRight() - img - cell.getEffectivePaddingRight() - img
.getScaledWidth()) / 2; .getScaledWidth()) / 2;
break; break;
case Element.ALIGN_RIGHT: case Element.ALIGN_RIGHT:
left = xPos + cell.getRight() left = xPos + cell.getRight()
- cell.getEffectivePaddingRight() - cell.getEffectivePaddingRight()
- img.getScaledWidth(); - img.getScaledWidth();
break; break;
default: default:
break; break;
} }
tly = cell.getTop() + yPos - cell.getEffectivePaddingTop(); tly = cell.getTop() + yPos - cell.getEffectivePaddingTop();
} }
@ -392,128 +388,128 @@ public class PdfPRow {
throw new ExceptionConverter(e); throw new ExceptionConverter(e);
} }
} else { } else {
// rotation sponsored by Connection GmbH // rotation sponsored by Connection GmbH
if (cell.getRotation() == 90 || cell.getRotation() == 270) { if (cell.getRotation() == 90 || cell.getRotation() == 270) {
float netWidth = currentMaxHeight - cell.getEffectivePaddingTop() - cell.getEffectivePaddingBottom(); float netWidth = currentMaxHeight - cell.getEffectivePaddingTop() - cell.getEffectivePaddingBottom();
float netHeight = cell.getWidth() - cell.getEffectivePaddingLeft() - cell.getEffectivePaddingRight(); float netHeight = cell.getWidth() - cell.getEffectivePaddingLeft() - cell.getEffectivePaddingRight();
ColumnText ct = ColumnText.duplicate(cell.getColumn()); ColumnText ct = ColumnText.duplicate(cell.getColumn());
ct.setCanvases(canvases); ct.setCanvases(canvases);
ct.setSimpleColumn(0, 0, netWidth + 0.001f, -netHeight); ct.setSimpleColumn(0, 0, netWidth + 0.001f, -netHeight);
try { try {
ct.go(true); ct.go(true);
} catch (DocumentException e) { } catch (DocumentException e) {
throw new ExceptionConverter(e); throw new ExceptionConverter(e);
} }
float calcHeight = -ct.getYLine(); float calcHeight = -ct.getYLine();
if (netWidth <= 0 || netHeight <= 0) if (netWidth <= 0 || netHeight <= 0)
calcHeight = 0; calcHeight = 0;
if (calcHeight > 0) { if (calcHeight > 0) {
if (cell.isUseDescender()) if (cell.isUseDescender())
calcHeight -= ct.getDescender(); calcHeight -= ct.getDescender();
ct = ColumnText.duplicate(cell.getColumn()); ct = ColumnText.duplicate(cell.getColumn());
ct.setCanvases(canvases); ct.setCanvases(canvases);
ct.setSimpleColumn(-0.003f, -0.001f, netWidth + 0.003f, calcHeight); ct.setSimpleColumn(-0.003f, -0.001f, netWidth + 0.003f, calcHeight);
float pivotX; float pivotX;
float pivotY; float pivotY;
if (cell.getRotation() == 90) { if (cell.getRotation() == 90) {
pivotY = cell.getTop() + yPos - currentMaxHeight + cell.getEffectivePaddingBottom(); pivotY = cell.getTop() + yPos - currentMaxHeight + cell.getEffectivePaddingBottom();
switch (cell.getVerticalAlignment()) { switch (cell.getVerticalAlignment()) {
case Element.ALIGN_BOTTOM: case Element.ALIGN_BOTTOM:
pivotX = cell.getLeft() + xPos + cell.getWidth() - cell.getEffectivePaddingRight(); pivotX = cell.getLeft() + xPos + cell.getWidth() - cell.getEffectivePaddingRight();
break; break;
case Element.ALIGN_MIDDLE: case Element.ALIGN_MIDDLE:
pivotX = cell.getLeft() + xPos + (cell.getWidth() + cell.getEffectivePaddingLeft() - cell.getEffectivePaddingRight() + calcHeight) / 2; pivotX = cell.getLeft() + xPos + (cell.getWidth() + cell.getEffectivePaddingLeft() - cell.getEffectivePaddingRight() + calcHeight) / 2;
break; break;
default: //top default: //top
pivotX = cell.getLeft() + xPos + cell.getEffectivePaddingLeft() + calcHeight; pivotX = cell.getLeft() + xPos + cell.getEffectivePaddingLeft() + calcHeight;
break; break;
} }
saveAndRotateCanvases(canvases, 0,1,-1,0,pivotX,pivotY); saveAndRotateCanvases(canvases, 0,1,-1,0,pivotX,pivotY);
} }
else { else {
pivotY = cell.getTop() + yPos - cell.getEffectivePaddingTop(); pivotY = cell.getTop() + yPos - cell.getEffectivePaddingTop();
switch (cell.getVerticalAlignment()) { switch (cell.getVerticalAlignment()) {
case Element.ALIGN_BOTTOM: case Element.ALIGN_BOTTOM:
pivotX = cell.getLeft() + xPos + cell.getEffectivePaddingLeft(); pivotX = cell.getLeft() + xPos + cell.getEffectivePaddingLeft();
break; break;
case Element.ALIGN_MIDDLE: case Element.ALIGN_MIDDLE:
pivotX = cell.getLeft() + xPos + (cell.getWidth() + cell.getEffectivePaddingLeft() - cell.getEffectivePaddingRight() - calcHeight) / 2; pivotX = cell.getLeft() + xPos + (cell.getWidth() + cell.getEffectivePaddingLeft() - cell.getEffectivePaddingRight() - calcHeight) / 2;
break; break;
default: //top default: //top
pivotX = cell.getLeft() + xPos + cell.getWidth() - cell.getEffectivePaddingRight() - calcHeight; pivotX = cell.getLeft() + xPos + cell.getWidth() - cell.getEffectivePaddingRight() - calcHeight;
break; break;
} }
saveAndRotateCanvases(canvases, 0,-1,1,0,pivotX,pivotY); saveAndRotateCanvases(canvases, 0,-1,1,0,pivotX,pivotY);
} }
try { try {
ct.go(); ct.go();
} catch (DocumentException e) { } catch (DocumentException e) {
throw new ExceptionConverter(e); throw new ExceptionConverter(e);
} finally { } finally {
restoreCanvases(canvases); restoreCanvases(canvases);
} }
} }
} }
else { else {
float fixedHeight = cell.getFixedHeight(); float fixedHeight = cell.getFixedHeight();
float rightLimit = cell.getRight() + xPos float rightLimit = cell.getRight() + xPos
- cell.getEffectivePaddingRight(); - cell.getEffectivePaddingRight();
float leftLimit = cell.getLeft() + xPos float leftLimit = cell.getLeft() + xPos
+ cell.getEffectivePaddingLeft(); + cell.getEffectivePaddingLeft();
if (cell.isNoWrap()) { if (cell.isNoWrap()) {
switch (cell.getHorizontalAlignment()) { switch (cell.getHorizontalAlignment()) {
case Element.ALIGN_CENTER: case Element.ALIGN_CENTER:
rightLimit += 10000; rightLimit += 10000;
leftLimit -= 10000; leftLimit -= 10000;
break; break;
case Element.ALIGN_RIGHT: case Element.ALIGN_RIGHT:
if (cell.getRotation() == 180) { if (cell.getRotation() == 180) {
rightLimit += RIGHT_LIMIT; rightLimit += RIGHT_LIMIT;
} }
else { else {
leftLimit -= RIGHT_LIMIT; leftLimit -= RIGHT_LIMIT;
} }
break; break;
default: default:
if (cell.getRotation() == 180) { if (cell.getRotation() == 180) {
leftLimit -= RIGHT_LIMIT; leftLimit -= RIGHT_LIMIT;
} }
else { else {
rightLimit += RIGHT_LIMIT; rightLimit += RIGHT_LIMIT;
} }
break; break;
} }
} }
ColumnText ct = ColumnText.duplicate(cell.getColumn()); ColumnText ct = ColumnText.duplicate(cell.getColumn());
ct.setCanvases(canvases); ct.setCanvases(canvases);
float bry = tly float bry = tly
- (currentMaxHeight - (currentMaxHeight
- cell.getEffectivePaddingTop() - cell.getEffectivePaddingBottom()); - cell.getEffectivePaddingTop() - cell.getEffectivePaddingBottom());
if (fixedHeight > 0) { if (fixedHeight > 0) {
if (cell.getHeight() > currentMaxHeight) { if (cell.getHeight() > currentMaxHeight) {
tly = cell.getTop() + yPos - cell.getEffectivePaddingTop(); tly = cell.getTop() + yPos - cell.getEffectivePaddingTop();
bry = cell.getTop() + yPos - currentMaxHeight + cell.getEffectivePaddingBottom(); bry = cell.getTop() + yPos - currentMaxHeight + cell.getEffectivePaddingBottom();
} }
} }
if ((tly > bry || ct.zeroHeightElement()) && leftLimit < rightLimit) { if ((tly > bry || ct.zeroHeightElement()) && leftLimit < rightLimit) {
ct.setSimpleColumn(leftLimit, bry - 0.001f, rightLimit, tly); ct.setSimpleColumn(leftLimit, bry - 0.001f, rightLimit, tly);
if (cell.getRotation() == 180) { if (cell.getRotation() == 180) {
float shx = leftLimit + rightLimit; float shx = leftLimit + rightLimit;
float shy = yPos + yPos - currentMaxHeight + cell.getEffectivePaddingBottom() - cell.getEffectivePaddingTop(); float shy = yPos + yPos - currentMaxHeight + cell.getEffectivePaddingBottom() - cell.getEffectivePaddingTop();
saveAndRotateCanvases(canvases, -1,0,0,-1,shx,shy); saveAndRotateCanvases(canvases, -1,0,0,-1,shx,shy);
} }
try { try {
ct.go(); ct.go();
} catch (DocumentException e) { } catch (DocumentException e) {
throw new ExceptionConverter(e); throw new ExceptionConverter(e);
} finally { } finally {
if (cell.getRotation() == 180) { if (cell.getRotation() == 180) {
restoreCanvases(canvases); restoreCanvases(canvases);
} }
} }
} }
} }
} }
PdfPCellEvent evt = cell.getCellEvent(); PdfPCellEvent evt = cell.getCellEvent();
if (evt != null) { if (evt != null) {
Rectangle rect = new Rectangle(cell.getLeft() + xPos, cell.getTop() Rectangle rect = new Rectangle(cell.getLeft() + xPos, cell.getTop()
@ -523,10 +519,10 @@ public class PdfPRow {
} }
} }
} }
/** /**
* Checks if the dimensions of the columns were calculated. * Checks if the dimensions of the columns were calculated.
* *
* @return true if the dimensions of the columns were calculated * @return true if the dimensions of the columns were calculated
*/ */
public boolean isCalculated() { public boolean isCalculated() {
@ -535,7 +531,7 @@ public class PdfPRow {
/** /**
* Gets the maximum height of the row (i.e. of the 'highest' cell). * Gets the maximum height of the row (i.e. of the 'highest' cell).
* *
* @return the maximum height of the row * @return the maximum height of the row
*/ */
public float getMaxHeights() { public float getMaxHeights() {
@ -547,7 +543,7 @@ public class PdfPRow {
/** /**
* Changes the maximum height of the row (to make it higher). * Changes the maximum height of the row (to make it higher).
* (added by Jin-Hsia Yang) * (added by Jin-Hsia Yang)
* *
* @param maxHeight the new maximum height * @param maxHeight the new maximum height
*/ */
public void setMaxHeights(float maxHeight) { public void setMaxHeights(float maxHeight) {
@ -578,7 +574,7 @@ public class PdfPRow {
* Splits a row to newHeight. * Splits a row to newHeight.
* The returned row is the remainder. It will return null if the newHeight * The returned row is the remainder. It will return null if the newHeight
* was so small that only an empty row would result. * was so small that only an empty row would result.
* *
* @param new_height the new height * @param new_height the new height
* @return the remainder row or null if the newHeight was so small that only * @return the remainder row or null if the newHeight was so small that only
* an empty row would result * an empty row would result
@ -619,22 +615,22 @@ public class PdfPRow {
} }
} }
else { else {
float y; float y;
ColumnText ct = ColumnText.duplicate(cell.getColumn()); ColumnText ct = ColumnText.duplicate(cell.getColumn());
float left = cell.getLeft() + cell.getEffectivePaddingLeft(); float left = cell.getLeft() + cell.getEffectivePaddingLeft();
float bottom = cell.getTop() + cell.getEffectivePaddingBottom() - newHeight; float bottom = cell.getTop() + cell.getEffectivePaddingBottom() - newHeight;
float right = cell.getRight() - cell.getEffectivePaddingRight(); float right = cell.getRight() - cell.getEffectivePaddingRight();
float top = cell.getTop() - cell.getEffectivePaddingTop(); float top = cell.getTop() - cell.getEffectivePaddingTop();
switch (cell.getRotation()) { switch (cell.getRotation()) {
case 90: case 90:
case 270: case 270:
y = setColumn(ct, bottom, left, top, right); y = setColumn(ct, bottom, left, top, right);
break; break;
default: default:
y = setColumn(ct, left, bottom, cell.isNoWrap() ? RIGHT_LIMIT : right, top); y = setColumn(ct, left, bottom, cell.isNoWrap() ? RIGHT_LIMIT : right, top);
break; break;
} }
int status; int status;
try { try {
status = ct.go(true); status = ct.go(true);
} }
@ -648,7 +644,7 @@ public class PdfPRow {
} }
else if ((status & ColumnText.NO_MORE_TEXT) == 0) { else if ((status & ColumnText.NO_MORE_TEXT) == 0) {
newCell.setColumn(ct); newCell.setColumn(ct);
ct.setFilledWidth(0); ct.setFilledWidth(0);
} }
else else
newCell.setPhrase(null); newCell.setPhrase(null);
@ -675,12 +671,12 @@ public class PdfPRow {
split.calculateHeights(); split.calculateHeights();
return split; return split;
} }
/** /**
* Returns the array of cells in the row. * Returns the array of cells in the row.
* Please be extremely careful with this method. * Please be extremely careful with this method.
* Use the cells as read only objects. * Use the cells as read only objects.
* *
* @return an array of cells * @return an array of cells
* @since 2.1.1 * @since 2.1.1
*/ */

1084
fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfPTable.java

File diff suppressed because it is too large Load Diff

54
fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/TableProperties.java

@ -0,0 +1,54 @@
package com.fr.third.com.lowagie.text.pdf;
import com.fr.third.com.lowagie.text.pdf.BorderStyle;
/**
* 描述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 isCollapse() ? 0 : 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();
}
}

3
fine-itext-old/src/com/fr/third/com/lowagie/text/rtf/text/RtfChunk.java

@ -59,6 +59,7 @@ import com.fr.third.com.lowagie.text.rtf.RtfElement;
import com.fr.third.com.lowagie.text.rtf.document.RtfDocument; import com.fr.third.com.lowagie.text.rtf.document.RtfDocument;
import com.fr.third.com.lowagie.text.rtf.style.RtfColor; import com.fr.third.com.lowagie.text.rtf.style.RtfColor;
import com.fr.third.com.lowagie.text.rtf.style.RtfFont; import com.fr.third.com.lowagie.text.rtf.style.RtfFont;
import com.fr.third.v2.lowagie.text.html.Markup;
/** /**
@ -126,7 +127,7 @@ public class RtfChunk extends RtfElement {
this.superSubScript = ((Float)chunk.getAttributes().get(Chunk.SUBSUPSCRIPT)).floatValue(); this.superSubScript = ((Float)chunk.getAttributes().get(Chunk.SUBSUPSCRIPT)).floatValue();
} }
if(chunk.getAttributes() != null && chunk.getAttributes().get(Chunk.BACKGROUND) != null) { if(chunk.getAttributes() != null && chunk.getAttributes().get(Chunk.BACKGROUND) != null) {
this.background = new RtfColor(this.document, (Color) ((Object[]) chunk.getAttributes().get(Chunk.BACKGROUND))[0]); this.background = new RtfColor(this.document, Markup.decodeColor((String)((Object[]) chunk.getAttributes().get(Chunk.BACKGROUND))[0]));
} }
font = new RtfFont(doc, chunk.getFont()); font = new RtfFont(doc, chunk.getFont());
content = chunk.getContent(); content = chunk.getContent();

Loading…
Cancel
Save