From 9ed5213d06606cc11b3f080e0611aceb8570aaeb Mon Sep 17 00:00:00 2001 From: kerry Date: Thu, 22 Nov 2018 14:05:17 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-11624=20Excel=E5=92=8CWord=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E7=9A=84html=E8=A7=A3=E6=9E=90(third=E9=83=A8?= =?UTF-8?q?=E5=88=86)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/third/com/lowagie/text/Chunk.java | 158 +-- .../com/fr/third/com/lowagie/text/Font.java | 33 +- .../com/fr/third/com/lowagie/text/Image.java | 689 ++++++----- .../com/fr/third/com/lowagie/text/List.java | 399 +++--- .../fr/third/com/lowagie/text/Paragraph.java | 140 ++- .../text/factories/ElementFactory.java | 2 +- .../fr/third/com/lowagie/text/html/CSS.java | 200 +++ .../third/com/lowagie/text/html/CSSUtils.java | 108 ++ .../lowagie/text/html/IndentAttribute.java | 55 + .../third/com/lowagie/text/html/Markup.java | 139 ++- .../text/html/ParseIndentAttrUtils.java | 84 ++ .../com/lowagie/text/html/WebColors.java | 4 +- .../html/simpleparser/ChainedProperties.java | 67 + .../html/simpleparser/FactoryProperties.java | 82 +- .../text/html/simpleparser/HTMLWorker.java | 103 +- .../text/html/simpleparser/HtmlConstants.java | 45 + .../text/html/simpleparser/IncCell.java | 94 +- .../text/html/simpleparser/IncTable.java | 110 +- .../com/lowagie/text/pdf/BorderStyle.java | 58 + .../third/com/lowagie/text/pdf/PdfPCell.java | 539 ++++---- .../third/com/lowagie/text/pdf/PdfPRow.java | 490 ++++---- .../third/com/lowagie/text/pdf/PdfPTable.java | 1084 +++++++++-------- .../com/lowagie/text/pdf/TableProperties.java | 54 + .../com/lowagie/text/rtf/text/RtfChunk.java | 3 +- 24 files changed, 2869 insertions(+), 1871 deletions(-) mode change 100755 => 100644 fine-itext-old/src/com/fr/third/com/lowagie/text/Chunk.java create mode 100644 fine-itext-old/src/com/fr/third/com/lowagie/text/html/CSS.java create mode 100644 fine-itext-old/src/com/fr/third/com/lowagie/text/html/CSSUtils.java create mode 100644 fine-itext-old/src/com/fr/third/com/lowagie/text/html/IndentAttribute.java create mode 100644 fine-itext-old/src/com/fr/third/com/lowagie/text/html/ParseIndentAttrUtils.java mode change 100755 => 100644 fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/FactoryProperties.java mode change 100755 => 100644 fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/HTMLWorker.java create mode 100644 fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/HtmlConstants.java create mode 100644 fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/BorderStyle.java create mode 100644 fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/TableProperties.java diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/Chunk.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/Chunk.java old mode 100755 new mode 100644 index 351679d97..1aa543272 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/Chunk.java +++ b/fine-itext-old/src/com/fr/third/com/lowagie/text/Chunk.java @@ -49,16 +49,18 @@ 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.PdfAction; 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.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 @@ -122,7 +124,7 @@ public class Chunk implements Element { /** * A Chunk copy constructor. * @param ck the Chunk to be copied - */ + */ public Chunk(Chunk ck) { if (ck.content != null) { content = new StringBuffer(ck.content.toString()); @@ -134,11 +136,11 @@ public class Chunk implements Element { attributes = new HashMap(ck.attributes); } } - + /** * Constructs a chunk of text with a certain content and a certain * Font. - * + * * @param content * the content * @param font @@ -152,7 +154,7 @@ public class Chunk implements Element { /** * Constructs a chunk of text with a certain content, without specifying a * Font. - * + * * @param content * the content */ @@ -162,7 +164,7 @@ public class Chunk implements Element { /** * Constructs a chunk of text with a char and a certain Font. - * + * * @param c * the content * @param font @@ -177,7 +179,7 @@ public class Chunk implements Element { /** * Constructs a chunk of text with a char, without specifying a Font * . - * + * * @param c * the content */ @@ -187,7 +189,7 @@ public class Chunk implements Element { /** * Constructs a chunk containing an Image. - * + * * @param image * the image * @param offsetX @@ -208,7 +210,7 @@ public class Chunk implements Element { * @since 2.1.2 */ public static final String SEPARATOR = "SEPARATOR"; - + /** * Creates a separator Chunk. * 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) { this(separator, false); - } - + } + /** * Creates a separator Chunk. * 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 */ public static final String TAB = "TAB"; - + /** * Creates a tab Chunk. * 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) { this(separator, tabPosition, false); } - + /** * Creates a tab Chunk. * 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 Image. - * + * * @param image * the image * @param offsetX @@ -277,7 +279,7 @@ public class Chunk implements Element { * true if the leading has to be adapted to the image */ public Chunk(Image image, float offsetX, float offsetY, - boolean changeLeading) { + boolean changeLeading) { this(OBJECT_REPLACEMENT_CHARACTER, new Font()); setAttribute(IMAGE, new Object[] { image, new Float(offsetX), 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 * ElementListener. - * + * * @param listener * an ElementListener * @return true if the element was processed successfully @@ -303,7 +305,7 @@ public class Chunk implements Element { /** * Gets the type of the text element. - * + * * @return a type */ public int type() { @@ -312,7 +314,7 @@ public class Chunk implements Element { /** * Gets all the chunks in this element. - * + * * @return an ArrayList */ public ArrayList getChunks() { @@ -325,7 +327,7 @@ public class Chunk implements Element { /** * appends some text to this Chunk. - * + * * @param string * String * @return a StringBuffer @@ -336,7 +338,7 @@ public class Chunk implements Element { /** * Sets the font of this Chunk. - * + * * @param font * a Font */ @@ -348,7 +350,7 @@ public class Chunk implements Element { /** * Gets the font of this Chunk. - * + * * @return a Font */ public Font getFont() { @@ -357,7 +359,7 @@ public class Chunk implements Element { /** * Returns the content of this Chunk. - * + * * @return a String */ public String getContent() { @@ -366,7 +368,7 @@ public class Chunk implements Element { /** * Returns the content of this Chunk. - * + * * @return a String */ public String toString() { @@ -375,7 +377,7 @@ public class Chunk implements Element { /** * Checks is this Chunk is empty. - * + * * @return false if the Chunk contains other characters than * space. */ @@ -387,23 +389,23 @@ public class Chunk implements Element { /** * Gets the width of the Chunk in points. - * + * * @return a width in points */ public float getWidthPoint() { if (getImage() != null) { return getImage().getScaledWidth(); } - return font.getCalculatedBaseFont(true).getWidthPoint(getContent(), - font.getCalculatedSize()) - * getHorizontalScaling(); + java.awt.Font awtFont = new java.awt.Font(font.getFontName(), font.getStyle(), (int)font.getSize()); + FontMetrics metrics = FontDesignMetrics.getMetrics(awtFont); + return metrics.stringWidth(getContent())* getHorizontalScaling(); } // attributes /** * Checks the attributes of this Chunk. - * + * * @return false if there aren't any. */ @@ -415,7 +417,7 @@ public class Chunk implements Element { * Gets the attributes for this Chunk. *

* It may be null. - * + * * @return the attributes for this Chunk */ @@ -433,7 +435,7 @@ public class Chunk implements Element { /** * Sets an arbitrary attribute. - * + * * @param name * the key for the attribute * @param obj @@ -441,7 +443,7 @@ public class Chunk implements Element { * @return this Chunk */ - private Chunk setAttribute(String name, Object obj) { + public Chunk setAttribute(String name, Object obj) { if (attributes == null) attributes = new HashMap(); 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 * 0.5f shrinks the text to half it's width. - * + * * @param scale * the horizontal scaling factor * @return this Chunk @@ -467,7 +469,7 @@ public class Chunk implements Element { /** * Gets the horizontal scaling. - * + * * @return a percentage in float */ public float getHorizontalScaling() { @@ -487,7 +489,7 @@ public class Chunk implements Element { * Actually, the line can be anywhere vertically and has always the * Chunk width. Multiple call to this method will produce multiple * lines. - * + * * @param thickness * the absolute thickness of the line * @param yPosition @@ -504,7 +506,7 @@ public class Chunk implements Element { * Actually, the line can be anywhere vertically and has always the * Chunk width. Multiple call to this method will produce multiple * lines. - * + * * @param color * the color of the line or null to follow the * text color @@ -523,7 +525,7 @@ public class Chunk implements Element { * @return this Chunk */ public Chunk setUnderline(Color color, float thickness, float thicknessMul, - float yPosition, float yPositionMul, int cap) { + float yPosition, float yPositionMul, int cap) { if (attributes == null) attributes = new HashMap(); Object obj[] = { @@ -533,16 +535,16 @@ public class Chunk implements Element { obj); return setAttribute(UNDERLINE, unders); } - + /** Key for sub/superscript. */ public static final String SUBSUPSCRIPT = "SUBSUPSCRIPT"; - + /** * Sets the text displacement relative to the baseline. Positive values rise * the text, negative values lower the text. *

* It can be used to implement sub/superscript. - * + * * @param rise * the displacement in points * @return this Chunk @@ -554,7 +556,7 @@ public class Chunk implements Element { /** * Gets the text displacement relative to the baseline. - * + * * @return a displacement in points */ public float getTextRise() { @@ -571,7 +573,7 @@ public class Chunk implements Element { /** * Skews the text to simulate italic and other effects. Try alpha=0 * and beta=12. - * + * * @param alpha * the first angle in degrees * @param beta @@ -589,19 +591,19 @@ public class Chunk implements Element { /** * Sets the color of the background Chunk. - * - * @param color + * + * @param background * the color of the background * @return this Chunk */ - public Chunk setBackground(Color color) { - return setBackground(color, 0, 0, 0, 0); + public Chunk setBackground(String background) { + return setBackground(background, 0, 0, 0, 0); } /** * Sets the color and the size of the background Chunk. - * - * @param color + * + * @param background * the color of the background * @param extraLeft * 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 * @return this Chunk */ - public Chunk setBackground(Color color, float extraLeft, float extraBottom, - float extraRight, float extraTop) { - return setAttribute(BACKGROUND, new Object[] { color, + public Chunk setBackground(String background, float extraLeft, float extraBottom, + float extraRight, float extraTop) { + return setAttribute(BACKGROUND, new Object[] { background, 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 * text invisible. - * + * * @param mode * the text rendering mode. It can be * PdfContentByte.TEXT_RENDER_MODE_FILL, @@ -642,7 +644,7 @@ public class Chunk implements Element { * @return this Chunk */ public Chunk setTextRenderMode(int mode, float strokeWidth, - Color strokeColor) { + Color strokeColor) { return setAttribute(TEXTRENDERMODE, new Object[] { new Integer(mode), new Float(strokeWidth), strokeColor }); } @@ -652,7 +654,7 @@ public class Chunk implements Element { /** * Sets the split characters. - * + * * @param splitCharacter * the SplitCharacter interface * @return this Chunk @@ -664,10 +666,10 @@ public class Chunk implements Element { /** Key for hyphenation. */ public static final String HYPHENATION = "HYPHENATION"; - + /** * sets the hyphenation engine to this Chunk. - * + * * @param hyphenation * the hyphenation engine * @return this Chunk @@ -681,7 +683,7 @@ public class Chunk implements Element { /** * Sets a goto for a remote destination for this Chunk. - * + * * @param filename * the file name of the destination document * @param name @@ -695,7 +697,7 @@ public class Chunk implements Element { /** * Sets a goto for a remote destination for this Chunk. - * + * * @param filename * the file name of the destination document * @param page @@ -710,12 +712,12 @@ public class Chunk implements Element { /** Key for local goto. */ public static final String LOCALGOTO = "LOCALGOTO"; - + /** * Sets a local goto for this Chunk. *

* There must be a local destination matching the name. - * + * * @param name * the name of the destination to go to * @return this Chunk @@ -730,7 +732,7 @@ public class Chunk implements Element { /** * Sets a local destination for this Chunk. - * + * * @param name * the name for this destination * @return this Chunk @@ -746,7 +748,7 @@ public class Chunk implements Element { * Sets the generic tag Chunk. *

* The text for this tag can be retrieved with PdfPageEvent. - * + * * @param text * the text for the tag * @return this Chunk @@ -755,13 +757,13 @@ public class Chunk implements Element { public Chunk setGenericTag(String text) { return setAttribute(GENERICTAG, text); } - + /** Key for image. */ public static final String IMAGE = "IMAGE"; /** * Returns the image. - * + * * @return the image */ @@ -775,13 +777,13 @@ public class Chunk implements Element { return (Image) obj[0]; } } - + /** Key for Action. */ public static final String ACTION = "ACTION"; /** * Sets an action for this Chunk. - * + * * @param action * the action * @return this Chunk @@ -793,7 +795,7 @@ public class Chunk implements Element { /** * Sets an anchor for this Chunk. - * + * * @param url * the URL to link to * @return this Chunk @@ -805,7 +807,7 @@ public class Chunk implements Element { /** * Sets an anchor for this Chunk. - * + * * @param url * the url to link to * @return this Chunk @@ -814,13 +816,13 @@ public class Chunk implements Element { public Chunk setAnchor(String url) { return setAttribute(ACTION, new PdfAction(url)); } - + /** Key for newpage. */ public static final String NEWPAGE = "NEWPAGE"; /** * Sets a new page tag.. - * + * * @return this Chunk */ @@ -833,7 +835,7 @@ public class Chunk implements Element { /** * Sets a generic annotation to this Chunk. - * + * * @param annotation * the annotation * @return this Chunk @@ -841,9 +843,9 @@ public class Chunk implements Element { public Chunk setAnnotation(PdfAnnotation annotation) { return setAttribute(PDFANNOTATION, annotation); } - + /** - * @see com.fr.third.com.lowagie.text.Element#isContent() + * @see Element#isContent() * @since iText 2.0.8 */ 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 */ public boolean isNestable() { diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/Font.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/Font.java index 4d136c80c..e0baa558a 100644 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/Font.java +++ b/fine-itext-old/src/com/fr/third/com/lowagie/text/Font.java @@ -350,35 +350,7 @@ public class Font implements Comparable { * @return the familyname */ public String getFamilyname() { - String tmp = "unknown"; - 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; + return getFontName(); } /** @@ -389,9 +361,10 @@ public class Font implements Comparable { * A String representing a certain font-family. */ public void setFamily(String family) { - this.family = getFamilyIndex(family); + this.fontName = family; } + /** * Translates a String -value of a certain family into the * index that is used for this family in this class. diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/Image.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/Image.java index d96f82158..f219cce98 100755 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/Image.java +++ b/fine-itext-old/src/com/fr/third/com/lowagie/text/Image.java @@ -49,15 +49,6 @@ package com.fr.third.com.lowagie.text; -import java.awt.Graphics2D; -import java.awt.color.ICC_Profile; -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Constructor; -import java.net.MalformedURLException; -import java.net.URL; - import com.fr.third.com.lowagie.text.pdf.PRIndirectReference; import com.fr.third.com.lowagie.text.pdf.PdfArray; import com.fr.third.com.lowagie.text.pdf.PdfContentByte; @@ -79,10 +70,19 @@ import com.fr.third.com.lowagie.text.pdf.codec.JBIG2Image; import com.fr.third.com.lowagie.text.pdf.codec.PngImage; import com.fr.third.com.lowagie.text.pdf.codec.TiffImage; +import java.awt.Graphics2D; +import java.awt.color.ICC_Profile; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Constructor; +import java.net.MalformedURLException; +import java.net.URL; + /** * An Image is the representation of a graphic element (JPEG, PNG * or GIF) that has to be inserted into the document - * + * * @see Element * @see Rectangle */ @@ -155,7 +155,7 @@ public abstract class Image extends Rectangle { public static final int ORIGINAL_WMF = 6; /** type of image */ - public static final int ORIGINAL_PS = 7; + public static final int ORIGINAL_PS = 7; /** type of image */ public static final int ORIGINAL_JPEG2000 = 8; @@ -165,8 +165,8 @@ public abstract class Image extends Rectangle { * @since 2.1.5 */ public static final int ORIGINAL_JBIG2 = 9; - - // member variables + + // member variables /** The image type. */ protected int type; @@ -179,7 +179,7 @@ public abstract class Image extends Rectangle { /** The bits per component of the raw image. It also flags a CCITT image. */ protected int bpc = 1; - + /** The template to be treated as an image. */ protected PdfTemplate template[] = new PdfTemplate[1]; @@ -206,21 +206,31 @@ public abstract class Image extends Rectangle { /** This is the original height of the image taking rotation into account. */ protected float scaledHeight; - - /** - * The compression level of the content streams. - * @since 2.1.3 - */ - protected int compressionLevel = PdfStream.DEFAULT_COMPRESSION; + + /** + * The compression level of the content streams. + * @since 2.1.3 + */ + protected int compressionLevel = PdfStream.DEFAULT_COMPRESSION; /** an iText attributed unique id for this image. */ protected Long mySerialId = getSerialId(); // image from file or URL - + + private String srcString = ""; + + public String getSrcString() { + return srcString; + } + + public void setSrcString(String srcString) { + this.srcString = srcString; + } + /** * Constructs an Image -object, using an url . - * + * * @param url * the URL where the image can be found. */ @@ -233,7 +243,7 @@ public abstract class Image extends Rectangle { /** * Gets an instance of an Image. - * + * * @param url * an URL * @return an Image @@ -288,7 +298,7 @@ public abstract class Image extends Rectangle { try { if (url.getProtocol().equals("file")) { String file = url.getFile(); - file = Utilities.unEscapeURL(file); + file = Utilities.unEscapeURL(file); ra = new RandomAccessFileOrArray(file); } else ra = new RandomAccessFileOrArray(url); @@ -308,20 +318,22 @@ public abstract class Image extends Rectangle { if (url.getProtocol().equals("file")) { String file = url.getFile(); file = Utilities.unEscapeURL(file); - ra = new RandomAccessFileOrArray(file); + ra = new RandomAccessFileOrArray(file); } else ra = new RandomAccessFileOrArray(url); Image img = JBIG2Image.getJbig2Image(ra, 1); img.url = url; return img; } finally { - if (ra != null) - ra.close(); + if (ra != null) + ra.close(); } } throw new IOException(url.toString() + " is not a recognized imageformat."); - } finally { + }catch (Exception e){ + return null; + }finally { if (is != null) { is.close(); } @@ -330,7 +342,7 @@ public abstract class Image extends Rectangle { /** * Gets an instance of an Image. - * + * * @param filename * a filename * @return an object of type Gif,Jpeg or @@ -343,10 +355,10 @@ public abstract class Image extends Rectangle { throws BadElementException, MalformedURLException, IOException { return getInstance(Utilities.toURL(filename)); } - + /** * gets an instance of an Image - * + * * @param imgb * raw image date * @return an Image object @@ -395,8 +407,8 @@ public abstract class Image extends Rectangle { try { ra = new RandomAccessFileOrArray(imgb); Image img = TiffImage.getTiffImage(ra, 1); - if (img.getOriginalData() == null) - img.setOriginalData(imgb); + if (img.getOriginalData() == null) + img.setOriginalData(imgb); return img; } finally { if (ra != null) @@ -418,7 +430,7 @@ public abstract class Image extends Rectangle { number_of_pages = (is.read() << 24) | (is.read() << 16) | (is.read() << 8) | is.read(); } is.close(); - // a jbig2 file with a file header. the header is the only way we know here. + // a jbig2 file with a file header. the header is the only way we know here. // embedded jbig2s don't have a header, have to create them by explicit use of Jbig2Image? // nkerr, 2008-12-05 see also the getInstance(URL) RandomAccessFileOrArray ra = null; @@ -445,7 +457,7 @@ public abstract class Image extends Rectangle { /** * Gets an instance of an Image in raw mode. - * + * * @param width * the width of the image in pixels * @param height @@ -461,7 +473,7 @@ public abstract class Image extends Rectangle { * on error */ public static Image getInstance(int width, int height, int components, - int bpc, byte data[]) throws BadElementException { + int bpc, byte data[]) throws BadElementException { return Image.getInstance(width, height, components, bpc, data, null); } @@ -477,11 +489,11 @@ public abstract class Image extends Rectangle { Image img = new ImgJBIG2(width, height, data, globals); return img; } - + /** * Creates an Image with CCITT G3 or G4 compression. It assumes that the * data bytes are already compressed. - * + * * @param width * the exact width of the image * @param height @@ -503,7 +515,7 @@ public abstract class Image extends Rectangle { * on error */ public static Image getInstance(int width, int height, boolean reverseBits, - int typeCCITT, int parameters, byte[] data) + int typeCCITT, int parameters, byte[] data) throws BadElementException { return Image.getInstance(width, height, reverseBits, typeCCITT, parameters, data, null); @@ -512,7 +524,7 @@ public abstract class Image extends Rectangle { /** * Creates an Image with CCITT G3 or G4 compression. It assumes that the * data bytes are already compressed. - * + * * @param width * the exact width of the image * @param height @@ -537,7 +549,7 @@ public abstract class Image extends Rectangle { * on error */ public static Image getInstance(int width, int height, boolean reverseBits, - int typeCCITT, int parameters, byte[] data, int transparency[]) + int typeCCITT, int parameters, byte[] data, int transparency[]) throws BadElementException { if (transparency != null && transparency.length != 2) throw new BadElementException( @@ -550,7 +562,7 @@ public abstract class Image extends Rectangle { /** * Gets an instance of an Image in raw mode. - * + * * @param width * the width of the image in pixels * @param height @@ -569,7 +581,7 @@ public abstract class Image extends Rectangle { * on error */ public static Image getInstance(int width, int height, int components, - int bpc, byte data[], int transparency[]) + int bpc, byte data[], int transparency[]) throws BadElementException { if (transparency != null && transparency.length != components * 2) throw new BadElementException( @@ -585,10 +597,10 @@ public abstract class Image extends Rectangle { } // images from a PdfTemplate - + /** * gets an instance of an Image - * + * * @param template * a PdfTemplate that has to be wrapped in an Image object * @return an Image object @@ -598,12 +610,12 @@ public abstract class Image extends Rectangle { throws BadElementException { return new ImgTemplate(template); } - - // images from a java.awt.Image - + + // images from a java.awt.Image + /** * Gets an instance of an Image from a java.awt.Image. - * + * * @param image * the java.awt.Image to convert * @param color @@ -618,15 +630,15 @@ public abstract class Image extends Rectangle { * on error */ public static Image getInstance(java.awt.Image image, java.awt.Color color, - boolean forceBW) throws BadElementException, IOException { - + boolean forceBW) throws BadElementException, IOException { + if(image instanceof BufferedImage){ BufferedImage bi = (BufferedImage) image; if(bi.getType()==BufferedImage.TYPE_BYTE_BINARY) { forceBW=true; } } - + java.awt.image.PixelGrabber pg = new java.awt.image.PixelGrabber(image, 0, 0, -1, -1, true); try { @@ -775,7 +787,7 @@ public abstract class Image extends Rectangle { /** * Gets an instance of an Image from a java.awt.Image. - * + * * @param image * the java.awt.Image to convert * @param color @@ -791,11 +803,11 @@ public abstract class Image extends Rectangle { throws BadElementException, IOException { return Image.getInstance(image, color, false); } - + /** * Gets an instance of a Image from a java.awt.Image. * The image is added as a JPEG with a user defined quality. - * + * * @param writer * the PdfWriter object to which the image will be added * @param awtImage @@ -810,102 +822,102 @@ public abstract class Image extends Rectangle { public static Image getInstance(PdfWriter writer, java.awt.Image awtImage, float quality) throws BadElementException, IOException { return getInstance(new PdfContentByte(writer), awtImage, quality); } - - /** - * Gets an instance of a Image from a java.awt.Image. - * The image is added as a JPEG with a user defined quality. - * - * @param cb - * the PdfContentByte object to which the image will be added - * @param awtImage - * the java.awt.Image to convert - * @param quality - * a float value between 0 and 1 - * @return an object of type PdfTemplate - * @throws BadElementException - * on error - * @throws IOException - */ - public static Image getInstance(PdfContentByte cb, java.awt.Image awtImage, float quality) throws BadElementException, IOException { - java.awt.image.PixelGrabber pg = new java.awt.image.PixelGrabber(awtImage, - 0, 0, -1, -1, true); - try { - pg.grabPixels(); - } catch (InterruptedException e) { - throw new IOException( - "java.awt.Image Interrupted waiting for pixels!"); - } - if ((pg.getStatus() & java.awt.image.ImageObserver.ABORT) != 0) { - throw new IOException("java.awt.Image fetch aborted or errored"); - } - int w = pg.getWidth(); - int h = pg.getHeight(); - PdfTemplate tp = cb.createTemplate(w, h); - Graphics2D g2d = tp.createGraphics(w, h, true, quality); - g2d.drawImage(awtImage, 0, 0, null); - g2d.dispose(); - return getInstance(tp); - } - - // image from indirect reference - - /** - * Holds value of property directReference. - * An image is embedded into a PDF as an Image XObject. - * This object is referenced by a PdfIndirectReference object. - */ - private PdfIndirectReference directReference; - - /** - * Getter for property directReference. - * @return Value of property directReference. - */ - public PdfIndirectReference getDirectReference() { - return this.directReference; - } - - /** - * Setter for property directReference. - * @param directReference New value of property directReference. - */ - public void setDirectReference(PdfIndirectReference directReference) { - this.directReference = directReference; - } - - /** - * Reuses an existing image. - * @param ref the reference to the image dictionary - * @throws BadElementException on error - * @return the image - */ - public static Image getInstance(PRIndirectReference ref) throws BadElementException { - PdfDictionary dic = (PdfDictionary)PdfReader.getPdfObjectRelease(ref); - int width = ((PdfNumber)PdfReader.getPdfObjectRelease(dic.get(PdfName.WIDTH))).intValue(); - int height = ((PdfNumber)PdfReader.getPdfObjectRelease(dic.get(PdfName.HEIGHT))).intValue(); - Image imask = null; - PdfObject obj = dic.get(PdfName.SMASK); - if (obj != null && obj.isIndirect()) { - imask = getInstance((PRIndirectReference)obj); - } - else { - obj = dic.get(PdfName.MASK); - if (obj != null && obj.isIndirect()) { - PdfObject obj2 = PdfReader.getPdfObjectRelease(obj); - if (obj2 instanceof PdfDictionary) - imask = getInstance((PRIndirectReference)obj); - } - } - Image img = new ImgRaw(width, height, 1, 1, null); - img.imageMask = imask; - img.directReference = ref; - return img; - } - - // copy constructor - + + /** + * Gets an instance of a Image from a java.awt.Image. + * The image is added as a JPEG with a user defined quality. + * + * @param cb + * the PdfContentByte object to which the image will be added + * @param awtImage + * the java.awt.Image to convert + * @param quality + * a float value between 0 and 1 + * @return an object of type PdfTemplate + * @throws BadElementException + * on error + * @throws IOException + */ + public static Image getInstance(PdfContentByte cb, java.awt.Image awtImage, float quality) throws BadElementException, IOException { + java.awt.image.PixelGrabber pg = new java.awt.image.PixelGrabber(awtImage, + 0, 0, -1, -1, true); + try { + pg.grabPixels(); + } catch (InterruptedException e) { + throw new IOException( + "java.awt.Image Interrupted waiting for pixels!"); + } + if ((pg.getStatus() & java.awt.image.ImageObserver.ABORT) != 0) { + throw new IOException("java.awt.Image fetch aborted or errored"); + } + int w = pg.getWidth(); + int h = pg.getHeight(); + PdfTemplate tp = cb.createTemplate(w, h); + Graphics2D g2d = tp.createGraphics(w, h, true, quality); + g2d.drawImage(awtImage, 0, 0, null); + g2d.dispose(); + return getInstance(tp); + } + + // image from indirect reference + + /** + * Holds value of property directReference. + * An image is embedded into a PDF as an Image XObject. + * This object is referenced by a PdfIndirectReference object. + */ + private PdfIndirectReference directReference; + + /** + * Getter for property directReference. + * @return Value of property directReference. + */ + public PdfIndirectReference getDirectReference() { + return this.directReference; + } + + /** + * Setter for property directReference. + * @param directReference New value of property directReference. + */ + public void setDirectReference(PdfIndirectReference directReference) { + this.directReference = directReference; + } + + /** + * Reuses an existing image. + * @param ref the reference to the image dictionary + * @throws BadElementException on error + * @return the image + */ + public static Image getInstance(PRIndirectReference ref) throws BadElementException { + PdfDictionary dic = (PdfDictionary)PdfReader.getPdfObjectRelease(ref); + int width = ((PdfNumber)PdfReader.getPdfObjectRelease(dic.get(PdfName.WIDTH))).intValue(); + int height = ((PdfNumber)PdfReader.getPdfObjectRelease(dic.get(PdfName.HEIGHT))).intValue(); + Image imask = null; + PdfObject obj = dic.get(PdfName.SMASK); + if (obj != null && obj.isIndirect()) { + imask = getInstance((PRIndirectReference)obj); + } + else { + obj = dic.get(PdfName.MASK); + if (obj != null && obj.isIndirect()) { + PdfObject obj2 = PdfReader.getPdfObjectRelease(obj); + if (obj2 instanceof PdfDictionary) + imask = getInstance((PRIndirectReference)obj); + } + } + Image img = new ImgRaw(width, height, 1, 1, null); + img.imageMask = imask; + img.directReference = ref; + return img; + } + + // copy constructor + /** * Constructs an Image -object, using an url . - * + * * @param image * another Image object. */ @@ -913,6 +925,7 @@ public abstract class Image extends Rectangle { super(image); this.type = image.type; this.url = image.url; + this.srcString = image.srcString; this.rawData = image.rawData; this.bpc = image.bpc; this.template = image.template; @@ -926,12 +939,12 @@ public abstract class Image extends Rectangle { this.scaledHeight = image.scaledHeight; this.mySerialId = image.mySerialId; - this.directReference = image.directReference; - + this.directReference = image.directReference; + this.rotationRadians = image.rotationRadians; - this.initialRotation = image.initialRotation; - this.indentationLeft = image.indentationLeft; - this.indentationRight = image.indentationRight; + this.initialRotation = image.initialRotation; + this.indentationLeft = image.indentationLeft; + this.indentationRight = image.indentationRight; this.spacingBefore = image.spacingBefore; this.spacingAfter = image.spacingAfter; @@ -945,7 +958,7 @@ public abstract class Image extends Rectangle { this.dpiX = image.dpiX; this.dpiY = image.dpiY; this.XYRatio = image.XYRatio; - + this.colorspace = image.colorspace; this.invert = image.invert; this.profile = image.profile; @@ -958,7 +971,7 @@ public abstract class Image extends Rectangle { /** * gets an instance of an Image - * + * * @param image * an Image object * @return a new Image object @@ -977,10 +990,10 @@ public abstract class Image extends Rectangle { } // implementation of the Element interface - + /** * Returns the type. - * + * * @return a type */ @@ -989,7 +1002,7 @@ public abstract class Image extends Rectangle { } /** - * @see com.fr.third.com.lowagie.text.Element#isNestable() + * @see Element#isNestable() * @since iText 2.0.8 */ public boolean isNestable() { @@ -1001,7 +1014,7 @@ public abstract class Image extends Rectangle { /** * Returns true if the image is a Jpeg * -object. - * + * * @return a boolean */ @@ -1012,7 +1025,7 @@ public abstract class Image extends Rectangle { /** * Returns true if the image is a ImgRaw * -object. - * + * * @return a boolean */ @@ -1023,20 +1036,20 @@ public abstract class Image extends Rectangle { /** * Returns true if the image is an ImgTemplate * -object. - * + * * @return a boolean */ public boolean isImgTemplate() { return type == IMGTEMPLATE; } - + // getters and setters /** * Gets the String -representation of the reference to the * image. - * + * * @return a String */ @@ -1046,7 +1059,7 @@ public abstract class Image extends Rectangle { /** * Sets the url of the image - * + * * @param url * the url of the image */ @@ -1059,7 +1072,7 @@ public abstract class Image extends Rectangle { *

* Remark: this only makes sense for Images of the type RawImage * . - * + * * @return the raw data */ public byte[] getRawData() { @@ -1071,7 +1084,7 @@ public abstract class Image extends Rectangle { *

* Remark: this only makes sense for Images of the type RawImage * . - * + * * @return a bpc value */ public int getBpc() { @@ -1083,7 +1096,7 @@ public abstract class Image extends Rectangle { *

* Remark: this only makes sense for Images of the type ImgTemplate * . - * + * * @return the template */ public PdfTemplate getTemplateData() { @@ -1092,7 +1105,7 @@ public abstract class Image extends Rectangle { /** * Sets data from a PdfTemplate - * + * * @param template * the template with the content */ @@ -1102,7 +1115,7 @@ public abstract class Image extends Rectangle { /** * Gets the alignment for the image. - * + * * @return a value */ public int getAlignment() { @@ -1111,7 +1124,7 @@ public abstract class Image extends Rectangle { /** * Sets the alignment for the image. - * + * * @param alignment * the alignment */ @@ -1122,7 +1135,7 @@ public abstract class Image extends Rectangle { /** * Gets the alternative text for the image. - * + * * @return a String */ @@ -1132,7 +1145,7 @@ public abstract class Image extends Rectangle { /** * Sets the alternative information for the image. - * + * * @param alt * the alternative information */ @@ -1143,7 +1156,7 @@ public abstract class Image extends Rectangle { /** * Sets the absolute position of the Image. - * + * * @param absoluteX * @param absoluteY */ @@ -1156,7 +1169,7 @@ public abstract class Image extends Rectangle { /** * Checks if the Images has to be added at an absolute X * position. - * + * * @return a boolean */ public boolean hasAbsoluteX() { @@ -1165,7 +1178,7 @@ public abstract class Image extends Rectangle { /** * Returns the absolute X position. - * + * * @return a position */ public float getAbsoluteX() { @@ -1175,7 +1188,7 @@ public abstract class Image extends Rectangle { /** * Checks if the Images has to be added at an absolute * position. - * + * * @return a boolean */ public boolean hasAbsoluteY() { @@ -1184,7 +1197,7 @@ public abstract class Image extends Rectangle { /** * Returns the absolute Y position. - * + * * @return a position */ public float getAbsoluteY() { @@ -1195,7 +1208,7 @@ public abstract class Image extends Rectangle { /** * Gets the scaled width of the image. - * + * * @return a value */ public float getScaledWidth() { @@ -1204,7 +1217,7 @@ public abstract class Image extends Rectangle { /** * Gets the scaled height of the image. - * + * * @return a value */ public float getScaledHeight() { @@ -1213,7 +1226,7 @@ public abstract class Image extends Rectangle { /** * Gets the plain width of the image. - * + * * @return a value */ public float getPlainWidth() { @@ -1222,16 +1235,16 @@ public abstract class Image extends Rectangle { /** * Gets the plain height of the image. - * + * * @return a value */ public float getPlainHeight() { return plainHeight; } - + /** * Scale the image to an absolute width and an absolute height. - * + * * @param newWidth * the new width * @param newHeight @@ -1248,7 +1261,7 @@ public abstract class Image extends Rectangle { /** * Scale the image to an absolute width. - * + * * @param newWidth * the new width */ @@ -1262,7 +1275,7 @@ public abstract class Image extends Rectangle { /** * Scale the image to an absolute height. - * + * * @param newHeight * the new height */ @@ -1276,7 +1289,7 @@ public abstract class Image extends Rectangle { /** * Scale the image to a certain percentage. - * + * * @param percent * the scaling percentage */ @@ -1286,7 +1299,7 @@ public abstract class Image extends Rectangle { /** * Scale the width and height of an image to a certain percentage. - * + * * @param percentX * the scaling percentage of the width * @param percentY @@ -1303,14 +1316,14 @@ public abstract class Image extends Rectangle { /** * Scales the image so that it fits a certain width and height. - * + * * @param fitWidth * the width to fit * @param fitHeight * the height to fit */ public void scaleToFit(float fitWidth, float fitHeight) { - scalePercent(100); + scalePercent(100); float percentX = (fitWidth * 100) / getScaledWidth(); float percentY = (fitHeight * 100) / getScaledHeight(); scalePercent(percentX < percentY ? percentX : percentY); @@ -1319,7 +1332,7 @@ public abstract class Image extends Rectangle { /** * Returns the transformation matrix of the image. - * + * * @return an array [AX, AY, BX, BY, CX, CY, DX, DY] */ public float[] matrix() { @@ -1358,7 +1371,7 @@ public abstract class Image extends Rectangle { /** a static that is used for attributing a unique id to each image. */ static long serialId = 0; - + /** Creates a new serial id. */ static protected synchronized Long getSerialId() { ++serialId; @@ -1367,37 +1380,37 @@ public abstract class Image extends Rectangle { /** * Returns a serial id for the Image (reuse the same image more than once) - * + * * @return a serialId */ public Long getMySerialId() { return mySerialId; } - // rotation, note that the superclass also has a rotation value. + // rotation, note that the superclass also has a rotation value. /** This is the rotation of the image in radians. */ protected float rotationRadians; - - /** Holds value of property initialRotation. */ - private float initialRotation; - - /** - * Gets the current image rotation in radians. - * @return the current image rotation in radians - */ - public float getImageRotation() { + + /** Holds value of property initialRotation. */ + private float initialRotation; + + /** + * Gets the current image rotation in radians. + * @return the current image rotation in radians + */ + public float getImageRotation() { double d = 2.0 * Math.PI; float rot = (float) ((rotationRadians - initialRotation) % d); if (rot < 0) { rot += d; } - return rot; - } - + return rot; + } + /** * Sets the rotation of the image in radians. - * + * * @param r * rotation in radians */ @@ -1414,7 +1427,7 @@ public abstract class Image extends Rectangle { /** * Sets the rotation of the image in degrees. - * + * * @param deg * rotation in degrees */ @@ -1422,27 +1435,27 @@ public abstract class Image extends Rectangle { double d = Math.PI; setRotation(deg / 180 * (float) d); } - - /** - * Getter for property initialRotation. - * @return Value of property initialRotation. - */ - public float getInitialRotation() { - return this.initialRotation; - } - - /** - * Some image formats, like TIFF may present the images rotated that have - * to be compensated. - * @param initialRotation New value of property initialRotation. - */ - public void setInitialRotation(float initialRotation) { - float old_rot = rotationRadians - this.initialRotation; - this.initialRotation = initialRotation; - setRotation(old_rot); - } - - // indentations + + /** + * Getter for property initialRotation. + * @return Value of property initialRotation. + */ + public float getInitialRotation() { + return this.initialRotation; + } + + /** + * Some image formats, like TIFF may present the images rotated that have + * to be compensated. + * @param initialRotation New value of property initialRotation. + */ + public void setInitialRotation(float initialRotation) { + float old_rot = rotationRadians - this.initialRotation; + this.initialRotation = initialRotation; + setRotation(old_rot); + } + + // indentations /** the indentation to the left. */ protected float indentationLeft = 0; @@ -1458,7 +1471,7 @@ public abstract class Image extends Rectangle { /** * Gets the left indentation. - * + * * @return the left indentation */ public float getIndentationLeft() { @@ -1467,7 +1480,7 @@ public abstract class Image extends Rectangle { /** * Sets the left indentation. - * + * * @param f */ public void setIndentationLeft(float f) { @@ -1476,7 +1489,7 @@ public abstract class Image extends Rectangle { /** * Gets the right indentation. - * + * * @return the right indentation */ public float getIndentationRight() { @@ -1485,7 +1498,7 @@ public abstract class Image extends Rectangle { /** * Sets the right indentation. - * + * * @param f */ public void setIndentationRight(float f) { @@ -1494,7 +1507,7 @@ public abstract class Image extends Rectangle { /** * Gets the spacing before this image. - * + * * @return the spacing */ public float getSpacingBefore() { @@ -1503,7 +1516,7 @@ public abstract class Image extends Rectangle { /** * Sets the spacing before this image. - * + * * @param spacing * the new spacing */ @@ -1514,7 +1527,7 @@ public abstract class Image extends Rectangle { /** * Gets the spacing before this image. - * + * * @return the spacing */ public float getSpacingAfter() { @@ -1523,7 +1536,7 @@ public abstract class Image extends Rectangle { /** * Sets the spacing after this image. - * + * * @param spacing * the new spacing */ @@ -1532,16 +1545,16 @@ public abstract class Image extends Rectangle { this.spacingAfter = spacing; } - // widthpercentage (for the moment only used in ColumnText) + // widthpercentage (for the moment only used in ColumnText) /** * Holds value of property widthPercentage. */ private float widthPercentage = 100; - + /** * Getter for property widthPercentage. - * + * * @return Value of property widthPercentage. */ public float getWidthPercentage() { @@ -1550,7 +1563,7 @@ public abstract class Image extends Rectangle { /** * Setter for property widthPercentage. - * + * * @param widthPercentage * New value of property widthPercentage. */ @@ -1558,14 +1571,14 @@ public abstract class Image extends Rectangle { this.widthPercentage = widthPercentage; } - // annotation + // annotation /** if the annotation is not null the image will be clickable. */ protected Annotation annotation = null; - + /** * Sets the annotation of this Image. - * + * * @param annotation * the annotation */ @@ -1575,21 +1588,21 @@ public abstract class Image extends Rectangle { /** * Gets the annotation. - * + * * @return the annotation that is linked to this image */ public Annotation getAnnotation() { return annotation; } - // Optional Content + // Optional Content - /** Optional Content layer to which we want this Image to belong. */ + /** Optional Content layer to which we want this Image to belong. */ protected PdfOCG layer; - + /** * Gets the layer this image belongs to. - * + * * @return the layer this image belongs to or null for no * layer defined */ @@ -1599,7 +1612,7 @@ public abstract class Image extends Rectangle { /** * Sets the layer this image belongs to. - * + * * @param layer * the layer this image belongs to */ @@ -1614,7 +1627,7 @@ public abstract class Image extends Rectangle { /** * Getter for property interpolation. - * + * * @return Value of property interpolation. */ public boolean isInterpolation() { @@ -1624,14 +1637,14 @@ public abstract class Image extends Rectangle { /** * Sets the image interpolation. Image interpolation attempts to produce a * smooth transition between adjacent sample values. - * + * * @param interpolation * New value of property interpolation. */ public void setInterpolation(boolean interpolation) { this.interpolation = interpolation; } - + // original type and data /** Holds value of property originalType. */ @@ -1639,12 +1652,12 @@ public abstract class Image extends Rectangle { /** Holds value of property originalData. */ protected byte[] originalData; - + /** * Getter for property originalType. - * + * * @return Value of property originalType. - * + * */ public int getOriginalType() { return this.originalType; @@ -1652,10 +1665,10 @@ public abstract class Image extends Rectangle { /** * Setter for property originalType. - * + * * @param originalType * New value of property originalType. - * + * */ public void setOriginalType(int originalType) { this.originalType = originalType; @@ -1663,9 +1676,9 @@ public abstract class Image extends Rectangle { /** * Getter for property originalData. - * + * * @return Value of property originalData. - * + * */ public byte[] getOriginalData() { return this.originalData; @@ -1673,25 +1686,25 @@ public abstract class Image extends Rectangle { /** * Setter for property originalData. - * + * * @param originalData * New value of property originalData. - * + * */ public void setOriginalData(byte[] originalData) { this.originalData = originalData; } // the following values are only set for specific types of images. - + /** Holds value of property deflated. */ protected boolean deflated = false; /** * Getter for property deflated. - * + * * @return Value of property deflated. - * + * */ public boolean isDeflated() { return this.deflated; @@ -1699,16 +1712,16 @@ public abstract class Image extends Rectangle { /** * Setter for property deflated. - * + * * @param deflated * New value of property deflated. */ public void setDeflated(boolean deflated) { this.deflated = deflated; } - + // DPI info - + /** Holds value of property dpiX. */ protected int dpiX = 0; @@ -1717,7 +1730,7 @@ public abstract class Image extends Rectangle { /** * Gets the dots-per-inch in the X direction. Returns 0 if not available. - * + * * @return the dots-per-inch in the X direction */ public int getDpiX() { @@ -1726,7 +1739,7 @@ public abstract class Image extends Rectangle { /** * Gets the dots-per-inch in the Y direction. Returns 0 if not available. - * + * * @return the dots-per-inch in the Y direction */ public int getDpiY() { @@ -1735,7 +1748,7 @@ public abstract class Image extends Rectangle { /** * Sets the dots per inch value - * + * * @param dpiX * dpi for x coordinates * @param dpiY @@ -1745,15 +1758,15 @@ public abstract class Image extends Rectangle { this.dpiX = dpiX; this.dpiY = dpiY; } - + // XY Ratio - + /** Holds value of property XYRatio. */ private float XYRatio = 0; /** * Gets the X/Y pixel dimensionless aspect ratio. - * + * * @return the X/Y pixel dimensionless aspect ratio */ public float getXYRatio() { @@ -1762,14 +1775,14 @@ public abstract class Image extends Rectangle { /** * Sets the X/Y pixel dimensionless aspect ratio. - * + * * @param XYRatio * the X/Y pixel dimensionless aspect ratio */ public void setXYRatio(float XYRatio) { this.XYRatio = XYRatio; } - + // color, colorspaces and transparency /** this is the colorspace of a jpeg-image. */ @@ -1779,19 +1792,19 @@ public abstract class Image extends Rectangle { * Gets the colorspace for the image. *

* Remark: this only makes sense for Images of the type Jpeg. - * + * * @return a colorspace value */ public int getColorspace() { return colorspace; } - + /** Image color inversion */ protected boolean invert = false; /** * Getter for the inverted value - * + * * @return true if the image is inverted */ public boolean isInverted() { @@ -1800,7 +1813,7 @@ public abstract class Image extends Rectangle { /** * Sets inverted true or false - * + * * @param invert * true or false */ @@ -1813,7 +1826,7 @@ public abstract class Image extends Rectangle { /** * Tags this image with an ICC profile. - * + * * @param profile * the profile */ @@ -1823,7 +1836,7 @@ public abstract class Image extends Rectangle { /** * Checks is the image has an ICC profile. - * + * * @return the ICC profile or null */ public boolean hasICCProfile() { @@ -1832,7 +1845,7 @@ public abstract class Image extends Rectangle { /** * Gets the images ICC profile. - * + * * @return the ICC profile */ public ICC_Profile getICCProfile() { @@ -1841,10 +1854,10 @@ public abstract class Image extends Rectangle { /** a dictionary with additional information */ private PdfDictionary additional = null; - + /** * Getter for the dictionary with additional information. - * + * * @return a PdfDictionary with additional information. */ public PdfDictionary getAdditional() { @@ -1853,7 +1866,7 @@ public abstract class Image extends Rectangle { /** * Sets the /Colorspace key. - * + * * @param additional * a PdfDictionary with additional information. */ @@ -1861,52 +1874,52 @@ public abstract class Image extends Rectangle { this.additional = additional; } - /** - * Replaces CalRGB and CalGray colorspaces with DeviceRGB and DeviceGray. - */ - public void simplifyColorspace() { - if (additional == null) - return; - PdfArray value = additional.getAsArray(PdfName.COLORSPACE); - if (value == null) - return; - PdfObject cs = simplifyColorspace(value); - PdfObject newValue; - if (cs.isName()) - newValue = cs; - else { - newValue = value; - PdfName first = value.getAsName(0); - if (PdfName.INDEXED.equals(first)) { - if (value.size() >= 2) { - PdfArray second = value.getAsArray(1); - if (second != null) { - value.set(1, simplifyColorspace(second)); - } - } - } - } - additional.put(PdfName.COLORSPACE, newValue); - } - + /** + * Replaces CalRGB and CalGray colorspaces with DeviceRGB and DeviceGray. + */ + public void simplifyColorspace() { + if (additional == null) + return; + PdfArray value = additional.getAsArray(PdfName.COLORSPACE); + if (value == null) + return; + PdfObject cs = simplifyColorspace(value); + PdfObject newValue; + if (cs.isName()) + newValue = cs; + else { + newValue = value; + PdfName first = value.getAsName(0); + if (PdfName.INDEXED.equals(first)) { + if (value.size() >= 2) { + PdfArray second = value.getAsArray(1); + if (second != null) { + value.set(1, simplifyColorspace(second)); + } + } + } + } + additional.put(PdfName.COLORSPACE, newValue); + } + /** * Gets a PDF Name from an array or returns the object that was passed. */ - private PdfObject simplifyColorspace(PdfArray obj) { - if (obj == null) - return obj; - PdfName first = obj.getAsName(0); - if (PdfName.CALGRAY.equals(first)) - return PdfName.DEVICEGRAY; - else if (PdfName.CALRGB.equals(first)) - return PdfName.DEVICERGB; - else - return obj; - } + private PdfObject simplifyColorspace(PdfArray obj) { + if (obj == null) + return obj; + PdfName first = obj.getAsName(0); + if (PdfName.CALGRAY.equals(first)) + return PdfName.DEVICEGRAY; + else if (PdfName.CALRGB.equals(first)) + return PdfName.DEVICERGB; + else + return obj; + } /** Is this image a mask? */ protected boolean mask = false; - + /** The image that serves as a mask for this image. */ protected Image imageMask; @@ -1915,7 +1928,7 @@ public abstract class Image extends Rectangle { /** * Returns true if this Image is a mask. - * + * * @return true if this Image is a mask */ public boolean isMask() { @@ -1924,7 +1937,7 @@ public abstract class Image extends Rectangle { /** * Make this Image a mask. - * + * * @throws DocumentException * if this Image can not be a mask */ @@ -1937,7 +1950,7 @@ public abstract class Image extends Rectangle { /** * Returns true if this Image has the * requisites to be a mask. - * + * * @return true if this Image can be a mask */ public boolean isMaskCandidate() { @@ -1950,7 +1963,7 @@ public abstract class Image extends Rectangle { /** * Gets the explicit masking. - * + * * @return the explicit masking */ public Image getImageMask() { @@ -1959,7 +1972,7 @@ public abstract class Image extends Rectangle { /** * Sets the explicit masking. - * + * * @param mask * the mask to be applied * @throws DocumentException @@ -1978,9 +1991,9 @@ public abstract class Image extends Rectangle { /** * Getter for property smask. - * + * * @return Value of property smask. - * + * */ public boolean isSmask() { return this.smask; @@ -1988,7 +2001,7 @@ public abstract class Image extends Rectangle { /** * Setter for property smask. - * + * * @param smask * New value of property smask. */ @@ -2001,7 +2014,7 @@ public abstract class Image extends Rectangle { /** * Returns the transparency. - * + * * @return the transparency values */ @@ -2011,7 +2024,7 @@ public abstract class Image extends Rectangle { /** * Sets the transparency values - * + * * @param transparency * the transparency values */ @@ -2023,7 +2036,7 @@ public abstract class Image extends Rectangle { /** * Returns the compression level used for images written as a compressed stream. * @return the compression level (0 = best speed, 9 = best compression, -1 is default) - * @since 2.1.3 + * @since 2.1.3 */ public int getCompressionLevel() { return compressionLevel; @@ -2032,7 +2045,7 @@ public abstract class Image extends Rectangle { /** * Sets the compression level to be used if the image is written as a compressed stream. * @param compressionLevel a value between 0 (best speed) and 9 (best compression) - * @since 2.1.3 + * @since 2.1.3 */ public void setCompressionLevel(int compressionLevel) { if (compressionLevel < PdfStream.NO_COMPRESSION || compressionLevel > PdfStream.BEST_COMPRESSION) diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/List.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/List.java index 3b1e41260..7ce95a06d 100755 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/List.java +++ b/fine-itext-old/src/com/fr/third/com/lowagie/text/List.java @@ -49,11 +49,11 @@ package com.fr.third.com.lowagie.text; +import com.fr.third.com.lowagie.text.factories.RomanAlphabetFactory; + import java.util.ArrayList; import java.util.Iterator; -import com.fr.third.com.lowagie.text.factories.RomanAlphabetFactory; - /** * A List contains several ListItems. *

@@ -100,38 +100,47 @@ import com.fr.third.com.lowagie.text.factories.RomanAlphabetFactory; */ public class List implements TextElementArray { - + // constants - - /** a possible value for the numbered parameter */ - public static final boolean ORDERED = true; - /** a possible value for the numbered parameter */ - public static final boolean UNORDERED = false; - /** a possible value for the lettered parameter */ - public static final boolean NUMERICAL = false; - /** a possible value for the lettered parameter */ - public static final boolean ALPHABETICAL = true; - /** a possible value for the lettered parameter */ - public static final boolean UPPERCASE = false; - /** a possible value for the lettered parameter */ - public static final boolean LOWERCASE = true; - + + /** a possible value for the numbered parameter */ + public static final boolean ORDERED = true; + /** a possible value for the numbered parameter */ + public static final boolean UNORDERED = false; + /** a possible value for the lettered parameter */ + public static final boolean NUMERICAL = false; + /** a possible value for the lettered parameter */ + public static final boolean ALPHABETICAL = true; + /** a possible value for the lettered parameter */ + public static final boolean UPPERCASE = false; + /** a possible value for the lettered parameter */ + public static final boolean LOWERCASE = true; + // member variables - - /** This is the ArrayList containing the different ListItems. */ + + /** This is the ArrayList containing the different ListItems. */ protected ArrayList list = new ArrayList(); - + /** Indicates if the list has to be numbered. */ protected boolean numbered = false; /** Indicates if the listsymbols are numerical or alphabetical. */ protected boolean lettered = false; /** Indicates if the listsymbols are lowercase or uppercase. */ 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. */ protected boolean autoindent = false; /** Indicates if the indentation of all the items has to be aligned. */ protected boolean alignindent = false; - + /** This variable indicates the first number of a numbered list. */ protected int first = 1; /** This is the listsymbol of a list that is not numbered. */ @@ -142,54 +151,54 @@ public class List implements TextElementArray { */ 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 */ protected String postSymbol = ". "; - + /** The indentation of this list on the left side. */ protected float indentationLeft = 0; /** The indentation of this list on the right side. */ protected float indentationRight = 0; /** The indentation of the listitems. */ protected float symbolIndent = 0; - + // constructors /** Constructs a List. */ public List() { this(false, false); } - + /** * Constructs a List with a specific symbol indentation. * @param symbolIndent the symbol indentation * @since iText 2.0.8 */ public List(float symbolIndent) { - this.symbolIndent = symbolIndent; + this.symbolIndent = symbolIndent; } - + /** * Constructs a List. * @param numbered a boolean */ public List(boolean numbered) { - this(numbered, false); + this(numbered, false); } - + /** * Constructs a List. * @param numbered a boolean * @param lettered has the list to be 'numbered' with letters */ public List(boolean numbered, boolean lettered) { - this.numbered = numbered; + this.numbered = numbered; this.lettered = lettered; this.autoindent = true; this.alignindent = true; } - + /** * Constructs a List. *

@@ -203,7 +212,7 @@ public class List implements TextElementArray { public List(boolean numbered, float symbolIndent) { this(numbered, false, symbolIndent); } - + /** * Creates a list * @param numbered has the list to be numbered? @@ -215,9 +224,9 @@ public class List implements TextElementArray { this.lettered = lettered; this.symbolIndent = symbolIndent; } - + // implementation of the Element-methods - + /** * Processes the element by adding it (or the different parts) to an * ElementListener. @@ -236,16 +245,16 @@ public class List implements TextElementArray { return false; } } - + /** * Gets the type of the text element. * * @return a type */ public int type() { - return Element.LIST; + return LIST; } - + /** * Gets all the chunks in this element. * @@ -258,9 +267,9 @@ public class List implements TextElementArray { } return tmp; } - + // methods to set the membervariables - + /** * Adds an Object to the List. * @@ -287,8 +296,8 @@ public class List implements TextElementArray { item.setIndentationRight(0); return list.add(item); } - else if (o instanceof List) { - List nested = (List) o; + else if (o instanceof com.fr.third.com.lowagie.text.List) { + com.fr.third.com.lowagie.text.List nested = (com.fr.third.com.lowagie.text.List) o; nested.setIndentationLeft(nested.getIndentationLeft() + symbolIndent); first--; return list.add(nested); @@ -298,63 +307,63 @@ public class List implements TextElementArray { } return false; } - + // 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() { float max = 0; - Element o; + Element o; for (Iterator i = list.iterator(); i.hasNext(); ) { - o = (Element)i.next(); + o = (Element)i.next(); 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(); ) { - o = (Element)i.next(); + o = (Element)i.next(); if (o instanceof ListItem) { - ((ListItem)o).setIndentationLeft(max); + ((ListItem)o).setIndentationLeft(max); } } } - + // setters - /** - * @param numbered the numbered to set - */ - public void setNumbered(boolean numbered) { - this.numbered = numbered; - } - - /** - * @param lettered the lettered to set - */ - public void setLettered(boolean lettered) { - this.lettered = lettered; - } - - /** - * @param uppercase the uppercase to set - */ - public void setLowercase(boolean uppercase) { - this.lowercase = uppercase; - } - - /** - * @param autoindent the autoindent to set - */ - public void setAutoindent(boolean autoindent) { - this.autoindent = autoindent; - } - /** - * @param alignindent the alignindent to set - */ - public void setAlignindent(boolean alignindent) { - this.alignindent = alignindent; - } - + /** + * @param numbered the numbered to set + */ + public void setNumbered(boolean numbered) { + this.numbered = numbered; + } + + /** + * @param lettered the lettered to set + */ + public void setLettered(boolean lettered) { + this.lettered = lettered; + } + + /** + * @param uppercase the uppercase to set + */ + public void setLowercase(boolean uppercase) { + this.lowercase = uppercase; + } + + /** + * @param autoindent the autoindent to set + */ + public void setAutoindent(boolean autoindent) { + this.autoindent = autoindent; + } + /** + * @param alignindent the alignindent to set + */ + public void setAlignindent(boolean alignindent) { + this.alignindent = alignindent; + } + /** * 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) { this.first = first; } - + /** * Sets the listsymbol. * @@ -372,7 +381,7 @@ public class List implements TextElementArray { public void setListSymbol(Chunk symbol) { this.symbol = symbol; } - + /** * Sets the listsymbol. *

@@ -383,7 +392,7 @@ public class List implements TextElementArray { public void setListSymbol(String symbol) { this.symbol = new Chunk(symbol); } - + /** * Sets the indentation of this paragraph on the left side. * @@ -392,7 +401,7 @@ public class List implements TextElementArray { public void setIndentationLeft(float indentation) { this.indentationLeft = indentation; } - + /** * Sets the indentation of this paragraph on the right side. * @@ -402,15 +411,15 @@ public class List implements TextElementArray { this.indentationRight = indentation; } - /** - * @param symbolIndent the symbolIndent to set - */ - public void setSymbolIndent(float symbolIndent) { - this.symbolIndent = symbolIndent; - } - + /** + * @param symbolIndent the symbolIndent to set + */ + public void setSymbolIndent(float symbolIndent) { + this.symbolIndent = symbolIndent; + } + // methods to retrieve information - + /** * Gets all the items in the list. * @@ -419,7 +428,7 @@ public class List implements TextElementArray { public ArrayList getItems() { return list; } - + /** * Gets the size of the list. * @@ -431,11 +440,11 @@ public class List implements TextElementArray { /** * Returns true if the list is empty. - * + * * @return true if the list is empty */ public boolean isEmpty() { - return list.isEmpty(); + return list.isEmpty(); } /** @@ -450,14 +459,14 @@ public class List implements TextElementArray { ListItem item = (ListItem) list.get(0); return item.getTotalLeading(); } - + // getters - + /** * Checks if the list is numbered. * @return true if the list is numbered, false otherwise. */ - + public boolean isNumbered() { return numbered; } @@ -477,112 +486,112 @@ public class List implements TextElementArray { public boolean isLowercase() { return lowercase; } - + /** * Checks if the indentation of list items is done automatically. - * @return the autoindent - */ - public boolean isAutoindent() { - return autoindent; - } - - /** - * Checks if all the listitems should be aligned. - * @return the alignindent - */ - public boolean isAlignindent() { - return alignindent; - } - - /** + * @return the autoindent + */ + public boolean isAutoindent() { + return autoindent; + } + + /** + * Checks if all the listitems should be aligned. + * @return the alignindent + */ + public boolean isAlignindent() { + return alignindent; + } + + /** * Gets the first number . * @return a number - */ - public int getFirst() { - return first; - } + */ + public int getFirst() { + return first; + } - /** + /** * Gets the Chunk containing the symbol. * @return a Chunk with a symbol - */ - public Chunk getSymbol() { - return symbol; - } + */ + public Chunk getSymbol() { + return symbol; + } - /** + /** * Gets the indentation of this paragraph on the left side. * @return the indentation - */ - public float getIndentationLeft() { - return indentationLeft; - } + */ + public float getIndentationLeft() { + return indentationLeft; + } - /** + /** * Gets the indentation of this paragraph on the right side. * @return the indentation - */ - public float getIndentationRight() { - return indentationRight; - } + */ + public float getIndentationRight() { + return indentationRight; + } - /** + /** * Gets the symbol indentation. * @return the symbol indentation - */ - public float getSymbolIndent() { - return symbolIndent; - } - /** - * @see com.fr.third.com.lowagie.text.Element#isContent() - * @since iText 2.0.8 - */ - public boolean isContent() { - return true; - } - - /** - * @see com.fr.third.com.lowagie.text.Element#isNestable() - * @since iText 2.0.8 - */ - public boolean isNestable() { - return true; - } - - /** - * 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 - * @since iText 2.1.1 - */ - public String getPostSymbol() { - return postSymbol; - } - - /** - * Sets the String that has to be added after a number or letter in the list symbol. - * @since iText 2.1.1 - * @param postSymbol the String that has to be added after a number or letter in the list symbol. - */ - public void setPostSymbol(String postSymbol) { - this.postSymbol = postSymbol; - } - - /** - * 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 - * @since iText 2.1.1 - */ - public String getPreSymbol() { - return preSymbol; - } - - /** - * Sets the String that has to be added before a number or letter in the list symbol. - * @since iText 2.1.1 - * @param preSymbol the String that has to be added before a number or letter in the list symbol. - */ - public void setPreSymbol(String preSymbol) { - this.preSymbol = preSymbol; - } - -} \ No newline at end of file + */ + public float getSymbolIndent() { + return symbolIndent; + } + /** + * @see Element#isContent() + * @since iText 2.0.8 + */ + public boolean isContent() { + return true; + } + + /** + * @see Element#isNestable() + * @since iText 2.0.8 + */ + public boolean isNestable() { + return true; + } + + /** + * 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 + * @since iText 2.1.1 + */ + public String getPostSymbol() { + return postSymbol; + } + + /** + * Sets the String that has to be added after a number or letter in the list symbol. + * @since iText 2.1.1 + * @param postSymbol the String that has to be added after a number or letter in the list symbol. + */ + public void setPostSymbol(String postSymbol) { + this.postSymbol = postSymbol; + } + + /** + * 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 + * @since iText 2.1.1 + */ + public String getPreSymbol() { + return preSymbol; + } + + /** + * Sets the String that has to be added before a number or letter in the list symbol. + * @since iText 2.1.1 + * @param preSymbol the String that has to be added before a number or letter in the list symbol. + */ + public void setPreSymbol(String preSymbol) { + this.preSymbol = preSymbol; + } + +} diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/Paragraph.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/Paragraph.java index fa4b03b6b..ab6d02744 100644 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/Paragraph.java +++ b/fine-itext-old/src/com/fr/third/com/lowagie/text/Paragraph.java @@ -49,6 +49,8 @@ package com.fr.third.com.lowagie.text; +import java.util.HashMap; + /** * A Paragraph is a series of Chunks and/or Phrases. *

@@ -72,13 +74,13 @@ package com.fr.third.com.lowagie.text; public class Paragraph extends Phrase { - // constants - private static final long serialVersionUID = 7852314969733375514L; + // constants + private static final long serialVersionUID = 7852314969733375514L; // membervariables - /** The alignment of the text. */ - protected int alignment = Element.ALIGN_UNDEFINED; + /** The alignment of the text. */ + protected int alignment = ALIGN_UNDEFINED; /** The text leading that is multiplied by the biggest font size in the line. */ protected float multipliedLeading = 0; @@ -106,6 +108,22 @@ public class Paragraph extends Phrase { 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 /** @@ -195,15 +213,15 @@ public class Paragraph extends Phrase { public Paragraph(Phrase phrase) { super(phrase); if (phrase instanceof Paragraph) { - Paragraph p = (Paragraph)phrase; - setAlignment(p.alignment); - setLeading(phrase.getLeading(), p.multipliedLeading); - setIndentationLeft(p.getIndentationLeft()); - setIndentationRight(p.getIndentationRight()); - setFirstLineIndent(p.getFirstLineIndent()); - setSpacingAfter(p.spacingAfter()); - setSpacingBefore(p.spacingBefore()); - setExtraParagraphSpace(p.getExtraParagraphSpace()); + Paragraph p = (Paragraph)phrase; + setAlignment(p.alignment); + setLeading(phrase.getLeading(), p.multipliedLeading); + setIndentationLeft(p.getIndentationLeft()); + setIndentationRight(p.getIndentationRight()); + setFirstLineIndent(p.getFirstLineIndent()); + setSpacingAfter(p.spacingAfter()); + setSpacingBefore(p.spacingBefore()); + setExtraParagraphSpace(p.getExtraParagraphSpace()); } } @@ -215,7 +233,7 @@ public class Paragraph extends Phrase { * @return a type */ public int type() { - return Element.PARAGRAPH; + return PARAGRAPH; } // methods @@ -241,11 +259,11 @@ public class Paragraph extends Phrase { super.add(o); java.util.List chunks = getChunks(); if (!chunks.isEmpty()) { - Chunk tmp = ((Chunk) chunks.get(chunks.size() - 1)); - super.add(new Chunk("\n", tmp.getFont())); + Chunk tmp = ((Chunk) chunks.get(chunks.size() - 1)); + super.add(new Chunk("\n", tmp.getFont())); } else { - super.add(Chunk.NEWLINE); + super.add(Chunk.NEWLINE); } return true; } @@ -270,32 +288,32 @@ public class Paragraph extends Phrase { */ public void setAlignment(String alignment) { if (ElementTags.ALIGN_CENTER.equalsIgnoreCase(alignment)) { - this.alignment = Element.ALIGN_CENTER; + this.alignment = ALIGN_CENTER; return; } if (ElementTags.ALIGN_RIGHT.equalsIgnoreCase(alignment)) { - this.alignment = Element.ALIGN_RIGHT; + this.alignment = ALIGN_RIGHT; return; } if (ElementTags.ALIGN_JUSTIFIED.equalsIgnoreCase(alignment)) { - this.alignment = Element.ALIGN_JUSTIFIED; + this.alignment = ALIGN_JUSTIFIED; return; } if (ElementTags.ALIGN_JUSTIFIED_ALL.equalsIgnoreCase(alignment)) { - this.alignment = Element.ALIGN_JUSTIFIED_ALL; + this.alignment = ALIGN_JUSTIFIED_ALL; 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) { this.leading = fixedLeading; this.multipliedLeading = 0; } - + /** * Sets the variable leading. The resultant leading will be * multipliedLeading*maxFontSize where maxFontSize is the @@ -306,7 +324,7 @@ public class Paragraph extends Phrase { this.leading = 0; this.multipliedLeading = multipliedLeading; } - + /** * Sets the leading fixed and variable. The resultant leading will be * fixedLeading+multipliedLeading*maxFontSize where maxFontSize is the @@ -318,7 +336,7 @@ public class Paragraph extends Phrase { this.leading = fixedLeading; this.multipliedLeading = multipliedLeading; } - + /** * Sets the indentation of this paragraph on the left side. * @@ -327,7 +345,7 @@ public class Paragraph extends Phrase { public void setIndentationLeft(float indentation) { this.indentationLeft = indentation; } - + /** * Sets the indentation of this paragraph on the right side. * @@ -336,7 +354,7 @@ public class Paragraph extends Phrase { public void setIndentationRight(float indentation) { this.indentationRight = indentation; } - + /** * Setter for property firstLineIndent. * @param firstLineIndent New value of property firstLineIndent. @@ -344,7 +362,7 @@ public class Paragraph extends Phrase { public void setFirstLineIndent(float firstLineIndent) { this.firstLineIndent = firstLineIndent; } - + /** * Sets the spacing before this paragraph. * @@ -353,7 +371,7 @@ public class Paragraph extends Phrase { public void setSpacingBefore(float spacing) { this.spacingBefore = spacing; } - + /** * Sets the spacing after this paragraph. * @@ -362,7 +380,7 @@ public class Paragraph extends Phrase { public void setSpacingAfter(float spacing) { this.spacingAfter = spacing; } - + /** * 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) { this.keeptogether = keeptogether; } - + /** * 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 - /** + /** * Gets the alignment of this paragraph. * * @return alignment @@ -391,7 +409,7 @@ public class Paragraph extends Phrase { public int getAlignment() { return alignment; } - + /** * Gets the variable leading * @return the leading @@ -399,7 +417,7 @@ public class Paragraph extends Phrase { public float getMultipliedLeading() { return multipliedLeading; } - + /** * Gets the total leading. * 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) */ public float getTotalLeading() { - float m = font == null ? - Font.DEFAULTSIZE * multipliedLeading : font.getCalculatedLeading(multipliedLeading); - if (m > 0 && !hasLeading()) { - return m; - } - return getLeading() + m; + float m = font == null ? + Font.DEFAULTSIZE * multipliedLeading : font.getCalculatedLeading(multipliedLeading); + if (m > 0 && !hasLeading()) { + return m; + } + return getLeading() + m; } - /** + /** * Gets the indentation of this paragraph on the left side. * * @return the indentation @@ -426,15 +444,15 @@ public class Paragraph extends Phrase { return indentationLeft; } - /** - * Gets the indentation of this paragraph on the right side. - * - * @return the indentation - */ + /** + * Gets the indentation of this paragraph on the right side. + * + * @return the indentation + */ public float getIndentationRight() { return indentationRight; } - + /** * Getter for property firstLineIndent. * @return Value of property firstLineIndent. @@ -442,25 +460,25 @@ public class Paragraph extends Phrase { public float getFirstLineIndent() { return this.firstLineIndent; } - + /** * Gets the spacing before this paragraph. * @return the spacing * @since 2.1.5 */ public float getSpacingBefore() { - return spacingBefore; - } - + return spacingBefore; + } + /** * Gets the spacing after this paragraph. * @return the spacing * @since 2.1.5 */ public float getSpacingAfter() { - return spacingAfter; - } - + return spacingAfter; + } + /** * Getter for property extraParagraphSpace. * @return Value of property extraParagraphSpace. @@ -468,7 +486,7 @@ public class Paragraph extends Phrase { public float getExtraParagraphSpace() { return this.extraParagraphSpace; } - + /** * Setter for property extraParagraphSpace. * @param extraParagraphSpace New value of property extraParagraphSpace. @@ -476,9 +494,9 @@ public class Paragraph extends Phrase { public void setExtraParagraphSpace(float extraParagraphSpace) { this.extraParagraphSpace = extraParagraphSpace; } - + // scheduled for removal - + /** * Gets the spacing before this paragraph. * @@ -508,5 +526,5 @@ public class Paragraph extends Phrase { public String getBackground(){ return this.background; } - -} \ No newline at end of file + +} diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/factories/ElementFactory.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/factories/ElementFactory.java index 91b36e786..c5a0a444a 100755 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/factories/ElementFactory.java +++ b/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); if (value != null) { - chunk.setBackground(Markup.decodeColor(value)); + chunk.setBackground(value); } return chunk; } diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/CSS.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/html/CSS.java new file mode 100644 index 000000000..d2f2fec79 --- /dev/null +++ b/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"; + } + +} \ No newline at end of file diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/CSSUtils.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/html/CSSUtils.java new file mode 100644 index 000000000..8eac69ec9 --- /dev/null +++ b/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 backgroundPositions = new HashSet( + Arrays.asList(new String[] { CSS.Value.LEFT, CSS.Value.CENTER, CSS.Value.BOTTOM, CSS.Value.TOP, CSS.Value.RIGHT })); + + public static Map processBackground(final String background) { + Map rules = new HashMap(); + 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; + } +} diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/IndentAttribute.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/html/IndentAttribute.java new file mode 100644 index 000000000..5db28f14c --- /dev/null +++ b/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(){ + + } +} diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/Markup.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/html/Markup.java index 2b4011dae..394ffd8a0 100755 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/Markup.java +++ b/fine-itext-old/src/com/fr/third/com/lowagie/text/html/Markup.java @@ -44,7 +44,7 @@ * * Contributions by: * Lubos Strapko - * + * * If you didn't download this code from the following link, you should check if * you aren't using an obsolete version: * http://www.lowagie.com/iText/ @@ -54,7 +54,6 @@ package com.fr.third.com.lowagie.text.html; import java.awt.Color; import java.util.Properties; -import java.util.StringTokenizer; /** * A class that contains all the possible tagnames and their attributes. @@ -272,14 +271,14 @@ public class Markup { /** a CSS value for text decoration */ public static final String CSS_VALUE_UNDERLINE = "underline"; - /** a default value for font-size - * @since 2.1.3 - */ + /** a default value for font-size + * @since 2.1.3 + */ public static final float DEFAULT_FONT_SIZE = 12f; /** * Parses a length. - * + * * @param string * a length in the form of an optional + or -, followed by a * number and a unit. @@ -295,23 +294,23 @@ public class Markup { boolean ok = true; while (ok && pos < length) { switch (string.charAt(pos)) { - case '+': - case '-': - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '.': - pos++; - break; - default: - ok = false; + case '+': + case '-': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '.': + pos++; + break; + default: + ok = false; } } if (pos == 0) @@ -342,7 +341,7 @@ public class Markup { /** * New method contributed by: Lubos Strapko - * + * * @since 2.1.3 */ public static float parseLength(String string, float actualFontSize) { @@ -353,23 +352,23 @@ public class Markup { boolean ok = true; while (ok && pos < length) { switch (string.charAt(pos)) { - case '+': - case '-': - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '.': - pos++; - break; - default: - ok = false; + case '+': + case '-': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '.': + pos++; + break; + default: + ok = false; } } if (pos == 0) @@ -410,7 +409,7 @@ public class Markup { /** * Converts a Color into a HTML representation of this * Color. - * + * * @param s * the Color that has to be converted. * @return the HTML representation of this Color @@ -431,7 +430,7 @@ public class Markup { /** * This method parses a String with attributes and returns a Properties * object. - * + * * @param string * a String of this form: 'key1="value1"; key2="value2";... * keyN="valueN" ' @@ -441,32 +440,48 @@ public class Markup { Properties result = new Properties(); if (string == null) return result; - StringTokenizer keyValuePairs = new StringTokenizer(string, ";"); - StringTokenizer keyValuePair; String key; String value; - while (keyValuePairs.hasMoreTokens()) { - keyValuePair = new StringTokenizer(keyValuePairs.nextToken(), ":"); - if (keyValuePair.hasMoreTokens()) - key = keyValuePair.nextToken().trim(); - else - continue; - if (keyValuePair.hasMoreTokens()) - value = keyValuePair.nextToken().trim(); - else - continue; - if (value.startsWith("\"")) - value = value.substring(1); - if (value.endsWith("\"")) - value = value.substring(0, value.length() - 1); - result.setProperty(key.toLowerCase(), value); + //鎹㈢鏂瑰紡瑙f瀽锛宻tyle涓璪ackground閲岄潰涔熸湁鍙兘浼氭湁;绗﹀彿 + String[] styles = string.split(";"); + for (String s : styles) { + String[] part = s.split(":",2); + if (part.length == 2) { + key = stripDoubleSpacesAndTrim(part[0]).toLowerCase(); + value = stripDoubleSpacesAndTrim(part[1]); + if (value.startsWith("\"") || value.startsWith("\'") ) + value = value.substring(1); + if (value.endsWith("\"") || value.endsWith("\'")) + value = value.substring(0, value.length() - 1); + result.setProperty(key.toLowerCase(), value); + } } 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. - * + * * @param string * the original String * @param startComment @@ -476,7 +491,7 @@ public class Markup { * @return the String stripped of its comment section */ public static String removeComment(String string, String startComment, - String endComment) { + String endComment) { StringBuffer result = new StringBuffer(); int pos = 0; int end = endComment.length(); diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/ParseIndentAttrUtils.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/html/ParseIndentAttrUtils.java new file mode 100644 index 000000000..34477b038 --- /dev/null +++ b/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;"); + } +} \ No newline at end of file diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/WebColors.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/html/WebColors.java index 84d9401c4..5c91ba8cb 100755 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/WebColors.java +++ b/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) throws IllegalArgumentException { - int[] c = { 0, 0, 0, 0 }; + int[] c = { 0, 0, 0, 255 }; if (name.startsWith("#")) { if (name.length() == 4) { c[0] = Integer.parseInt(name.substring(1, 2), 16) * 16; @@ -258,6 +258,6 @@ public class WebColors extends HashMap { throw new IllegalArgumentException("Color '" + name + "' not found."); 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); } } \ No newline at end of file diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/ChainedProperties.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/ChainedProperties.java index 5321a6845..5aa81eb69 100755 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/ChainedProperties.java +++ b/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/ChainedProperties.java @@ -75,6 +75,13 @@ public class ChainedProperties { return null; } + public String getLastChainProperty(String key){ + Object obj[] = (Object[]) chain.get(chain.size()-1); + HashMap prop = (HashMap) obj[1]; + return (String) prop.get(key); + } + + public boolean hasProperty(String key) { for (int k = chain.size() - 1; k >= 0; --k) { Object obj[] = (Object[]) chain.get(k); @@ -85,6 +92,66 @@ public class ChainedProperties { 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) { // adjust the font size String value = (String) prop.get(ElementTags.SIZE); diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/FactoryProperties.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/FactoryProperties.java old mode 100755 new mode 100644 index 00f7dac8c..0fc0a74b9 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/FactoryProperties.java +++ b/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; -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.Element; 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.ListItem; 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.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.HyphenationEvent; +import java.awt.Color; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Properties; +import java.util.StringTokenizer; + /** * * @author psoares @@ -85,16 +86,24 @@ public class FactoryProperties { public Chunk createChunk(String text, ChainedProperties props) { Font font = getFont(props); float size = font.getSize(); - size /= 2; + size /= 3; Chunk ck = new Chunk(text, font); if (props.hasProperty("sub")) ck.setTextRise(-size); else if (props.hasProperty("sup")) ck.setTextRise(size); 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; } - private static void setParagraphLeading(Paragraph p, String leading) { if (leading == null) { p.setLeading(0, 1.5f); @@ -126,6 +135,34 @@ public class FactoryProperties { else if (value.equalsIgnoreCase("justify")) 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)); setParagraphLeading(p, props.getProperty("leading")); value = props.getProperty("before"); @@ -191,10 +228,7 @@ public class FactoryProperties { if (value != null) size = Float.parseFloat(value); Color color = Markup.decodeColor(props.getProperty("color")); - String encoding = props.getProperty("encoding"); - if (encoding == null) - encoding = BaseFont.WINANSI; - return fontImp.getFont(face, encoding, true, size, style, color); + return new Font(face, size, style, color); } /** @@ -309,13 +343,22 @@ public class FactoryProperties { else { 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(); h.put("align", ss); } } } + /** * New method contributed by Lubos Strapko * @param h @@ -380,12 +423,17 @@ public class FactoryProperties { return; } h.put("leading", v + ",0"); + h.put("line-height", ss); } else if (key.equals(Markup.CSS_KEY_TEXTALIGN)) { String ss = prop.getProperty(key).trim().toLowerCase(); 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(); - h.put("indent", Float.toString(Markup.parseLength(ss))); + h.put("background", ss); + } + else{ + String ss = prop.getProperty(key).trim(); + h.put(key, ss); } } } diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/HTMLWorker.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/HTMLWorker.java old mode 100755 new mode 100644 index 32cecee08..e4048ae18 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/HTMLWorker.java +++ b/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; -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.DocListener; 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.HeaderFooter; 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.Paragraph; import com.fr.third.com.lowagie.text.Phrase; import com.fr.third.com.lowagie.text.Rectangle; 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.draw.LineSeparator; import com.fr.third.com.lowagie.text.xml.simpleparser.SimpleXMLDocHandler; 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 { @@ -176,11 +183,16 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { cprops.addToChain("body", h); } + public void startElement(String tag, HashMap h) { if (!tagsSupported.containsKey(tag)) return; try { 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); if (follow != null) { HashMap prop = new HashMap(); @@ -226,7 +238,7 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { int hrAlign = Element.ALIGN_CENTER; if (align != null) { if (align.equalsIgnoreCase("left")) - hrAlign = Element.ALIGN_LEFT; + hrAlign = Element.ALIGN_LEFT; if (align.equalsIgnoreCase("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 (!src.startsWith("http")) { String path = cprops.getProperty("image_path"); @@ -294,6 +314,10 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { } img = Image.getInstance(src); } + if(img == null){ + return; + } + img.setSrcString(src); String align = (String) h.get("align"); String width = (String) h.get("width"); String height = (String) h.get("height"); @@ -342,12 +366,22 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { document.add(img); cprops.removeChain(tag); } 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); if (currentParagraph == null) { currentParagraph = FactoryProperties .createParagraph(cprops); } - currentParagraph.add(new Chunk(img, 0, 0)); + + currentParagraph.add(ck); } return; } @@ -366,7 +400,7 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { endElement(HtmlTags.LISTITEM); skipText = true; 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{ list.setIndentationLeft(new Float(cprops.getProperty("indent")).floatValue()); }catch (Exception e) { @@ -381,7 +415,7 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { endElement(HtmlTags.LISTITEM); skipText = true; 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{ list.setIndentationLeft(new Float(cprops.getProperty("indent")).floatValue()); }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) { if (!tagsSupported.containsKey(tag)) return; @@ -510,7 +568,7 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { if (stack.empty()) return; Object obj = stack.pop(); - if (!(obj instanceof com.fr.third.com.lowagie.text.List)) { + if (!(obj instanceof List)) { stack.push(obj); return; } @@ -536,12 +594,12 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { return; } Object list = stack.pop(); - if (!(list instanceof com.fr.third.com.lowagie.text.List)) { + if (!(list instanceof List)) { stack.push(list); return; } ListItem item = (ListItem) obj; - ((com.fr.third.com.lowagie.text.List) list).add(item); + ((List) list).add(item); ArrayList cks = item.getChunks(); if (!cks.isEmpty()) item.getListSymbol() @@ -588,6 +646,8 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { if (pendingTD) endElement("td"); pendingTR = false; + String rowHeightPx = cprops.getLastChainProperty("height"); + cprops.removeChain("tr"); ArrayList cells = new ArrayList(); IncTable table = null; @@ -601,8 +661,13 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { break; } } + float rowHeight = 0.0f; + if(rowHeightPx!=null){ + rowHeight = CSSUtils.parseFloat(rowHeightPx); + } table.addCols(cells); - table.endRow(); + table.endRow(rowHeight); + stack.push(table); skipText = true; return; @@ -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 */ public boolean setMarginMirroringTopBottom(boolean marginMirroring) { diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/HtmlConstants.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/HtmlConstants.java new file mode 100644 index 000000000..3edc3ee35 --- /dev/null +++ b/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 BLOCK_ELEMENTS = new ArrayList(); + //琛屽唴鍏冪礌闆嗗悎 + public static final List INLINE_ELEMENTS = new ArrayList(); + //鏀寔瑙f瀽鐨勫睘鎬 + public static final List PADDING = new ArrayList(); + public static final List MARGIN = new ArrayList(); + 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); + } +} diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/IncCell.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/IncCell.java index 6d64d8b6d..712dcf1e3 100755 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/IncCell.java +++ b/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; 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.ElementListener; -import com.fr.third.com.lowagie.text.Phrase; 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.pdf.PdfPCell; +import com.fr.third.com.lowagie.text.Phrase; + /** * * @author psoares */ public class IncCell implements TextElementArray { - + private ArrayList chunks = new ArrayList(); private PdfPCell cell; - + /** Creates a new instance of IncCell */ public IncCell(String tag, ChainedProperties props) { cell = new PdfPCell((Phrase)null); @@ -94,52 +98,90 @@ public class IncCell implements TextElementArray { value = props.getProperty("border"); float border = 0; if (value != null) - border = Float.parseFloat(value); + border = CSSUtils.parseFloat(value); cell.setBorderWidth(border); value = props.getProperty("cellpadding"); if (value != null) - cell.setPadding(Float.parseFloat(value)); + cell.setPadding(CSSUtils.parseFloat(value)); cell.setUseDescender(true); value = props.getProperty("bgcolor"); cell.setBackgroundColor(Markup.decodeColor(value)); + //瑙f瀽td涓婂0鏄庣殑width + value = props.getLastChainProperty("width"); + if(value != null){ + cell.setStyleWidth(CSSUtils.parseFloat(value)); + } + //瑙f瀽td涓婂0鏄庣殑height + value = props.getLastChainProperty("height"); + if(value != null){ + cell.setStyleHeight(CSSUtils.parseFloat(value)); + } + //瑙f瀽background鐩稿叧灞炴у苟淇濆瓨鍒癱ell瀵硅薄 + Map backgroundRules = new HashMap(); + value = props.getLastChainProperty("background-size"); + if(value!=null){ + backgroundRules.put("background-size", value); + } + value = props.getLastChainProperty("background"); + if(value!=null){ + Map 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) { if (!(o instanceof Element)) return false; cell.addElement((Element)o); return true; } - + public ArrayList getChunks() { return chunks; } - + public boolean process(ElementListener listener) { return true; } - + public int type() { return Element.RECTANGLE; } - + public PdfPCell getCell() { return cell; - } - - /** - * @see com.fr.third.com.lowagie.text.Element#isContent() - * @since iText 2.0.8 - */ - public boolean isContent() { - return true; - } + } + + /** + * @see Element#isContent() + * @since iText 2.0.8 + */ + public boolean isContent() { + return true; + } - /** - * @see com.fr.third.com.lowagie.text.Element#isNestable() - * @since iText 2.0.8 - */ - public boolean isNestable() { - return true; - } + /** + * @see Element#isNestable() + * @since iText 2.0.8 + */ + public boolean isNestable() { + return true; + } } \ No newline at end of file diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/IncTable.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/IncTable.java index 4e5b6b131..39c6c6009 100755 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/html/simpleparser/IncTable.java +++ b/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.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.PdfPCell; +import com.fr.third.com.lowagie.text.pdf.TableProperties; /** * @@ -62,62 +66,126 @@ public class IncTable { private HashMap props = new HashMap(); private ArrayList rows = new ArrayList(); private ArrayList cols; + + private ArrayList rowHeights = new ArrayList(); /** Creates a new instance of IncTable */ public IncTable(HashMap props) { this.props.putAll(props); } - + public void addCol(PdfPCell cell) { if (cols == null) cols = new ArrayList(); cols.add(cell); } - + public void addCols(ArrayList ncols) { if (cols == null) cols = new ArrayList(ncols); else cols.addAll(ncols); } - - public void endRow() { + + public void endRow(float rowHeight) { + rowHeights.add(rowHeight); if (cols != null) { Collections.reverse(cols); rows.add(cols); cols = null; } } - + public ArrayList getRows() { return rows; } - + public PdfPTable buildTable() { if (rows.isEmpty()) return new PdfPTable(1); int ncol = 0; ArrayList c0 = (ArrayList)rows.get(0); + ArrayList colWidths = new ArrayList(); for (int k = 0; k < c0.size(); ++k) { - ncol += ((PdfPCell)c0.get(k)).getColspan(); + PdfPCell pCell = ((PdfPCell)c0.get(k)); + int cellCols = pCell.getColspan(); + ncol += cellCols; + if(cellCols > 1){ + for(int a = 0; a < cellCols ; a++){ + colWidths.add(pCell.getStyleWidth()/cellCols); + } + }else { + colWidths.add(pCell.getStyleWidth()); + } } + PdfPTable table = new PdfPTable(ncol); - String width = (String)props.get("width"); - if (width == null) - table.setWidthPercentage(100); - else { - if (width.endsWith("%")) - table.setWidthPercentage(Float.parseFloat(width.substring(0, width.length() - 1))); + try { + TableProperties tableProperties = parseTableProperties(); + table.setTableProperties(tableProperties); + String width = (String)props.get("width"); + if (width == null) + table.setWidthPercentage(100); else { - table.setTotalWidth(Float.parseFloat(width)); - table.setLockedWidth(true); + if (width.endsWith("%")) + table.setWidthPercentage(CSSUtils.parseFloat(width)); + else { + //瑙f瀽鍗曞厓鏍煎搴 + float totalWidth = CSSUtils.parseFloat(width); + float[] floats = new float[colWidths.size()]; + for (int a = 0; a < colWidths.size(); a++){ + floats[a] = colWidths.get(a); + } + //瑙f瀽px鏁板 + table.setTotalWidth(totalWidth); + try { + table.setWidths(floats); + }catch (Exception e){ + e.printStackTrace(); + } + table.setLockedWidth(true); + } } - } - for (int row = 0; row < rows.size(); ++row) { - ArrayList col = (ArrayList)rows.get(row); - for (int k = 0; k < col.size(); ++k) { - table.addCell((PdfPCell)col.get(k)); + for (int row = 0; row < rows.size(); ++row) { + ArrayList col = (ArrayList)rows.get(row); + for (int k = 0; k < col.size(); ++k) { + table.addCell((PdfPCell)col.get(k)); + } + } + //璋冩暣琛岄珮 + for(int a = 0; a < rowHeights.size(); a++){ + table.getRow(a).setStyleHeight(rowHeights.get(a)); } + + }catch (Exception e){ + e.printStackTrace(); } return table; } + + public TableProperties parseTableProperties(){ + TableProperties tableProperties = new TableProperties(); + BorderStyle borderStyle = new BorderStyle(); + tableProperties.setBorderStyle(borderStyle); + String value = (String)props.get("border"); + if(value != null){ + borderStyle.setBorderWidth(CSSUtils.parseFloat(value)); + } + value = (String)props.get("border-color"); + if(value != null){ + borderStyle.setBorderColor(Markup.decodeColor(value)); + } + value = (String)props.get("border-collapse"); + if(value != null){ + tableProperties.setCollapse(value.equals("collapse")); + } + value = (String)props.get("cellspacing"); + if(value != null){ + tableProperties.setCellspacing(CSSUtils.parseFloat(value)); + } + value = (String)props.get("cellpadding"); + if(value != null){ + tableProperties.setCellpadding(CSSUtils.parseFloat(value)); + } + return tableProperties; + } } diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/BorderStyle.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/BorderStyle.java new file mode 100644 index 000000000..015596bf8 --- /dev/null +++ b/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; + + } + +} diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfPCell.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfPCell.java index 32e9f1181..f2c2365b1 100755 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfPCell.java +++ b/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfPCell.java @@ -50,48 +50,80 @@ package com.fr.third.com.lowagie.text.pdf; import java.util.List; +import java.util.Map; +import com.fr.Container; import com.fr.third.com.lowagie.text.Chunk; import com.fr.third.com.lowagie.text.DocumentException; 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.Phrase; import com.fr.third.com.lowagie.text.Rectangle; import com.fr.third.com.lowagie.text.pdf.events.PdfPCellEventForwarder; +import com.fr.third.com.lowagie.text.Phrase; /** * A cell in a PdfPTable. */ -public class PdfPCell extends Rectangle{ - +public class PdfPCell extends Rectangle { + + private float styleWidth = 0.0f; + private float styleHeight = 0.0f; + + public float getStyleHeight() { + return styleHeight; + } + + public void setStyleHeight(float styleHeight) { + this.styleHeight = styleHeight; + } + + public float getStyleWidth() { + return styleWidth; + } + + public Map background ; + + public Map getBackground() { + return background; + } + + public void setBackground(Map background) { + this.background = background; + } + + public void setStyleWidth(float styleWidth) { + this.styleWidth = styleWidth; + } + + private ColumnText column = new ColumnText(null); - + /** Vertical alignment of the cell. */ private int verticalAlignment = Element.ALIGN_TOP; - + /** Left padding of the cell. */ private float paddingLeft = 2; - + /** Right padding of the cell. */ private float paddingRight = 2; - + /** Top padding of the cell. */ private float paddingTop = 2; - + /** Bottom padding of the cell. */ private float paddingBottom = 2; - + /** Fixed height of the cell. */ private float fixedHeight = 0; - + /** Minimum height of the cell. */ private float minimumHeight; - + /** Holds value of property noWrap. */ private boolean noWrap = false; - + /** Holds value of property table. */ private PdfPTable table; @@ -103,10 +135,10 @@ public class PdfPCell extends Rectangle{ * @since 2.1.6 */ private int rowspan = 1; - + /** Holds value of property image. */ private Image image; - + /** Holds value of property cellEvent. */ private PdfPCellEvent cellEvent; @@ -139,7 +171,7 @@ public class PdfPCell extends Rectangle{ /** * Constructs a PdfPCell with a Phrase. * The default padding is 2. - * + * * @param phrase the text */ public PdfPCell(Phrase phrase) { @@ -149,21 +181,21 @@ public class PdfPCell extends Rectangle{ column.addText(this.phrase = phrase); column.setLeading(0, 1); } - + /** * Constructs a PdfPCell with an Image. * The default padding is 0. - * + * * @param image the Image */ public PdfPCell(Image image) { this(image, false); } - + /** * Constructs a PdfPCell with an Image. * The default padding is 0.25 for a border width of 0.5. - * + * * @param image the Image * @param fit true to fit the image to the cell */ @@ -182,22 +214,22 @@ public class PdfPCell extends Rectangle{ setPadding(0); } } - + /** * Constructs a PdfPCell with a PdfPtable. * This constructor allows nested tables. * The default padding is 0. - * + * * @param table The PdfPTable */ public PdfPCell(PdfPTable table) { this(table, null); } - + /** * Constructs a PdfPCell with a PdfPtable. * This constructor allows nested tables. - * + * * @param table The PdfPTable * @param style The style to apply to the cell (you could use getDefaultCell()) * @since 2.1.0 @@ -212,26 +244,26 @@ public class PdfPCell extends Rectangle{ table.setExtendLastRow(true); column.addElement(table); if (style != null) { - cloneNonPositionParameters(style); - verticalAlignment = style.verticalAlignment; - paddingLeft = style.paddingLeft; - paddingRight = style.paddingRight; - paddingTop = style.paddingTop; - paddingBottom = style.paddingBottom; - colspan = style.colspan; - rowspan = style.rowspan; - cellEvent = style.cellEvent; - useDescender = style.useDescender; - useBorderPadding = style.useBorderPadding; - rotation = style.rotation; + cloneNonPositionParameters(style); + verticalAlignment = style.verticalAlignment; + paddingLeft = style.paddingLeft; + paddingRight = style.paddingRight; + paddingTop = style.paddingTop; + paddingBottom = style.paddingBottom; + colspan = style.colspan; + rowspan = style.rowspan; + cellEvent = style.cellEvent; + useDescender = style.useDescender; + useBorderPadding = style.useBorderPadding; + rotation = style.rotation; } else - setPadding(0); + setPadding(0); } - + /** * Constructs a deep copy of a PdfPCell. - * + * * @param cell the PdfPCell to duplicate */ public PdfPCell(PdfPCell cell) { @@ -256,11 +288,14 @@ public class PdfPCell extends Rectangle{ column = ColumnText.duplicate(cell.column); useBorderPadding = cell.useBorderPadding; rotation = cell.rotation; + background = cell.background; + styleWidth = cell.styleWidth; + styleHeight = cell.styleHeight; } - + /** * Adds an iText element to the cell. - * + * * @param element */ public void addElement(Element element) { @@ -270,19 +305,19 @@ public class PdfPCell extends Rectangle{ } column.addElement(element); } - + /** * Gets the Phrase from this cell. - * + * * @return the Phrase */ public Phrase getPhrase() { return phrase; } - + /** * Sets the Phrase for this cell. - * + * * @param phrase the Phrase */ public void setPhrase(Phrase phrase) { @@ -290,39 +325,39 @@ public class PdfPCell extends Rectangle{ image = null; column.setText(this.phrase = phrase); } - + /** * Gets the horizontal alignment for the cell. - * + * * @return the horizontal alignment for the cell */ public int getHorizontalAlignment() { return column.getAlignment(); } - + /** * Sets the horizontal alignment for the cell. It could be * Element.ALIGN_CENTER for example. - * + * * @param horizontalAlignment The horizontal alignment */ public void setHorizontalAlignment(int horizontalAlignment) { column.setAlignment(horizontalAlignment); } - + /** * Gets the vertical alignment for the cell. - * + * * @return the vertical alignment for the cell */ public int getVerticalAlignment() { return verticalAlignment; } - + /** * Sets the vertical alignment for the cell. It could be * Element.ALIGN_MIDDLE for example. - * + * * @param verticalAlignment The vertical alignment */ public void setVerticalAlignment(int verticalAlignment) { @@ -330,22 +365,22 @@ public class PdfPCell extends Rectangle{ table.setExtendLastRow(verticalAlignment == Element.ALIGN_TOP); this.verticalAlignment = verticalAlignment; } - + /** * Gets the effective left padding. * This will include the left border width if * {@link #isUseBorderPadding()} is true. - * + * * @return effective value of property paddingLeft. */ public float getEffectivePaddingLeft() { - if (isUseBorderPadding()) { - float border = getBorderWidthLeft() / (isUseVariableBorders() ? 1f : 2f); - return paddingLeft + border; - } - return paddingLeft; + if (isUseBorderPadding()) { + float border = getBorderWidthLeft() / (isUseVariableBorders() ? 1f : 2f); + return paddingLeft + border; + } + return paddingLeft; } - + /** * @return Value of property paddingLeft. */ @@ -355,30 +390,30 @@ public class PdfPCell extends Rectangle{ /** * Setter for property paddingLeft. - * + * * @param paddingLeft New value of property paddingLeft. */ public void setPaddingLeft(float paddingLeft) { this.paddingLeft = paddingLeft; } - + /** * Gets the effective right padding. This will include * the right border width if {@link #isUseBorderPadding()} is true. - * + * * @return effective value of property paddingRight. */ public float getEffectivePaddingRight() { - if (isUseBorderPadding()) { - float border = getBorderWidthRight() / (isUseVariableBorders() ? 1f : 2f); - return paddingRight + border; - } - return paddingRight; + if (isUseBorderPadding()) { + float border = getBorderWidthRight() / (isUseVariableBorders() ? 1f : 2f); + return paddingRight + border; + } + return paddingRight; } - + /** * Getter for property paddingRight. - * + * * @return Value of property paddingRight. */ public float getPaddingRight() { @@ -387,30 +422,30 @@ public class PdfPCell extends Rectangle{ /** * Setter for property paddingRight. - * + * * @param paddingRight New value of property paddingRight. */ public void setPaddingRight(float paddingRight) { this.paddingRight = paddingRight; } - - /** + + /** * Gets the effective top padding. This will include * the top border width if {@link #isUseBorderPadding()} is true. - * + * * @return effective value of property paddingTop. */ public float getEffectivePaddingTop() { - if (isUseBorderPadding()) { - float border = getBorderWidthTop()/(isUseVariableBorders()?1f:2f); - return paddingTop + border; - } + if (isUseBorderPadding()) { + float border = getBorderWidthTop()/(isUseVariableBorders()?1f:2f); + return paddingTop + border; + } return paddingTop; } - + /** * Getter for property paddingTop. - * + * * @return Value of property paddingTop. */ public float getPaddingTop() { @@ -419,31 +454,31 @@ public class PdfPCell extends Rectangle{ /** * Setter for property paddingTop. - * + * * @param paddingTop New value of property paddingTop. */ public void setPaddingTop(float paddingTop) { this.paddingTop = paddingTop; } - + /** * Gets the effective bottom padding. * This will include the bottom border width if * {@link #isUseBorderPadding()} is true. - * + * * @return effective value of property paddingBottom. */ public float getEffectivePaddingBottom() { - if (isUseBorderPadding()) { - float border = getBorderWidthBottom()/(isUseVariableBorders()?1f:2f); - return paddingBottom + border; - } + if (isUseBorderPadding()) { + float border = getBorderWidthBottom()/(isUseVariableBorders()?1f:2f); + return paddingBottom + border; + } return paddingBottom; } - + /** * Getter for property paddingBottom. - * + * * @return Value of property paddingBottom. */ public float getPaddingBottom() { @@ -452,16 +487,16 @@ public class PdfPCell extends Rectangle{ /** * Setter for property paddingBottom. - * + * * @param paddingBottom New value of property paddingBottom. */ public void setPaddingBottom(float paddingBottom) { this.paddingBottom = paddingBottom; } - + /** * Sets the padding of the contents in the cell (space between content and border). - * + * * @param padding */ public void setPadding(float padding) { @@ -473,7 +508,7 @@ public class PdfPCell extends Rectangle{ /** * If true, then effective padding will include border widths - * + * * @return true if effective padding includes border widths */ public boolean isUseBorderPadding() { @@ -482,7 +517,7 @@ public class PdfPCell extends Rectangle{ /** * Adjusts effective padding to include border widths. - * + * * @param use adjust effective padding if true */ public void setUseBorderPadding(boolean use) { @@ -490,86 +525,86 @@ public class PdfPCell extends Rectangle{ } /** - * Sets the leading fixed and variable. + * Sets the leading fixed and variable. * The resultant leading will be: * fixedLeading+multipliedLeading*maxFontSize * where maxFontSize is the size of the biggest font in the line. - * + * * @param fixedLeading the fixed leading * @param multipliedLeading the variable leading */ public void setLeading(float fixedLeading, float multipliedLeading) { column.setLeading(fixedLeading, multipliedLeading); } - + /** * Gets the fixed leading. - * + * * @return the leading */ public float getLeading() { return column.getLeading(); } - + /** * Gets the variable leading. - * + * * @return the leading */ public float getMultipliedLeading() { return column.getMultipliedLeading(); } - + /** * Sets the first paragraph line indent. - * + * * @param indent the indent */ public void setIndent(float indent) { column.setIndent(indent); } - + /** * Gets the first paragraph line indent. - * + * * @return the indent */ public float getIndent() { return column.getIndent(); } - + /** * Gets the extra space between paragraphs. - * + * * @return the extra space between paragraphs */ public float getExtraParagraphSpace() { return column.getExtraParagraphSpace(); } - + /** * Sets the extra space between paragraphs. - * + * * @param extraParagraphSpace the extra space between paragraphs */ public void setExtraParagraphSpace(float extraParagraphSpace) { column.setExtraParagraphSpace(extraParagraphSpace); } - + /** * Set a fixed height for the cell. * This will automatically unset minimumHeight, if set. - * + * * @param fixedHeight New value of property fixedHeight. */ public void setFixedHeight(float fixedHeight) { this.fixedHeight = fixedHeight; minimumHeight = 0; } - + /** * Get the fixed height of the cell. - * + * * @return Value of property fixedHeight. */ public float getFixedHeight() { @@ -578,25 +613,25 @@ public class PdfPCell extends Rectangle{ /** * Tells you whether the cell has a fixed height. - * + * * @return true is a fixed height was set. * @since 2.1.5 */ public boolean hasFixedHeight() { - return getFixedHeight() > 0; + return getFixedHeight() > 0; } - + /** * Set a minimum height for the cell. * This will automatically unset fixedHeight, if set. - * + * * @param minimumHeight New value of property minimumHeight. */ public void setMinimumHeight(float minimumHeight) { this.minimumHeight = minimumHeight; fixedHeight = 0; } - + /** * Get the minimum height of the cell. * @@ -608,42 +643,42 @@ public class PdfPCell extends Rectangle{ /** * Tells you whether the cell has a minimum height. - * + * * @return true if a minimum height was set. * @since 2.1.5 */ public boolean hasMinimumHeight() { - return getMinimumHeight() > 0; + return getMinimumHeight() > 0; } - + /** * Getter for property noWrap. - * + * * @return Value of property noWrap. */ public boolean isNoWrap() { return noWrap; } - + /** * Setter for property noWrap. - * + * * @param noWrap New value of property noWrap. */ public void setNoWrap(boolean noWrap) { this.noWrap = noWrap; } - + /** * Getter for property table. - * + * * @return Value of property table. * @since 2.x */ public PdfPTable getTable() { return table; } - + void setTable(PdfPTable table) { this.table = table; column.setText(null); @@ -657,35 +692,35 @@ public class PdfPCell extends Rectangle{ /** * Getter for property colspan. - * + * * @return Value of property colspan. */ public int getColspan() { return colspan; } - + /** * Setter for property colspan. - * + * * @param colspan New value of property colspan. */ public void setColspan(int colspan) { this.colspan = colspan; } - + /** * Getter for property rowspan. - * + * * @return Value of property rowspan. * @since 2.1.6 */ public int getRowspan() { return rowspan; } - + /** * Setter for property rowspan. - * + * * @param rowspan New value of property rowspan. * @since 2.1.6 */ @@ -695,62 +730,62 @@ public class PdfPCell extends Rectangle{ /** * Sets the following paragraph lines indent. - * + * * @param indent the indent */ public void setFollowingIndent(float indent) { column.setFollowingIndent(indent); } - + /** * Gets the following paragraph lines indent. - * + * * @return the indent */ public float getFollowingIndent() { return column.getFollowingIndent(); } - + /** * Sets the right paragraph lines indent. - * + * * @param indent the indent */ public void setRightIndent(float indent) { column.setRightIndent(indent); } - + /** * Gets the right paragraph lines indent. - * + * * @return the indent */ public float getRightIndent() { return column.getRightIndent(); } - + /** * Gets the space/character extra spacing ratio for fully justified text. - * + * * @return the space/character extra spacing ratio */ public float getSpaceCharRatio() { return column.getSpaceCharRatio(); } - + /** Sets the ratio between the extra word spacing and the * extra character spacing when the text is fully justified. * Extra word spacing will grow spaceCharRatio times more * than extra character spacing. * If the ratio is PdfWriter.NO_SPACE_CHAR_RATIO then the * extra character spacing will be zero. - * + * * @param spaceCharRatio the ratio between the extra word spacing and the extra character spacing */ public void setSpaceCharRatio(float spaceCharRatio) { column.setSpaceCharRatio(spaceCharRatio); } - + /** * Sets the run direction of the text content in the cell. * May be either of: @@ -761,10 +796,10 @@ public class PdfPCell extends Rectangle{ public void setRunDirection(int runDirection) { column.setRunDirection(runDirection); } - + /** * Gets the run direction of the text content in the cell - * + * * @return One of the following values: * PdfWriter.RUN_DIRECTION_DEFAULT, PdfWriter.RUN_DIRECTION_NO_BIDI, * PdfWriter.RUN_DIRECTION_LTR or PdfWriter.RUN_DIRECTION_RTL. @@ -772,19 +807,19 @@ public class PdfPCell extends Rectangle{ public int getRunDirection() { return column.getRunDirection(); } - + /** * Getter for property image. - * + * * @return Value of property image. */ public Image getImage() { return image; } - + /** * Setter for property image. - * + * * @param image New value of property image. */ public void setImage(Image image) { @@ -792,58 +827,58 @@ public class PdfPCell extends Rectangle{ table = null; this.image = image; } - + /** * Gets the cell event for this cell. - * + * * @return the cell event */ public PdfPCellEvent getCellEvent() { return cellEvent; } - + /** * Sets the cell event for this cell. - * + * * @param cellEvent the cell event */ public void setCellEvent(PdfPCellEvent cellEvent) { - if (cellEvent == null) - this.cellEvent = null; - else if (this.cellEvent == null) - this.cellEvent = cellEvent; - else if (this.cellEvent instanceof PdfPCellEventForwarder) - ((PdfPCellEventForwarder)this.cellEvent).addCellEvent(cellEvent); - else { - PdfPCellEventForwarder forward = new PdfPCellEventForwarder(); - forward.addCellEvent(this.cellEvent); - forward.addCellEvent(cellEvent); - this.cellEvent = forward; - } - } - + if (cellEvent == null) + this.cellEvent = null; + else if (this.cellEvent == null) + this.cellEvent = cellEvent; + else if (this.cellEvent instanceof PdfPCellEventForwarder) + ((PdfPCellEventForwarder)this.cellEvent).addCellEvent(cellEvent); + else { + PdfPCellEventForwarder forward = new PdfPCellEventForwarder(); + forward.addCellEvent(this.cellEvent); + forward.addCellEvent(cellEvent); + this.cellEvent = forward; + } + } + /** * Gets the arabic shaping options. - * + * * @return the arabic shaping options */ public int getArabicOptions() { return column.getArabicOptions(); } - - /** + + /** * Sets the arabic shaping options. * The option can be AR_NOVOWEL, AR_COMPOSEDTASHKEEL and AR_LIG. - * + * * @param arabicOptions the arabic shaping options */ public void setArabicOptions(int arabicOptions) { column.setArabicOptions(arabicOptions); } - + /** * Gets state of first line height based on max ascender - * + * * @return true if an ascender is to be used. */ public boolean isUseAscender() { @@ -862,7 +897,7 @@ public class PdfPCell extends Rectangle{ /** * Getter for property useDescender. - * + * * @return Value of property useDescender. */ public boolean isUseDescender() { @@ -871,7 +906,7 @@ public class PdfPCell extends Rectangle{ /** * Setter for property useDescender. - * + * * @param useDescender New value of property useDescender. */ public void setUseDescender(boolean useDescender) { @@ -880,13 +915,13 @@ public class PdfPCell extends Rectangle{ /** * Gets the ColumnText with the content of the cell. - * + * * @return a columntext object */ public ColumnText getColumn() { return column; } - + /** * Returns the list of composite elements of the column. * @@ -894,9 +929,9 @@ public class PdfPCell extends Rectangle{ * @since 2.1.1 */ public List getCompositeElements() { - return getColumn().compositeElements; + return getColumn().compositeElements; } - + /** * Sets the columntext in the cell. * @@ -916,7 +951,7 @@ public class PdfPCell extends Rectangle{ } /** - * Sets the rotation of the cell. + * Sets the rotation of the cell. * Possible values are 0, 90, 180 and 270. * * @param rotation the rotation of the cell @@ -929,7 +964,7 @@ public class PdfPCell extends Rectangle{ throw new IllegalArgumentException("Rotation must be a multiple of 90."); this.rotation = rotation; } - + /** * Consumes part of the content of the cell. * @param height the hight of the part that has to be consumed @@ -943,71 +978,81 @@ public class PdfPCell extends Rectangle{ column.setSimpleColumn(leftLimit, bry + 0.001f, rightLimit, 0); } else { - column.setSimpleColumn(0, leftLimit, bry + 0.001f, rightLimit); + column.setSimpleColumn(0, leftLimit, bry + 0.001f, rightLimit); } try { - column.go(true); - } catch (DocumentException e) { - // do nothing - } - } - - /** - * Returns the height of the cell. - * @return the height of the cell - * @since 3.0.0 - */ - public float getMaxHeight() { - boolean pivoted = (getRotation() == 90 || getRotation() == 270); - Image img = getImage(); - if (img != null) { - img.scalePercent(100); - float refWidth = pivoted ? img.getScaledHeight() : img.getScaledWidth(); - float scale = (getRight() - getEffectivePaddingRight() + column.go(true); + } catch (DocumentException e) { + // do nothing + } + } + + /** + * Returns the height of the cell. + * @return the height of the cell + * @since 3.0.0 + */ + public float getMaxHeight() { + boolean pivoted = (getRotation() == 90 || getRotation() == 270); + Image img = getImage(); + if (img != null) { + img.scalePercent(100); + float refWidth = pivoted ? img.getScaledHeight() : img.getScaledWidth(); + float scale = (getRight() - getEffectivePaddingRight() - getEffectivePaddingLeft() - getLeft()) / refWidth; - img.scalePercent(scale * 100); - float refHeight = pivoted ? img.getScaledWidth() : img.getScaledHeight(); - setBottom(getTop() - getEffectivePaddingTop() - getEffectivePaddingBottom() - refHeight); - } - else { - if (pivoted && hasFixedHeight()) - setBottom(getTop() - getFixedHeight()); - else { - ColumnText ct = ColumnText.duplicate(getColumn()); - float right, top, left, bottom; - if (pivoted) { - right = PdfPRow.RIGHT_LIMIT; - top = getRight() - getEffectivePaddingRight(); - left = 0; - bottom = getLeft() + getEffectivePaddingLeft(); - } - else { - right = isNoWrap() ? PdfPRow.RIGHT_LIMIT : getRight() - getEffectivePaddingRight(); - top = getTop() - getEffectivePaddingTop(); - left = getLeft() + getEffectivePaddingLeft(); - bottom = hasFixedHeight() ? top + getEffectivePaddingBottom() - getFixedHeight() : PdfPRow.BOTTOM_LIMIT; - } - PdfPRow.setColumn(ct, left, bottom, right, top); - try { - ct.go(true); - } catch (DocumentException e) { - throw new ExceptionConverter(e); - } - if (pivoted) - setBottom(getTop() - getEffectivePaddingTop() - getEffectivePaddingBottom() - ct.getFilledWidth()); - else { - float yLine = ct.getYLine(); - if (isUseDescender()) - yLine += ct.getDescender(); - setBottom(yLine - getEffectivePaddingBottom()); - } - } - } - float height = getHeight(); - if (height < getFixedHeight()) - height = getFixedHeight(); - else if (height < getMinimumHeight()) - height = getMinimumHeight(); - return height; - } + img.scalePercent(scale * 100); + float refHeight = pivoted ? img.getScaledWidth() : img.getScaledHeight(); + setBottom(getTop() - getEffectivePaddingTop() - getEffectivePaddingBottom() - refHeight); + } + else { + if (pivoted && hasFixedHeight()) + setBottom(getTop() - getFixedHeight()); + else { + ColumnText ct = ColumnText.duplicate(getColumn()); + float right, top, left, bottom; + if (pivoted) { + right = PdfPRow.RIGHT_LIMIT; + top = getRight() - getEffectivePaddingRight(); + left = 0; + bottom = getLeft() + getEffectivePaddingLeft(); + } + else { + right = isNoWrap() ? PdfPRow.RIGHT_LIMIT : getRight() - getEffectivePaddingRight(); + top = getTop() - getEffectivePaddingTop(); + left = getLeft() + getEffectivePaddingLeft(); + bottom = hasFixedHeight() ? top + getEffectivePaddingBottom() - getFixedHeight() : PdfPRow.BOTTOM_LIMIT; + } + PdfPRow.setColumn(ct, left, bottom, right, top); + try { + ct.go(true); + } catch (DocumentException e) { + throw new ExceptionConverter(e); + } + if (pivoted) + setBottom(getTop() - getEffectivePaddingTop() - getEffectivePaddingBottom() - ct.getFilledWidth()); + else { + float yLine = ct.getYLine(); + if (isUseDescender()) + yLine += ct.getDescender(); + setBottom(yLine - getEffectivePaddingBottom()); + } + } + } + float height = getHeight(); + if (height < getFixedHeight()) + height = getFixedHeight(); + else if (height < getMinimumHeight()) + height = getMinimumHeight(); + return height; + } + + private Container container; + + public Container getContainer() { + return container; + } + + public void addContent(Container container){ + this.container = container; + } } \ No newline at end of file diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfPRow.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfPRow.java index 10919d24b..102dcb7c9 100755 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfPRow.java +++ b/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 com.fr.third.com.lowagie.text.ExceptionConverter; import com.fr.third.com.lowagie.text.DocumentException; 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.Rectangle; /** * A row in a PdfPTable. - * + * * @author Paulo Soares (psoares@consiste.pt) */ public class PdfPRow { @@ -75,7 +75,17 @@ public class PdfPRow { protected PdfPCell cells[]; protected float widths[]; - + + private float styleHeight; + + public float getStyleHeight() { + return styleHeight; + } + + public void setStyleHeight(float styleHeight) { + this.styleHeight = styleHeight; + } + /** * extra heights that needs to be added to a cell because of rowspans. * @since 2.1.6 @@ -83,15 +93,15 @@ public class PdfPRow { protected float extraHeights[]; protected float maxHeight = 0; - + protected boolean calculated = false; - - private int[] canvasesPos; - + + private int[] canvasesPos; + /** * Constructs a new PdfPRow with the cells in the array that was passed * as a parameter. - * + * * @param cells */ public PdfPRow(PdfPCell cells[]) { @@ -102,7 +112,7 @@ public class PdfPRow { /** * Makes a copy of an existing row. - * + * * @param row */ public PdfPRow(PdfPRow row) { @@ -120,7 +130,7 @@ public class PdfPRow { /** * Sets the widths of the columns in the row. - * + * * @param widths * @return true if everything went right */ @@ -132,12 +142,12 @@ public class PdfPRow { calculated = false; for (int k = 0; k < widths.length; ++k) { PdfPCell cell = cells[k]; - + if (cell == null) { total += widths[k]; continue; } - + cell.setLeft(total); int last = k + cell.getColspan(); for (; k < last; ++k) @@ -159,7 +169,7 @@ public class PdfPRow { extraHeights[i] = 0; } } - + /** * Sets an extra height for a cell. * @param cell the index of the cell that needs an extra height @@ -171,48 +181,34 @@ public class PdfPRow { return; extraHeights[cell] = height; } - + /** * Calculates the heights of each cell in the row. - * + * * @return the maximum height of the row. */ public float calculateHeights() { maxHeight = 0; - // @change - int rowSpan = Integer.MAX_VALUE; - boolean hasAboveRowSpan = false; - float max_height = 0.0f; - for (int k = 0; k < cells.length;) { + for (int k = 0; k < cells.length; ++k) { PdfPCell cell = cells[k]; float height = 0; if (cell == null) { - hasAboveRowSpan = true; - k++; continue; } else { - height = cell.getMaxHeight(); - if (cell.getRowspan() == rowSpan && height > max_height) { - max_height = height; - } else if (cell.getRowspan() < rowSpan) { - rowSpan = cell.getRowspan(); - max_height = height; - } - k += cell.getColspan(); + height = cell.getStyleHeight() == 0 ? cell.getContainer().getHeight() : cell.getStyleHeight(); + if ((height > maxHeight) && (cell.getRowspan() == 1)) + maxHeight = height; } } calculated = true; - // carl:假如有格子是从属于一个rowSpan的格子,而这个格子的主格不在这一行(当然这样的假设建立在格子是满的情况下。) - if (!hasAboveRowSpan || rowSpan == 1) { - maxHeight = max_height; - } - return maxHeight; + return maxHeight = Math.max(styleHeight, maxHeight); } + /** * Writes the border and background of one cell in the row. - * + * * @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 currentMaxHeight The height of the cell to be drawn. @@ -228,7 +224,7 @@ public class PdfPRow { float top = cell.getTop() + yPos; float left = cell.getLeft() + xPos; float bottom = top - currentMaxHeight; - + if (background != null) { PdfContentByte backgr = canvases[PdfPTable.BACKGROUNDCANVAS]; backgr.setColorFill(background); @@ -250,48 +246,48 @@ public class PdfPRow { /** * @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) { - int last = PdfPTable.TEXTCANVAS + 1; - if (canvasesPos == null) - canvasesPos = new int[last * 2]; - for (int k = 0; k < last; ++k) { - ByteBuffer bb = canvases[k].getInternalBuffer(); - canvasesPos[k * 2] = bb.size(); - canvases[k].saveState(); - canvases[k].concatCTM(a, b, c, d, e, f); - canvasesPos[k * 2 + 1] = bb.size(); - } - } + protected void saveAndRotateCanvases(PdfContentByte[] canvases, float a, float b, float c, float d, float e, float f) { + int last = PdfPTable.TEXTCANVAS + 1; + if (canvasesPos == null) + canvasesPos = new int[last * 2]; + for (int k = 0; k < last; ++k) { + ByteBuffer bb = canvases[k].getInternalBuffer(); + canvasesPos[k * 2] = bb.size(); + canvases[k].saveState(); + canvases[k].concatCTM(a, b, c, d, e, f); + canvasesPos[k * 2 + 1] = bb.size(); + } + } /** * @since 2.1.6 private is now protected */ - protected void restoreCanvases(PdfContentByte[] canvases) { - int last = PdfPTable.TEXTCANVAS + 1; - for (int k = 0; k < last; ++k) { - ByteBuffer bb = canvases[k].getInternalBuffer(); - int p1 = bb.size(); - canvases[k].restoreState(); - if (p1 == canvasesPos[k * 2 + 1]) - bb.setSize(canvasesPos[k * 2]); - } - } + protected void restoreCanvases(PdfContentByte[] canvases) { + int last = PdfPTable.TEXTCANVAS + 1; + for (int k = 0; k < last; ++k) { + ByteBuffer bb = canvases[k].getInternalBuffer(); + int p1 = bb.size(); + canvases[k].restoreState(); + if (p1 == canvasesPos[k * 2 + 1]) + bb.setSize(canvasesPos[k * 2]); + } + } /** * @since 3.0.0 protected is now public static */ - public static float setColumn(ColumnText ct, float left, float bottom, float right, float top) { - if (left > right) - right = left; - if (bottom > top) - top = bottom; - ct.setSimpleColumn(left, bottom, right, top); - return top; - } - + public static float setColumn(ColumnText ct, float left, float bottom, float right, float top) { + if (left > right) + right = left; + if (bottom > top) + top = bottom; + ct.setSimpleColumn(left, bottom, right, top); + return top; + } + /** * Writes a number of cells (not necessarily all cells). - * + * * @param colStart The first column to be written. * Remember that the column index starts with 0. * @param colEnd The last column to be written. @@ -311,7 +307,7 @@ public class PdfPRow { colStart = 0; if (colStart >= colEnd) return; - + int newStart; for (newStart = colStart; newStart >= 0; --newStart) { if (cells[newStart] != null) @@ -319,42 +315,42 @@ public class PdfPRow { if (newStart > 0) xPos -= widths[newStart - 1]; } - + if (newStart < 0) newStart = 0; if (cells[newStart] != null) xPos -= cells[newStart].getLeft(); - + for (int k = newStart; k < colEnd; ++k) { PdfPCell cell = cells[k]; if (cell == null) continue; float currentMaxHeight = maxHeight + extraHeights[k]; - + writeBorderAndBackground(xPos, yPos, currentMaxHeight, cell, canvases); Image img = cell.getImage(); - + float tly = cell.getTop() + yPos - cell.getEffectivePaddingTop(); if (cell.getHeight() <= currentMaxHeight) { switch (cell.getVerticalAlignment()) { - case Element.ALIGN_BOTTOM: - tly = cell.getTop() + yPos - currentMaxHeight + cell.getHeight() - - cell.getEffectivePaddingTop(); - break; - case Element.ALIGN_MIDDLE: - tly = cell.getTop() + yPos + (cell.getHeight() - currentMaxHeight) / 2 - - cell.getEffectivePaddingTop(); - break; - default: - break; + case Element.ALIGN_BOTTOM: + tly = cell.getTop() + yPos - currentMaxHeight + cell.getHeight() + - cell.getEffectivePaddingTop(); + break; + case Element.ALIGN_MIDDLE: + tly = cell.getTop() + yPos + (cell.getHeight() - currentMaxHeight) / 2 + - cell.getEffectivePaddingTop(); + break; + default: + break; } } if (img != null) { - if (cell.getRotation() != 0) { - img = Image.getInstance(img); - img.setRotation(img.getImageRotation() + (float)(cell.getRotation() * Math.PI / 180.0)); - } + if (cell.getRotation() != 0) { + img = Image.getInstance(img); + img.setRotation(img.getImageRotation() + (float)(cell.getRotation() * Math.PI / 180.0)); + } boolean vf = false; if (cell.getHeight() > currentMaxHeight) { img.scalePercent(100); @@ -368,20 +364,20 @@ public class PdfPRow { + cell.getEffectivePaddingLeft(); if (vf) { switch (cell.getHorizontalAlignment()) { - case Element.ALIGN_CENTER: - left = xPos - + (cell.getLeft() + cell.getEffectivePaddingLeft() - + cell.getRight() - - cell.getEffectivePaddingRight() - img - .getScaledWidth()) / 2; - break; - case Element.ALIGN_RIGHT: - left = xPos + cell.getRight() - - cell.getEffectivePaddingRight() - - img.getScaledWidth(); - break; - default: - break; + case Element.ALIGN_CENTER: + left = xPos + + (cell.getLeft() + cell.getEffectivePaddingLeft() + + cell.getRight() + - cell.getEffectivePaddingRight() - img + .getScaledWidth()) / 2; + break; + case Element.ALIGN_RIGHT: + left = xPos + cell.getRight() + - cell.getEffectivePaddingRight() + - img.getScaledWidth(); + break; + default: + break; } tly = cell.getTop() + yPos - cell.getEffectivePaddingTop(); } @@ -392,128 +388,128 @@ public class PdfPRow { throw new ExceptionConverter(e); } } else { - // rotation sponsored by Connection GmbH - if (cell.getRotation() == 90 || cell.getRotation() == 270) { - float netWidth = currentMaxHeight - cell.getEffectivePaddingTop() - cell.getEffectivePaddingBottom(); - float netHeight = cell.getWidth() - cell.getEffectivePaddingLeft() - cell.getEffectivePaddingRight(); - ColumnText ct = ColumnText.duplicate(cell.getColumn()); - ct.setCanvases(canvases); - ct.setSimpleColumn(0, 0, netWidth + 0.001f, -netHeight); - try { - ct.go(true); - } catch (DocumentException e) { - throw new ExceptionConverter(e); - } - float calcHeight = -ct.getYLine(); - if (netWidth <= 0 || netHeight <= 0) - calcHeight = 0; - if (calcHeight > 0) { - if (cell.isUseDescender()) - calcHeight -= ct.getDescender(); - ct = ColumnText.duplicate(cell.getColumn()); - ct.setCanvases(canvases); - ct.setSimpleColumn(-0.003f, -0.001f, netWidth + 0.003f, calcHeight); - float pivotX; - float pivotY; - if (cell.getRotation() == 90) { - pivotY = cell.getTop() + yPos - currentMaxHeight + cell.getEffectivePaddingBottom(); - switch (cell.getVerticalAlignment()) { - case Element.ALIGN_BOTTOM: - pivotX = cell.getLeft() + xPos + cell.getWidth() - cell.getEffectivePaddingRight(); - break; - case Element.ALIGN_MIDDLE: - pivotX = cell.getLeft() + xPos + (cell.getWidth() + cell.getEffectivePaddingLeft() - cell.getEffectivePaddingRight() + calcHeight) / 2; - break; - default: //top - pivotX = cell.getLeft() + xPos + cell.getEffectivePaddingLeft() + calcHeight; - break; - } - saveAndRotateCanvases(canvases, 0,1,-1,0,pivotX,pivotY); - } - else { - pivotY = cell.getTop() + yPos - cell.getEffectivePaddingTop(); - switch (cell.getVerticalAlignment()) { - case Element.ALIGN_BOTTOM: - pivotX = cell.getLeft() + xPos + cell.getEffectivePaddingLeft(); - break; - case Element.ALIGN_MIDDLE: - pivotX = cell.getLeft() + xPos + (cell.getWidth() + cell.getEffectivePaddingLeft() - cell.getEffectivePaddingRight() - calcHeight) / 2; - break; - default: //top - pivotX = cell.getLeft() + xPos + cell.getWidth() - cell.getEffectivePaddingRight() - calcHeight; - break; - } - saveAndRotateCanvases(canvases, 0,-1,1,0,pivotX,pivotY); - } - try { - ct.go(); - } catch (DocumentException e) { - throw new ExceptionConverter(e); - } finally { - restoreCanvases(canvases); - } - } - } - else { - float fixedHeight = cell.getFixedHeight(); - float rightLimit = cell.getRight() + xPos - - cell.getEffectivePaddingRight(); - float leftLimit = cell.getLeft() + xPos - + cell.getEffectivePaddingLeft(); - if (cell.isNoWrap()) { - switch (cell.getHorizontalAlignment()) { - case Element.ALIGN_CENTER: - rightLimit += 10000; - leftLimit -= 10000; - break; - case Element.ALIGN_RIGHT: - if (cell.getRotation() == 180) { - rightLimit += RIGHT_LIMIT; - } - else { - leftLimit -= RIGHT_LIMIT; - } - break; - default: - if (cell.getRotation() == 180) { - leftLimit -= RIGHT_LIMIT; - } - else { - rightLimit += RIGHT_LIMIT; - } - break; - } - } - ColumnText ct = ColumnText.duplicate(cell.getColumn()); - ct.setCanvases(canvases); - float bry = tly - - (currentMaxHeight - - cell.getEffectivePaddingTop() - cell.getEffectivePaddingBottom()); - if (fixedHeight > 0) { - if (cell.getHeight() > currentMaxHeight) { - tly = cell.getTop() + yPos - cell.getEffectivePaddingTop(); - bry = cell.getTop() + yPos - currentMaxHeight + cell.getEffectivePaddingBottom(); - } - } - if ((tly > bry || ct.zeroHeightElement()) && leftLimit < rightLimit) { - ct.setSimpleColumn(leftLimit, bry - 0.001f, rightLimit, tly); - if (cell.getRotation() == 180) { - float shx = leftLimit + rightLimit; - float shy = yPos + yPos - currentMaxHeight + cell.getEffectivePaddingBottom() - cell.getEffectivePaddingTop(); - saveAndRotateCanvases(canvases, -1,0,0,-1,shx,shy); - } - try { - ct.go(); - } catch (DocumentException e) { - throw new ExceptionConverter(e); - } finally { - if (cell.getRotation() == 180) { - restoreCanvases(canvases); - } - } - } - } - } + // rotation sponsored by Connection GmbH + if (cell.getRotation() == 90 || cell.getRotation() == 270) { + float netWidth = currentMaxHeight - cell.getEffectivePaddingTop() - cell.getEffectivePaddingBottom(); + float netHeight = cell.getWidth() - cell.getEffectivePaddingLeft() - cell.getEffectivePaddingRight(); + ColumnText ct = ColumnText.duplicate(cell.getColumn()); + ct.setCanvases(canvases); + ct.setSimpleColumn(0, 0, netWidth + 0.001f, -netHeight); + try { + ct.go(true); + } catch (DocumentException e) { + throw new ExceptionConverter(e); + } + float calcHeight = -ct.getYLine(); + if (netWidth <= 0 || netHeight <= 0) + calcHeight = 0; + if (calcHeight > 0) { + if (cell.isUseDescender()) + calcHeight -= ct.getDescender(); + ct = ColumnText.duplicate(cell.getColumn()); + ct.setCanvases(canvases); + ct.setSimpleColumn(-0.003f, -0.001f, netWidth + 0.003f, calcHeight); + float pivotX; + float pivotY; + if (cell.getRotation() == 90) { + pivotY = cell.getTop() + yPos - currentMaxHeight + cell.getEffectivePaddingBottom(); + switch (cell.getVerticalAlignment()) { + case Element.ALIGN_BOTTOM: + pivotX = cell.getLeft() + xPos + cell.getWidth() - cell.getEffectivePaddingRight(); + break; + case Element.ALIGN_MIDDLE: + pivotX = cell.getLeft() + xPos + (cell.getWidth() + cell.getEffectivePaddingLeft() - cell.getEffectivePaddingRight() + calcHeight) / 2; + break; + default: //top + pivotX = cell.getLeft() + xPos + cell.getEffectivePaddingLeft() + calcHeight; + break; + } + saveAndRotateCanvases(canvases, 0,1,-1,0,pivotX,pivotY); + } + else { + pivotY = cell.getTop() + yPos - cell.getEffectivePaddingTop(); + switch (cell.getVerticalAlignment()) { + case Element.ALIGN_BOTTOM: + pivotX = cell.getLeft() + xPos + cell.getEffectivePaddingLeft(); + break; + case Element.ALIGN_MIDDLE: + pivotX = cell.getLeft() + xPos + (cell.getWidth() + cell.getEffectivePaddingLeft() - cell.getEffectivePaddingRight() - calcHeight) / 2; + break; + default: //top + pivotX = cell.getLeft() + xPos + cell.getWidth() - cell.getEffectivePaddingRight() - calcHeight; + break; + } + saveAndRotateCanvases(canvases, 0,-1,1,0,pivotX,pivotY); + } + try { + ct.go(); + } catch (DocumentException e) { + throw new ExceptionConverter(e); + } finally { + restoreCanvases(canvases); + } + } + } + else { + float fixedHeight = cell.getFixedHeight(); + float rightLimit = cell.getRight() + xPos + - cell.getEffectivePaddingRight(); + float leftLimit = cell.getLeft() + xPos + + cell.getEffectivePaddingLeft(); + if (cell.isNoWrap()) { + switch (cell.getHorizontalAlignment()) { + case Element.ALIGN_CENTER: + rightLimit += 10000; + leftLimit -= 10000; + break; + case Element.ALIGN_RIGHT: + if (cell.getRotation() == 180) { + rightLimit += RIGHT_LIMIT; + } + else { + leftLimit -= RIGHT_LIMIT; + } + break; + default: + if (cell.getRotation() == 180) { + leftLimit -= RIGHT_LIMIT; + } + else { + rightLimit += RIGHT_LIMIT; + } + break; + } + } + ColumnText ct = ColumnText.duplicate(cell.getColumn()); + ct.setCanvases(canvases); + float bry = tly + - (currentMaxHeight + - cell.getEffectivePaddingTop() - cell.getEffectivePaddingBottom()); + if (fixedHeight > 0) { + if (cell.getHeight() > currentMaxHeight) { + tly = cell.getTop() + yPos - cell.getEffectivePaddingTop(); + bry = cell.getTop() + yPos - currentMaxHeight + cell.getEffectivePaddingBottom(); + } + } + if ((tly > bry || ct.zeroHeightElement()) && leftLimit < rightLimit) { + ct.setSimpleColumn(leftLimit, bry - 0.001f, rightLimit, tly); + if (cell.getRotation() == 180) { + float shx = leftLimit + rightLimit; + float shy = yPos + yPos - currentMaxHeight + cell.getEffectivePaddingBottom() - cell.getEffectivePaddingTop(); + saveAndRotateCanvases(canvases, -1,0,0,-1,shx,shy); + } + try { + ct.go(); + } catch (DocumentException e) { + throw new ExceptionConverter(e); + } finally { + if (cell.getRotation() == 180) { + restoreCanvases(canvases); + } + } + } + } + } PdfPCellEvent evt = cell.getCellEvent(); if (evt != null) { 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. - * + * * @return true if the dimensions of the columns were calculated */ public boolean isCalculated() { @@ -535,7 +531,7 @@ public class PdfPRow { /** * Gets the maximum height of the row (i.e. of the 'highest' cell). - * + * * @return the maximum height of the row */ public float getMaxHeights() { @@ -547,7 +543,7 @@ public class PdfPRow { /** * Changes the maximum height of the row (to make it higher). * (added by Jin-Hsia Yang) - * + * * @param maxHeight the new maximum height */ public void setMaxHeights(float maxHeight) { @@ -578,7 +574,7 @@ public class PdfPRow { * Splits a row to newHeight. * The returned row is the remainder. It will return null if the newHeight * was so small that only an empty row would result. - * + * * @param new_height the new height * @return the remainder row or null if the newHeight was so small that only * an empty row would result @@ -619,22 +615,22 @@ public class PdfPRow { } } else { - float y; + float y; ColumnText ct = ColumnText.duplicate(cell.getColumn()); - float left = cell.getLeft() + cell.getEffectivePaddingLeft(); - float bottom = cell.getTop() + cell.getEffectivePaddingBottom() - newHeight; - float right = cell.getRight() - cell.getEffectivePaddingRight(); - float top = cell.getTop() - cell.getEffectivePaddingTop(); - switch (cell.getRotation()) { - case 90: - case 270: - y = setColumn(ct, bottom, left, top, right); - break; - default: - y = setColumn(ct, left, bottom, cell.isNoWrap() ? RIGHT_LIMIT : right, top); - break; - } - int status; + float left = cell.getLeft() + cell.getEffectivePaddingLeft(); + float bottom = cell.getTop() + cell.getEffectivePaddingBottom() - newHeight; + float right = cell.getRight() - cell.getEffectivePaddingRight(); + float top = cell.getTop() - cell.getEffectivePaddingTop(); + switch (cell.getRotation()) { + case 90: + case 270: + y = setColumn(ct, bottom, left, top, right); + break; + default: + y = setColumn(ct, left, bottom, cell.isNoWrap() ? RIGHT_LIMIT : right, top); + break; + } + int status; try { status = ct.go(true); } @@ -648,7 +644,7 @@ public class PdfPRow { } else if ((status & ColumnText.NO_MORE_TEXT) == 0) { newCell.setColumn(ct); - ct.setFilledWidth(0); + ct.setFilledWidth(0); } else newCell.setPhrase(null); @@ -675,12 +671,12 @@ public class PdfPRow { split.calculateHeights(); return split; } - + /** * Returns the array of cells in the row. * Please be extremely careful with this method. * Use the cells as read only objects. - * + * * @return an array of cells * @since 2.1.1 */ diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfPTable.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfPTable.java index 7216dd8a0..de5521c54 100755 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfPTable.java +++ b/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/PdfPTable.java @@ -53,153 +53,166 @@ import java.util.ArrayList; import com.fr.third.com.lowagie.text.DocumentException; import com.fr.third.com.lowagie.text.Element; +import com.fr.third.com.lowagie.text.LargeElement; import com.fr.third.com.lowagie.text.ElementListener; import com.fr.third.com.lowagie.text.Image; -import com.fr.third.com.lowagie.text.LargeElement; import com.fr.third.com.lowagie.text.Phrase; import com.fr.third.com.lowagie.text.Rectangle; import com.fr.third.com.lowagie.text.pdf.events.PdfPTableEventForwarder; +import com.fr.third.com.lowagie.text.pdf.BorderStyle; +import com.fr.third.com.lowagie.text.pdf.TableProperties; /** * This is a table that can be put at an absolute position but can also * be added to the document as the class Table. * In the last case when crossing pages the table always break at full rows; if a * row is bigger than the page it is dropped silently to avoid infinite loops. - *

+ *

* A PdfPTableEvent can be associated to the table to do custom drawing * when the table is rendered. + * * @author Paulo Soares (psoares@consiste.pt) */ -public class PdfPTable implements LargeElement{ - +public class PdfPTable implements LargeElement { + /** * The index of the original PdfcontentByte. - */ + */ public static final int BASECANVAS = 0; - + /** * The index of the duplicate PdfContentByte where the background will be drawn. - */ + */ public static final int BACKGROUNDCANVAS = 1; - + /** * The index of the duplicate PdfContentByte where the border lines will be drawn. - */ + */ public static final int LINECANVAS = 2; - + /** * The index of the duplicate PdfContentByte where the text will be drawn. - */ + */ public static final int TEXTCANVAS = 3; - + protected ArrayList rows = new ArrayList(); protected float totalHeight = 0; protected PdfPCell currentRow[]; protected int currentRowIdx = 0; - protected PdfPCell defaultCell = new PdfPCell((Phrase)null); + protected PdfPCell defaultCell = new PdfPCell((Phrase) null); protected float totalWidth = 0; protected float relativeWidths[]; protected float absoluteWidths[]; protected PdfPTableEvent tableEvent; - - + private TableProperties tableProperties; + + public TableProperties getTableProperties() { + return tableProperties; + } + + public void setTableProperties(TableProperties tableProperties) { + this.tableProperties = tableProperties; + } + /** * Holds value of property headerRows. */ protected int headerRows; - + /** * Holds value of property widthPercentage. */ protected float widthPercentage = 80; - + /** * Holds value of property horizontalAlignment. */ private int horizontalAlignment = Element.ALIGN_CENTER; - + /** * Holds value of property skipFirstHeader. */ private boolean skipFirstHeader = false; /** * Holds value of property skipLastFooter. - * @since 2.1.6 + * + * @since 2.1.6 */ private boolean skipLastFooter = false; protected boolean isColspan = false; - + protected int runDirection = PdfWriter.RUN_DIRECTION_DEFAULT; /** * Holds value of property lockedWidth. */ private boolean lockedWidth = false; - + /** * Holds value of property splitRows. */ private boolean splitRows = true; - + /** * The spacing before the table. */ protected float spacingBefore; - + /** * The spacing after the table. */ protected float spacingAfter; - + /** * Holds value of property extendLastRow. */ private boolean extendLastRow; - + /** * Holds value of property headersInEvent. */ private boolean headersInEvent; - + /** * Holds value of property splitLate. */ private boolean splitLate = true; - + /** * Defines if the table should be kept * on one page if possible */ private boolean keepTogether; - + /** * Indicates if the PdfPTable is complete once added to the document. - * - * @since iText 2.0.8 + * + * @since iText 2.0.8 */ protected boolean complete = true; - + /** * Holds value of property footerRows. */ private int footerRows; - + /** * Keeps track of the completeness of the current row. - * @since 2.1.6 + * + * @since 2.1.6 */ protected boolean rowCompleted = true; - + protected PdfPTable() { } - - /** + + /** * Constructs a PdfPTable with the relative column widths. - * + * * @param relativeWidths the relative column widths - */ + */ public PdfPTable(float relativeWidths[]) { if (relativeWidths == null) throw new NullPointerException("The widths array in PdfPTable constructor can not be null."); @@ -213,11 +226,11 @@ public class PdfPTable implements LargeElement{ keepTogether = false; } - /** + /** * Constructs a PdfPTable with numColumns columns. - * + * * @param numColumns the number of columns - */ + */ public PdfPTable(int numColumns) { if (numColumns <= 0) throw new IllegalArgumentException("The number of columns in PdfPTable constructor must be greater than zero."); @@ -229,12 +242,12 @@ public class PdfPTable implements LargeElement{ currentRow = new PdfPCell[absoluteWidths.length]; keepTogether = false; } - - /** + + /** * Constructs a copy of a PdfPTable. - * + * * @param table the PdfPTable to be copied - */ + */ public PdfPTable(PdfPTable table) { copyFormat(table); for (int k = 0; k < currentRow.length; ++k) { @@ -243,16 +256,16 @@ public class PdfPTable implements LargeElement{ currentRow[k] = new PdfPCell(table.currentRow[k]); } for (int k = 0; k < table.rows.size(); ++k) { - PdfPRow row = (PdfPRow)(table.rows.get(k)); + PdfPRow row = (PdfPRow) (table.rows.get(k)); if (row != null) row = new PdfPRow(row); rows.add(row); } } - + /** * Makes a shallow copy of a table (format without content). - * + * * @param table * @return a shallow copy of the table */ @@ -264,10 +277,10 @@ public class PdfPTable implements LargeElement{ /** * Copies the format of the sourceTable without copying the content. - * + * * @param sourceTable - * @since 2.1.6 private is now protected - */ + * @since 2.1.6 private is now protected + */ protected void copyFormat(PdfPTable sourceTable) { relativeWidths = new float[sourceTable.getNumberOfColumns()]; absoluteWidths = new float[sourceTable.getNumberOfColumns()]; @@ -296,15 +309,16 @@ public class PdfPTable implements LargeElement{ horizontalAlignment = sourceTable.horizontalAlignment; keepTogether = sourceTable.keepTogether; complete = sourceTable.complete; + tableProperties = sourceTable.tableProperties; } /** * Sets the relative widths of the table. - * + * * @param relativeWidths the relative widths of the table. * @throws DocumentException if the number of widths is different than the number - * of columns - */ + * of columns + */ public void setWidths(float relativeWidths[]) throws DocumentException { if (relativeWidths.length != getNumberOfColumns()) throw new DocumentException("Wrong number of columns."); @@ -313,16 +327,16 @@ public class PdfPTable implements LargeElement{ absoluteWidths = new float[relativeWidths.length]; totalHeight = 0; calculateWidths(); - calculateHeights(true); +// calculateHeights(true); } /** * Sets the relative widths of the table. - * + * * @param relativeWidths the relative widths of the table. * @throws DocumentException if the number of widths is different than the number - * of columns - */ + * of columns + */ public void setWidths(int relativeWidths[]) throws DocumentException { float tb[] = new float[relativeWidths.length]; for (int k = 0; k < relativeWidths.length; ++k) @@ -330,41 +344,49 @@ public class PdfPTable implements LargeElement{ setWidths(tb); } - /** - * @since 2.1.6 private is now protected - */ + /** + * @since 2.1.6 private is now protected + */ protected void calculateWidths() { if (totalWidth <= 0) return; float total = 0; int numCols = getNumberOfColumns(); + BorderStyle borderStyle = tableProperties.getBorderStyle(); + float borderWidth = tableProperties.isCollapse() ? borderStyle.getBorderWidth() / 2 : borderStyle.getBorderWidth(); + float cellspacing = tableProperties.getCellspacing(); + float cellpadding = tableProperties.getCellpadding(); for (int k = 0; k < numCols; ++k) total += relativeWidths[k]; for (int k = 0; k < numCols; ++k) - absoluteWidths[k] = totalWidth * relativeWidths[k] / total; + absoluteWidths[k] = (totalWidth - cellspacing * (numCols + 1) - numCols * 2 * (borderWidth + cellpadding) - 2 * borderWidth) * relativeWidths[k] / total; } - + /** * Sets the full width of the table. - * + * * @param totalWidth the full width of the table. - */ + */ public void setTotalWidth(float totalWidth) { if (this.totalWidth == totalWidth) return; this.totalWidth = totalWidth; totalHeight = 0; calculateWidths(); - calculateHeights(true); +// calculateHeights(true); + for (int k = 0; k < rows.size(); ++k) { + PdfPRow row = (PdfPRow) rows.get(k); + row.setWidths(absoluteWidths); + } } /** * Sets the full width of the table from the absolute column width. - * + * * @param columnWidth the absolute width of each column * @throws DocumentException if the number of widths is different than the number - * of columns - */ + * of columns + */ public void setTotalWidth(float columnWidth[]) throws DocumentException { if (columnWidth.length != getNumberOfColumns()) throw new DocumentException("Wrong number of columns."); @@ -376,11 +398,11 @@ public class PdfPTable implements LargeElement{ /** * Sets the percentage width of the table from the absolute column width. - * + * * @param columnWidth the absolute width of each column - * @param pageSize the page size + * @param pageSize the page size * @throws DocumentException - */ + */ public void setWidthPercentage(float columnWidth[], Rectangle pageSize) throws DocumentException { if (columnWidth.length != getNumberOfColumns()) throw new IllegalArgumentException("Wrong number of columns."); @@ -393,61 +415,66 @@ public class PdfPTable implements LargeElement{ /** * Gets the full width of the table. - * + * * @return the full width of the table - */ + */ public float getTotalWidth() { return totalWidth; } - + /** * Calculates the heights of the table. - * - * @param firsttime if true, the heights of the rows will be recalculated. + * + * @param firsttime if true, the heights of the rows will be recalculated. * This takes time; normally the heights of the rows are already calcultated, * so in most cases, it's save to use false as parameter. - * @return the total height of the table. Note that it will be 0 if you didn't + * @return the total height of the table. Note that it will be 0 if you didn't * specify the width of the table with setTotalWidth(). - * @since 2.1.5 added a parameter and a return type to an existing method, + * @since 2.1.5 added a parameter and a return type to an existing method, * and made it public */ public float calculateHeights(boolean firsttime) { if (totalWidth <= 0) return 0; totalHeight = 0; + BorderStyle borderStyle = tableProperties.getBorderStyle(); + float borderWidth = tableProperties.isCollapse() ? borderStyle.getBorderWidth() / 2 : borderStyle.getBorderWidth(); + float cellspacing = tableProperties.getCellspacing(); + float cellpadding = tableProperties.getCellpadding(); for (int k = 0; k < rows.size(); ++k) { - totalHeight += getRowHeight(k, firsttime); + totalHeight += getRowHeight(k, firsttime); } + totalHeight += (rows.size() + 1) * 2 * borderWidth + cellpadding * 2 * rows.size() + (rows.size() + 1) * cellspacing; return totalHeight; } - + /** * Calculates the heights of the table. */ public void calculateHeightsFast() { calculateHeights(false); } - + /** * Gets the default PdfPCell that will be used as * reference for all the addCell methods except * addCell(PdfPCell). - * + * * @return default PdfPCell - */ + */ public PdfPCell getDefaultCell() { return defaultCell; } - + /** * Adds a cell element. - * + * * @param cell the cell element - */ + */ public void addCell(PdfPCell cell) { - rowCompleted = false; + rowCompleted = false; PdfPCell ncell = new PdfPCell(cell); - + int colspan = ncell.getColspan(); colspan = Math.max(colspan, 1); colspan = Math.min(colspan, currentRow.length - currentRowIdx); @@ -458,20 +485,20 @@ public class PdfPTable implements LargeElement{ int rdir = ncell.getRunDirection(); if (rdir == PdfWriter.RUN_DIRECTION_DEFAULT) ncell.setRunDirection(runDirection); - + skipColsWithRowspanAbove(); - + boolean cellAdded = false; - if (currentRowIdx < currentRow.length) { - currentRow[currentRowIdx] = ncell; - currentRowIdx += colspan; - cellAdded = true; + if (currentRowIdx < currentRow.length) { + currentRow[currentRowIdx] = ncell; + currentRowIdx += colspan; + cellAdded = true; } skipColsWithRowspanAbove(); - + if (currentRowIdx >= currentRow.length) { - int numCols = getNumberOfColumns(); + int numCols = getNumberOfColumns(); if (runDirection == PdfWriter.RUN_DIRECTION_RTL) { PdfPCell rtlRow[] = new PdfPCell[numCols]; int rev = currentRow.length; @@ -487,201 +514,203 @@ public class PdfPTable implements LargeElement{ PdfPRow row = new PdfPRow(currentRow); if (totalWidth > 0) { row.setWidths(absoluteWidths); - totalHeight += row.getMaxHeights(); +// totalHeight += row.getMaxHeights(); } rows.add(row); currentRow = new PdfPCell[numCols]; currentRowIdx = 0; rowCompleted = true; } - + if (!cellAdded) { currentRow[currentRowIdx] = ncell; currentRowIdx += colspan; } } - + /** * When updating the row index, cells with rowspan should be taken into account. * This is what happens in this method. - * @since 2.1.6 + * + * @since 2.1.6 */ private void skipColsWithRowspanAbove() { - int direction = 1; - if (runDirection == PdfWriter.RUN_DIRECTION_RTL) - direction = -1; - while (rowSpanAbove(rows.size(), currentRowIdx)) - currentRowIdx += direction; + int direction = 1; + if (runDirection == PdfWriter.RUN_DIRECTION_RTL) + direction = -1; + while (rowSpanAbove(rows.size(), currentRowIdx)) + currentRowIdx += direction; } - + /** * Checks if there are rows above belonging to a rowspan. - * @param currRow the current row to check - * @param currCol the current column to check - * @return true if there's a cell above that belongs to a rowspan - * @since 2.1.6 + * + * @param currRow the current row to check + * @param currCol the current column to check + * @return true if there's a cell above that belongs to a rowspan + * @since 2.1.6 */ boolean rowSpanAbove(int currRow, int currCol) { - - if ((currCol >= getNumberOfColumns()) - || (currCol < 0) - || (currRow == 0)) - return false; - - int row = currRow - 1; - PdfPRow aboveRow = (PdfPRow)rows.get(row); - if (aboveRow == null) - return false; - PdfPCell aboveCell = (PdfPCell)aboveRow.getCells()[currCol]; - while ((aboveCell == null) && (row > 0)) { - aboveRow = (PdfPRow)rows.get(--row); - if (aboveRow == null) - return false; - aboveCell = (PdfPCell)aboveRow.getCells()[currCol]; - } - - int distance = currRow - row; - - if (aboveCell == null) { - int col = currCol - 1; - aboveCell = (PdfPCell)aboveRow.getCells()[col]; - while ((aboveCell == null) && (row > 0)) - aboveCell = (PdfPCell)aboveRow.getCells()[--col]; - return aboveCell != null && aboveCell.getRowspan() > distance; - } - - if ((aboveCell.getRowspan() == 1) && (distance > 1)) { - int col = currCol - 1; - aboveRow = (PdfPRow)rows.get(row + 1); - distance--; - aboveCell = (PdfPCell)aboveRow.getCells()[col]; - while ((aboveCell == null) && (col > 0)) - aboveCell = (PdfPCell)aboveRow.getCells()[--col]; - } - - return aboveCell != null && aboveCell.getRowspan() > distance; - } - - + + if ((currCol >= getNumberOfColumns()) + || (currCol < 0) + || (currRow == 0)) + return false; + + int row = currRow - 1; + PdfPRow aboveRow = (PdfPRow) rows.get(row); + if (aboveRow == null) + return false; + PdfPCell aboveCell = (PdfPCell) aboveRow.getCells()[currCol]; + while ((aboveCell == null) && (row > 0)) { + aboveRow = (PdfPRow) rows.get(--row); + if (aboveRow == null) + return false; + aboveCell = (PdfPCell) aboveRow.getCells()[currCol]; + } + + int distance = currRow - row; + + if (aboveCell == null) { + int col = currCol - 1; + aboveCell = (PdfPCell) aboveRow.getCells()[col]; + while ((aboveCell == null) && (row > 0)) + aboveCell = (PdfPCell) aboveRow.getCells()[--col]; + return aboveCell != null && aboveCell.getRowspan() > distance; + } + + if ((aboveCell.getRowspan() == 1) && (distance > 1)) { + int col = currCol - 1; + aboveRow = (PdfPRow) rows.get(row + 1); + distance--; + aboveCell = (PdfPCell) aboveRow.getCells()[col]; + while ((aboveCell == null) && (col > 0)) + aboveCell = (PdfPCell) aboveRow.getCells()[--col]; + } + + return aboveCell != null && aboveCell.getRowspan() > distance; + } + + /** * Adds a cell element. - * + * * @param text the text for the cell - */ + */ public void addCell(String text) { addCell(new Phrase(text)); } - + /** * Adds a nested table. - * + * * @param table the table to be added to the cell - */ + */ public void addCell(PdfPTable table) { defaultCell.setTable(table); addCell(defaultCell); defaultCell.setTable(null); } - + /** * Adds an Image as Cell. - * + * * @param image the Image to add to the table. - * This image will fit in the cell - */ + * This image will fit in the cell + */ public void addCell(Image image) { defaultCell.setImage(image); addCell(defaultCell); defaultCell.setImage(null); } - + /** * Adds a cell element. - * + * * @param phrase the Phrase to be added to the cell - */ + */ public void addCell(Phrase phrase) { defaultCell.setPhrase(phrase); addCell(defaultCell); defaultCell.setPhrase(null); } - + /** * Writes the selected rows to the document. * canvases is obtained from beginWritingRows(). - * + * * @param rowStart the first row to be written, zero index - * @param rowEnd the last row to be written + 1. If it is -1 all the - * rows to the end are written - * @param xPos the x write coordinate - * @param yPos the y write coordinate + * @param rowEnd the last row to be written + 1. If it is -1 all the + * rows to the end are written + * @param xPos the x write coordinate + * @param yPos the y write coordinate * @param canvases an array of 4 PdfContentByte obtained from - * beginWrittingRows() + * beginWrittingRows() * @return the y coordinate position of the bottom of the last row - * @see #beginWritingRows(com.fr.third.com.lowagie.text.pdf.PdfContentByte) - */ + * @see #beginWritingRows(PdfContentByte) + */ public float writeSelectedRows(int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte[] canvases) { return writeSelectedRows(0, -1, rowStart, rowEnd, xPos, yPos, canvases); } - + /** * Writes the selected rows and columns to the document. * This method does not clip the columns; this is only important * if there are columns with colspan at boundaries. * canvases is obtained from beginWritingRows(). * The table event is only fired for complete rows. - * + * * @param colStart the first column to be written, zero index - * @param colEnd the last column to be written + 1. If it is -1 all the - * columns to the end are written + * @param colEnd the last column to be written + 1. If it is -1 all the + * columns to the end are written * @param rowStart the first row to be written, zero index - * @param rowEnd the last row to be written + 1. If it is -1 all the - * rows to the end are written - * @param xPos the x write coordinate - * @param yPos the y write coordinate + * @param rowEnd the last row to be written + 1. If it is -1 all the + * rows to the end are written + * @param xPos the x write coordinate + * @param yPos the y write coordinate * @param canvases an array of 4 PdfContentByte obtained from - * beginWritingRows() + * beginWritingRows() * @return the y coordinate position of the bottom of the last row - * @see #beginWritingRows(com.fr.third.com.lowagie.text.pdf.PdfContentByte) - */ + * @see #beginWritingRows(PdfContentByte) + */ public float writeSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte[] canvases) { if (totalWidth <= 0) throw new RuntimeException("The table width must be greater than zero."); - + int totalRows = rows.size(); if (rowStart < 0) rowStart = 0; if (rowEnd < 0) rowEnd = totalRows; else - rowEnd = Math.min(rowEnd, totalRows); + rowEnd = Math.min(rowEnd, totalRows); if (rowStart >= rowEnd) return yPos; - + int totalCols = getNumberOfColumns(); if (colStart < 0) colStart = 0; else - colStart = Math.min(colStart, totalCols); + colStart = Math.min(colStart, totalCols); if (colEnd < 0) colEnd = totalCols; else - colEnd = Math.min(colEnd, totalCols); - + colEnd = Math.min(colEnd, totalCols); + float yPosStart = yPos; for (int k = rowStart; k < rowEnd; ++k) { - PdfPRow row = (PdfPRow)rows.get(k); + PdfPRow row = (PdfPRow) rows.get(k); if (row != null) { row.writeCells(colStart, colEnd, xPos, yPos, canvases); yPos -= row.getMaxHeights(); } } - + if (tableEvent != null && colStart == 0 && colEnd == totalCols) { float heights[] = new float[rowEnd - rowStart + 1]; heights[0] = yPosStart; for (int k = rowStart; k < rowEnd; ++k) { - PdfPRow row = (PdfPRow)rows.get(k); + PdfPRow row = (PdfPRow) rows.get(k); float hr = 0; if (row != null) hr = row.getMaxHeights(); @@ -689,58 +718,58 @@ public class PdfPTable implements LargeElement{ } tableEvent.tableLayout(this, getEventWidths(xPos, rowStart, rowEnd, headersInEvent), heights, headersInEvent ? headerRows : 0, rowStart, canvases); } - + return yPos; } - + /** * Writes the selected rows to the document. - * + * * @param rowStart the first row to be written, zero index - * @param rowEnd the last row to be written + 1. If it is -1 all the - * rows to the end are written - * @param xPos the x write coordinate - * @param yPos the y write coordinate - * @param canvas the PdfContentByte where the rows will - * be written to + * @param rowEnd the last row to be written + 1. If it is -1 all the + * rows to the end are written + * @param xPos the x write coordinate + * @param yPos the y write coordinate + * @param canvas the PdfContentByte where the rows will + * be written to * @return the y coordinate position of the bottom of the last row - */ + */ public float writeSelectedRows(int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte canvas) { return writeSelectedRows(0, -1, rowStart, rowEnd, xPos, yPos, canvas); } - + /** * Writes the selected rows and columns to the document. * This method clips the columns; this is only important * if there are columns with colspan at boundaries. * The table event is only fired for complete rows. - * + * * @param colStart the first column to be written, zero index - * @param colEnd the last column to be written + 1. If it is -1 all the - * columns to the end are written + * @param colEnd the last column to be written + 1. If it is -1 all the + * columns to the end are written * @param rowStart the first row to be written, zero index - * @param rowEnd the last row to be written + 1. If it is -1 all the - * rows to the end are written - * @param xPos the x write coordinate - * @param yPos the y write coordinate - * @param canvas the PdfContentByte where the rows will - * be written to + * @param rowEnd the last row to be written + 1. If it is -1 all the + * rows to the end are written + * @param xPos the x write coordinate + * @param yPos the y write coordinate + * @param canvas the PdfContentByte where the rows will + * be written to * @return the y coordinate position of the bottom of the last row - */ + */ public float writeSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte canvas) { int totalCols = getNumberOfColumns(); if (colStart < 0) colStart = 0; else - colStart = Math.min(colStart, totalCols); - - if (colEnd < 0) + colStart = Math.min(colStart, totalCols); + + if (colEnd < 0) colEnd = totalCols; - else - colEnd = Math.min(colEnd, totalCols); - - boolean clip = (colStart != 0 || colEnd != totalCols); - + else + colEnd = Math.min(colEnd, totalCols); + + boolean clip = (colStart != 0 || colEnd != totalCols); + if (clip) { float w = 0; for (int k = colStart; k < colEnd; ++k) @@ -752,17 +781,17 @@ public class PdfPTable implements LargeElement{ canvas.clip(); canvas.newPath(); } - + PdfContentByte[] canvases = beginWritingRows(canvas); float y = writeSelectedRows(colStart, colEnd, rowStart, rowEnd, xPos, yPos, canvases); endWritingRows(canvases); - + if (clip) canvas.restoreState(); - + return y; } - + /** * Gets and initializes the 4 layers where the table is written to. The text or graphics are added to * one of the 4 PdfContentByte returned with the following order:

@@ -775,26 +804,26 @@ public class PdfPTable implements LargeElement{ * will be over the table. *

* The layers are placed in sequence on top of each other. - * + * * @param canvas the PdfContentByte where the rows will - * be written to + * be written to * @return an array of 4 PdfContentByte * @see #writeSelectedRows(int, int, float, float, PdfContentByte[]) - */ + */ public static PdfContentByte[] beginWritingRows(PdfContentByte canvas) { return new PdfContentByte[]{ - canvas, - canvas.getDuplicate(), - canvas.getDuplicate(), - canvas.getDuplicate(), + canvas, + canvas.getDuplicate(), + canvas.getDuplicate(), + canvas.getDuplicate(), }; } - + /** * Finishes writing the table. - * + * * @param canvases the array returned by beginWritingRows() - */ + */ public static void endWritingRows(PdfContentByte[] canvases) { PdfContentByte canvas = canvases[BASECANVAS]; canvas.saveState(); @@ -807,74 +836,73 @@ public class PdfPTable implements LargeElement{ canvas.restoreState(); canvas.add(canvases[TEXTCANVAS]); } - + /** * Gets the number of rows in this table. - * + * * @return the number of rows in this table - */ + */ public int size() { return rows.size(); } - + /** * Gets the total height of the table. - * + * * @return the total height of the table - */ + */ public float getTotalHeight() { return totalHeight; } /** * Gets the height of a particular row. - * + * * @param idx the row index (starts at 0) * @return the height of a particular row - */ + */ public float getRowHeight(int idx) { - return getRowHeight(idx, false); + return getRowHeight(idx, false); } + /** * Gets the height of a particular row. - * - * @param idx the row index (starts at 0) - * @param firsttime is this the first time the row heigh is calculated? + * + * @param idx the row index (starts at 0) + * @param firsttime is this the first time the row heigh is calculated? * @return the height of a particular row - * @since 3.0.0 - */ + * @since 3.0.0 + */ public float getRowHeight(int idx, boolean firsttime) { if (totalWidth <= 0 || idx < 0 || idx >= rows.size()) return 0; - PdfPRow row = (PdfPRow)rows.get(idx); + PdfPRow row = (PdfPRow) rows.get(idx); if (row == null) return 0; if (firsttime) - row.setWidths(absoluteWidths); + row.setWidths(absoluteWidths); float height = row.getMaxHeights(); PdfPCell cell; PdfPRow tmprow; for (int i = 0; i < relativeWidths.length; i++) { - if(!rowSpanAbove(idx, i)) - continue; - int rs = 1; - while (rowSpanAbove(idx - rs, i)) { - rs++; - } - tmprow = (PdfPRow)rows.get(idx - rs); - cell = tmprow.getCells()[i]; - // @change null就不继续了,这个版本没考虑到rowSpan和colSpan都大于1的情况 - if (cell == null) break; - float tmp = 0; - if (cell.getRowspan() == rs + 1) { - tmp = cell.getMaxHeight(); - while (rs > 0) { - tmp -= getRowHeight(idx - rs); - rs--; - } - } - if (tmp > height) - height = tmp; + if (!rowSpanAbove(idx, i)) + continue; + int rs = 1; + while (rowSpanAbove(idx - rs, i)) { + rs++; + } + tmprow = (PdfPRow) rows.get(idx - rs); + cell = tmprow.getCells()[i]; + float tmp = 0; + if (cell.getRowspan() == rs + 1) { + tmp = cell.getMaxHeight(); + while (rs > 0) { + tmp -= getRowHeight(idx - rs); + rs--; + } + } + if (tmp > height) + height = tmp; } row.setMaxHeights(height); return height; @@ -883,96 +911,96 @@ public class PdfPTable implements LargeElement{ /** * Gets the maximum height of a cell in a particular row (will only be different * from getRowHeight is one of the cells in the row has a rowspan > 1). - * - * @param rowIndex the row index - * @param cellIndex the cell index + * * @return the height of a particular row including rowspan - * @since 2.1.6 - */ + * @param rowIndex the row index + * @param cellIndex the cell index + * @since 2.1.6 + */ public float getRowspanHeight(int rowIndex, int cellIndex) { if (totalWidth <= 0 || rowIndex < 0 || rowIndex >= rows.size()) return 0; - PdfPRow row = (PdfPRow)rows.get(rowIndex); + PdfPRow row = (PdfPRow) rows.get(rowIndex); if (row == null || cellIndex >= row.getCells().length) return 0; PdfPCell cell = row.getCells()[cellIndex]; if (cell == null) - return 0; + return 0; float rowspanHeight = 0; for (int j = 0; j < cell.getRowspan(); j++) { - rowspanHeight += getRowHeight(rowIndex + j); + rowspanHeight += getRowHeight(rowIndex + j); } return rowspanHeight; } - + /** * Gets the height of the rows that constitute the header as defined by * setHeaderRows(). - * + * * @return the height of the rows that constitute the header and footer - */ + */ public float getHeaderHeight() { float total = 0; int size = Math.min(rows.size(), headerRows); for (int k = 0; k < size; ++k) { - PdfPRow row = (PdfPRow)rows.get(k); + PdfPRow row = (PdfPRow) rows.get(k); if (row != null) total += row.getMaxHeights(); } return total; } - + /** * Gets the height of the rows that constitute the footer as defined by * setFooterRows(). - * + * * @return the height of the rows that constitute the footer * @since 2.1.1 - */ + */ public float getFooterHeight() { float total = 0; int start = Math.max(0, headerRows - footerRows); int size = Math.min(rows.size(), headerRows); for (int k = start; k < size; ++k) { - PdfPRow row = (PdfPRow)rows.get(k); + PdfPRow row = (PdfPRow) rows.get(k); if (row != null) total += row.getMaxHeights(); } return total; } - + /** * Deletes a row from the table. - * + * * @param rowNumber the row to be deleted * @return true if the row was deleted - */ + */ public boolean deleteRow(int rowNumber) { if (rowNumber < 0 || rowNumber >= rows.size()) return false; if (totalWidth > 0) { - PdfPRow row = (PdfPRow)rows.get(rowNumber); + PdfPRow row = (PdfPRow) rows.get(rowNumber); if (row != null) totalHeight -= row.getMaxHeights(); } rows.remove(rowNumber); if (rowNumber < headerRows) { - --headerRows; - if (rowNumber >= (headerRows - footerRows)) - --footerRows; + --headerRows; + if (rowNumber >= (headerRows - footerRows)) + --footerRows; } return true; } - + /** * Deletes the last row in the table. - * + * * @return true if the last row was deleted - */ + */ public boolean deleteLastRow() { return deleteRow(rows.size() - 1); } - + /** * Removes all of the rows except headers */ @@ -985,31 +1013,31 @@ public class PdfPTable implements LargeElement{ if (totalWidth > 0) totalHeight = getHeaderHeight(); } - + /** * Returns the number of columns. - * - * @return the number of columns. - * @since 2.1.1 + * + * @return the number of columns. + * @since 2.1.1 */ public int getNumberOfColumns() { - return relativeWidths.length; + return relativeWidths.length; } /** * Gets the number of the rows that constitute the header. - * + * * @return the number of the rows that constitute the header */ public int getHeaderRows() { return headerRows; } - + /** * Sets the number of the top rows that constitute the header. * This header has only meaning if the table is added to Document * and the table crosses pages. - * + * * @param headerRows the number of the top rows that constitute the header */ public void setHeaderRows(int headerRows) { @@ -1017,66 +1045,65 @@ public class PdfPTable implements LargeElement{ headerRows = 0; this.headerRows = headerRows; } - + /** * Gets all the chunks in this element. * - * @return an ArrayList + * @return an ArrayList */ public ArrayList getChunks() { return new ArrayList(); } - + /** * Gets the type of the text element. * - * @return a type + * @return a type */ public int type() { return Element.PTABLE; } - - /** - * @see com.fr.third.com.lowagie.text.Element#isContent() - * @since iText 2.0.8 - */ - public boolean isContent() { - return true; - } - - /** - * @see com.fr.third.com.lowagie.text.Element#isNestable() - * @since iText 2.0.8 - */ - public boolean isNestable() { - return true; - } - + + /** + * @since iText 2.0.8 + * @see Element#isContent() + */ + public boolean isContent() { + return true; + } + + /** + * @since iText 2.0.8 + * @see Element#isNestable() + */ + public boolean isNestable() { + return true; + } + /** * Processes the element by adding it (or the different parts) to an * ElementListener. * - * @param listener an ElementListener - * @return true if the element was processed successfully + * @param listener an ElementListener + * @return true if the element was processed successfully */ public boolean process(ElementListener listener) { try { return listener.add(this); - } - catch(DocumentException de) { + } catch (DocumentException de) { return false; } } - + /** * Gets the width percentage that the table will occupy in the page. - * + * * @return the width percentage that the table will occupy in the page */ public float getWidthPercentage() { return widthPercentage; } - + /** * Sets the width percentage that the table will occupy in the page. * @@ -1085,157 +1112,161 @@ public class PdfPTable implements LargeElement{ public void setWidthPercentage(float widthPercentage) { this.widthPercentage = widthPercentage; } - + /** * Gets the horizontal alignment of the table relative to the page. - * + * * @return the horizontal alignment of the table relative to the page */ public int getHorizontalAlignment() { return horizontalAlignment; } - + /** * Sets the horizontal alignment of the table relative to the page. * It only has meaning if the width percentage is less than 100%. * * @param horizontalAlignment the horizontal alignment of the table - * relative to the page + * relative to the page */ public void setHorizontalAlignment(int horizontalAlignment) { this.horizontalAlignment = horizontalAlignment; } - + /** * Gets a row with a given index * (added by Jin-Hsia Yang). - * + * * @param idx * @return the row at position idx */ public PdfPRow getRow(int idx) { - return (PdfPRow)rows.get(idx); + return (PdfPRow) rows.get(idx); } /** * Gets an arraylist with all the rows in the table. - * + * * @return an arraylist */ public ArrayList getRows() { return rows; } - + /** * Gets an arraylist with a selection of rows. - * @param start the first row in the selection - * @param end the first row that isn't part of the selection - * @return a selection of rows - * @since 2.1.6 + * + * @param start the first row in the selection + * @param end the first row that isn't part of the selection + * @return a selection of rows + * @since 2.1.6 */ public ArrayList getRows(int start, int end) { - ArrayList list = new ArrayList(); - if (start < 0 || end > size()) { - return list; - } - PdfPRow firstRow = adjustCellsInRow(start, end); - int colIndex = 0; - PdfPCell cell; - while (colIndex < getNumberOfColumns()) { - int rowIndex = start; - while (rowSpanAbove(rowIndex--, colIndex)) { - PdfPRow row = getRow(rowIndex); - if (row != null) { - PdfPCell replaceCell = row.getCells()[colIndex]; - if (replaceCell != null) { - firstRow.getCells()[colIndex] = new PdfPCell(replaceCell); - float extra = 0; - int stop = Math.min(rowIndex + replaceCell.getRowspan(), end); - for (int j = start + 1; j < stop; j++) { - extra += getRowHeight(j); - } - firstRow.setExtraHeight(colIndex, extra); - float diff = getRowspanHeight(rowIndex, colIndex) - - getRowHeight(start) - extra; - firstRow.getCells()[colIndex].consumeHeight(diff); - } - } - } - cell = firstRow.getCells()[colIndex]; - if (cell == null) - colIndex++; - else - colIndex += cell.getColspan(); - } - list.add(firstRow); - for (int i = start + 1; i < end; i++) { - list.add(adjustCellsInRow(i, end)); - } - return list; - } - + ArrayList list = new ArrayList(); + if (start < 0 || end > size()) { + return list; + } + PdfPRow firstRow = adjustCellsInRow(start, end); + int colIndex = 0; + PdfPCell cell; + while (colIndex < getNumberOfColumns()) { + int rowIndex = start; + while (rowSpanAbove(rowIndex--, colIndex)) { + PdfPRow row = getRow(rowIndex); + if (row != null) { + PdfPCell replaceCell = row.getCells()[colIndex]; + if (replaceCell != null) { + firstRow.getCells()[colIndex] = new PdfPCell(replaceCell); + float extra = 0; + int stop = Math.min(rowIndex + replaceCell.getRowspan(), end); + for (int j = start + 1; j < stop; j++) { + extra += getRowHeight(j); + } + firstRow.setExtraHeight(colIndex, extra); + float diff = getRowspanHeight(rowIndex, colIndex) + - getRowHeight(start) - extra; + firstRow.getCells()[colIndex].consumeHeight(diff); + } + } + } + cell = firstRow.getCells()[colIndex]; + if (cell == null) + colIndex++; + else + colIndex += cell.getColspan(); + } + list.add(firstRow); + for (int i = start + 1; i < end; i++) { + list.add(adjustCellsInRow(i, end)); + } + return list; + } + /** * Calculates the extra height needed in a row because of rowspans. - * @param start the index of the start row (the one to adjust) - * @param end the index of the end row on the page - * @since 2.1.6 + * + * @param start the index of the start row (the one to adjust) + * @param end the index of the end row on the page + * @since 2.1.6 */ protected PdfPRow adjustCellsInRow(int start, int end) { - PdfPRow row = new PdfPRow(getRow(start)); - row.initExtraHeights(); - PdfPCell cell; - PdfPCell[] cells = row.getCells(); - for (int i = 0; i < cells.length; i++) { - cell = cells[i]; - if (cell == null || cell.getRowspan() == 1) - continue; - int stop = Math.min(end, start + cell.getRowspan()); - float extra = 0; - for (int k = start + 1; k < stop; k++) { - extra += getRowHeight(k); - } - row.setExtraHeight(i, extra); - } - return row; - } - - /** Sets the table event for this table. + PdfPRow row = new PdfPRow(getRow(start)); + row.initExtraHeights(); + PdfPCell cell; + PdfPCell[] cells = row.getCells(); + for (int i = 0; i < cells.length; i++) { + cell = cells[i]; + if (cell == null || cell.getRowspan() == 1) + continue; + int stop = Math.min(end, start + cell.getRowspan()); + float extra = 0; + for (int k = start + 1; k < stop; k++) { + extra += getRowHeight(k); + } + row.setExtraHeight(i, extra); + } + return row; + } + + /** + * Sets the table event for this table. + * * @param event the table event for this table - */ + */ public void setTableEvent(PdfPTableEvent event) { - if (event == null) - this.tableEvent = null; - else if (this.tableEvent == null) - this.tableEvent = event; - else if (this.tableEvent instanceof PdfPTableEventForwarder) - ((PdfPTableEventForwarder)this.tableEvent).addTableEvent(event); - else { - PdfPTableEventForwarder forward = new PdfPTableEventForwarder(); - forward.addTableEvent(this.tableEvent); - forward.addTableEvent(event); - this.tableEvent = forward; - } - } - + if (event == null) + this.tableEvent = null; + else if (this.tableEvent == null) + this.tableEvent = event; + else if (this.tableEvent instanceof PdfPTableEventForwarder) + ((PdfPTableEventForwarder) this.tableEvent).addTableEvent(event); + else { + PdfPTableEventForwarder forward = new PdfPTableEventForwarder(); + forward.addTableEvent(this.tableEvent); + forward.addTableEvent(event); + this.tableEvent = forward; + } + } + /** * Gets the table event for this page. - * + * * @return the table event for this page - */ + */ public PdfPTableEvent getTableEvent() { return tableEvent; } - + /** * Gets the absolute sizes of each column width. - * + * * @return he absolute sizes of each column width - */ + */ public float[] getAbsoluteWidths() { return absoluteWidths; } - - float [][] getEventWidths(float xPos, int firstRow, int lastRow, boolean includeHeaders) { + + float[][] getEventWidths(float xPos, int firstRow, int lastRow, boolean includeHeaders) { if (includeHeaders) { firstRow = Math.max(firstRow, headerRows); lastRow = Math.max(lastRow, headerRows); @@ -1245,7 +1276,7 @@ public class PdfPTable implements LargeElement{ int n = 0; if (includeHeaders) { for (int k = 0; k < headerRows; ++k) { - PdfPRow row = (PdfPRow)rows.get(k); + PdfPRow row = (PdfPRow) rows.get(k); if (row == null) ++n; else @@ -1253,15 +1284,14 @@ public class PdfPTable implements LargeElement{ } } for (; firstRow < lastRow; ++firstRow) { - PdfPRow row = (PdfPRow)rows.get(firstRow); - if (row == null) - ++n; - else - widths[n++] = row.getEventWidth(xPos); + PdfPRow row = (PdfPRow) rows.get(firstRow); + if (row == null) + ++n; + else + widths[n++] = row.getEventWidth(xPos); } - } - else { - int numCols = getNumberOfColumns(); + } else { + int numCols = getNumberOfColumns(); float width[] = new float[numCols + 1]; width[0] = xPos; for (int k = 0; k < numCols; ++k) @@ -1276,7 +1306,7 @@ public class PdfPTable implements LargeElement{ /** * Tells you if the first header needs to be skipped * (for instance if the header says "continued from the previous page"). - * + * * @return Value of property skipFirstHeader. */ public boolean isSkipFirstHeader() { @@ -1287,30 +1317,30 @@ public class PdfPTable implements LargeElement{ /** * Tells you if the last footer needs to be skipped * (for instance if the footer says "continued on the next page") - * + * * @return Value of property skipLastFooter. - * @since 2.1.6 + * @since 2.1.6 */ public boolean isSkipLastFooter() { return skipLastFooter; } - + /** * Skips the printing of the first header. Used when printing * tables in succession belonging to the same printed table aspect. - * + * * @param skipFirstHeader New value of property skipFirstHeader. */ public void setSkipFirstHeader(boolean skipFirstHeader) { this.skipFirstHeader = skipFirstHeader; } - + /** * Skips the printing of the last footer. Used when printing * tables in succession belonging to the same printed table aspect. - * + * * @param skipLastFooter New value of property skipLastFooter. - * @since 2.1.6 + * @since 2.1.6 */ public void setSkipLastFooter(boolean skipLastFooter) { this.skipLastFooter = skipLastFooter; @@ -1318,27 +1348,27 @@ public class PdfPTable implements LargeElement{ /** * Sets the run direction of the contents of the table. - * + * * @param runDirection One of the following values: - * PdfWriter.RUN_DIRECTION_DEFAULT, PdfWriter.RUN_DIRECTION_NO_BIDI, - * PdfWriter.RUN_DIRECTION_LTR or PdfWriter.RUN_DIRECTION_RTL. + * PdfWriter.RUN_DIRECTION_DEFAULT, PdfWriter.RUN_DIRECTION_NO_BIDI, + * PdfWriter.RUN_DIRECTION_LTR or PdfWriter.RUN_DIRECTION_RTL. */ public void setRunDirection(int runDirection) { switch (runDirection) { - case PdfWriter.RUN_DIRECTION_DEFAULT: - case PdfWriter.RUN_DIRECTION_NO_BIDI: - case PdfWriter.RUN_DIRECTION_LTR: - case PdfWriter.RUN_DIRECTION_RTL: - this.runDirection = runDirection; - break; - default: - throw new RuntimeException("Invalid run direction: " + runDirection); + case PdfWriter.RUN_DIRECTION_DEFAULT: + case PdfWriter.RUN_DIRECTION_NO_BIDI: + case PdfWriter.RUN_DIRECTION_LTR: + case PdfWriter.RUN_DIRECTION_RTL: + this.runDirection = runDirection; + break; + default: + throw new RuntimeException("Invalid run direction: " + runDirection); } } - + /** * Returns the run direction of the contents in the table. - * + * * @return One of the following values: * PdfWriter.RUN_DIRECTION_DEFAULT, PdfWriter.RUN_DIRECTION_NO_BIDI, * PdfWriter.RUN_DIRECTION_LTR or PdfWriter.RUN_DIRECTION_RTL. @@ -1346,140 +1376,140 @@ public class PdfPTable implements LargeElement{ public int getRunDirection() { return runDirection; } - + /** * Getter for property lockedWidth. - * + * * @return Value of property lockedWidth. */ public boolean isLockedWidth() { return this.lockedWidth; } - + /** * Uses the value in setTotalWidth() in Document.add(). - * + * * @param lockedWidth true to use the value in setTotalWidth() in Document.add() */ public void setLockedWidth(boolean lockedWidth) { this.lockedWidth = lockedWidth; } - + /** * Gets the split value. - * + * * @return true to split; false otherwise */ public boolean isSplitRows() { return this.splitRows; } - + /** - * When set the rows that won't fit in the page will be split. + * When set the rows that won't fit in the page will be split. * Note that it takes at least twice the memory to handle a split table row * than a normal table. true by default. - * + * * @param splitRows true to split; false otherwise */ public void setSplitRows(boolean splitRows) { this.splitRows = splitRows; } - + /** * Sets the spacing before this table. * - * @param spacing the new spacing + * @param spacing the new spacing */ public void setSpacingBefore(float spacing) { this.spacingBefore = spacing; } - + /** * Sets the spacing after this table. * - * @param spacing the new spacing + * @param spacing the new spacing */ public void setSpacingAfter(float spacing) { this.spacingAfter = spacing; - } + } /** * Gets the spacing before this table. * - * @return the spacing + * @return the spacing */ public float spacingBefore() { return spacingBefore; } - + /** * Gets the spacing after this table. * - * @return the spacing + * @return the spacing */ public float spacingAfter() { return spacingAfter; - } - + } + /** * Gets the value of the last row extension. - * + * * @return true if the last row will extend; false otherwise */ public boolean isExtendLastRow() { return extendLastRow; } - + /** * When set the last row will be extended to fill all the remaining space * to the bottom boundary. - * + * * @param extendLastRow true to extend the last row; false otherwise */ public void setExtendLastRow(boolean extendLastRow) { this.extendLastRow = extendLastRow; } - + /** * Gets the header status inclusion in PdfPTableEvent. - * + * * @return true if the headers are included; false otherwise */ public boolean isHeadersInEvent() { return headersInEvent; } - + /** * When set the PdfPTableEvent will include the headers. - * + * * @param headersInEvent true to include the headers; false otherwise */ public void setHeadersInEvent(boolean headersInEvent) { this.headersInEvent = headersInEvent; } - + /** * Gets the property splitLate. - * + * * @return the property splitLate */ public boolean isSplitLate() { return splitLate; } - + /** * If true the row will only split if it's the first one in an empty page. * It's true by default. * It's only meaningful if setSplitRows(true). - * + * * @param splitLate the property value */ public void setSplitLate(boolean splitLate) { this.splitLate = splitLate; } - + /** - * If true the table will be kept on one page if it fits, by forcing a + * If true the table will be kept on one page if it fits, by forcing a * new page if it doesn't fit on the current page. The default is to * split the table over multiple pages. * @@ -1488,26 +1518,26 @@ public class PdfPTable implements LargeElement{ public void setKeepTogether(boolean keepTogether) { this.keepTogether = keepTogether; } - + /** * Getter for property keepTogether - * + * * @return true if it is tried to keep the table on one page; * false otherwise */ public boolean getKeepTogether() { return keepTogether; } - + /** * Gets the number of rows in the footer. - * + * * @return the number of rows in the footer */ public int getFooterRows() { return this.footerRows; } - + /** * Sets the number of rows to be used for the footer. The number * of footer rows are subtracted from the header rows. For @@ -1518,7 +1548,7 @@ public class PdfPTable implements LargeElement{ * table.setFooterRows(1); * * Row 0 and 1 will be the header rows and row 2 will be the footer row. - * + * * @param footerRows the number of rows to be used for the footer */ public void setFooterRows(int footerRows) { @@ -1526,7 +1556,7 @@ public class PdfPTable implements LargeElement{ footerRows = 0; this.footerRows = footerRows; } - + /** * Completes the current row with the default cell. An incomplete row will * be dropped but calling this method will make sure that it will be @@ -1537,29 +1567,31 @@ public class PdfPTable implements LargeElement{ addCell(defaultCell); } } - - /** - * @since iText 2.0.8 - * @see com.fr.third.com.lowagie.text.LargeElement#flushContent() - */ - public void flushContent() { - deleteBodyRows(); - setSkipFirstHeader(true); - } - - /** - * @since iText 2.0.8 - * @see com.fr.third.com.lowagie.text.LargeElement#isComplete() - */ - public boolean isComplete() { - return complete; - } - - /** - * @since iText 2.0.8 - * @see com.fr.third.com.lowagie.text.LargeElement#setComplete(boolean) - */ - public void setComplete(boolean complete) { - this.complete = complete; - } + + /** + * @since iText 2.0.8 + * @see LargeElement#flushContent() + */ + public void flushContent() { + deleteBodyRows(); + setSkipFirstHeader(true); + } + + /** + * @since iText 2.0.8 + * @see LargeElement#isComplete() + */ + public boolean isComplete() { + return complete; + } + + /** + * @since iText 2.0.8 + * @see LargeElement#setComplete(boolean) + */ + public void setComplete(boolean complete) { + this.complete = complete; + } + + } \ No newline at end of file diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/TableProperties.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/pdf/TableProperties.java new file mode 100644 index 000000000..4bcef11c8 --- /dev/null +++ b/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鐨勫睘鎬х被 + * 鍖呮嫭cellspacing銆乧ellpadding銆乥order绛 + */ +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(); + } +} diff --git a/fine-itext-old/src/com/fr/third/com/lowagie/text/rtf/text/RtfChunk.java b/fine-itext-old/src/com/fr/third/com/lowagie/text/rtf/text/RtfChunk.java index a9edc3e78..09903083a 100755 --- a/fine-itext-old/src/com/fr/third/com/lowagie/text/rtf/text/RtfChunk.java +++ b/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.style.RtfColor; 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(); } 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()); content = chunk.getContent();