From 5ec179464d44850bb52c474ede389376084e7986 Mon Sep 17 00:00:00 2001 From: William Victor Mote Date: Mon, 30 Jun 2003 00:20:09 +0000 Subject: [PATCH] Convert all tab characters to spaces to comply with style requirements. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196541 13f79535-47bb-0310-9956-ffa450edef68 --- .../rtflib/rtfdoc/IRtfBookmarkContainer.java | 20 +- .../rtfdoc/IRtfExternalGraphicContainer.java | 12 +- .../rtflib/rtfdoc/IRtfHyperLinkContainer.java | 12 +- .../rtflib/rtfdoc/IRtfJforCmdContainer.java | 2 +- .../fop/rtf/rtflib/rtfdoc/IRtfOptions.java | 20 +- .../rtf/rtflib/rtfdoc/IRtfTableContainer.java | 4 +- .../rtf/rtflib/rtfdoc/ITableAttributes.java | 18 +- .../rtflib/rtfdoc/IrtfTemplateContainer.java | 12 +- .../rtfdoc/ParagraphKeeptogetherContext.java | 76 +- .../fop/rtf/rtflib/rtfdoc/RtfBookmark.java | 256 ++-- .../rtfdoc/RtfBookmarkContainerImpl.java | 112 +- .../fop/rtf/rtflib/rtfdoc/RtfColorTable.java | 374 +++--- .../rtf/rtflib/rtfdoc/RtfExternalGraphic.java | 1032 ++++++++--------- .../apache/fop/rtf/rtflib/rtfdoc/RtfFile.java | 278 ++--- .../fop/rtf/rtflib/rtfdoc/RtfFontManager.java | 290 ++--- .../fop/rtf/rtflib/rtfdoc/RtfFontTable.java | 20 +- .../fop/rtf/rtflib/rtfdoc/RtfHeader.java | 6 +- .../fop/rtf/rtflib/rtfdoc/RtfHyperLink.java | 320 ++--- .../fop/rtf/rtflib/rtfdoc/RtfJforCmd.java | 54 +- .../fop/rtf/rtflib/rtfdoc/RtfListItem.java | 10 +- .../fop/rtf/rtflib/rtfdoc/RtfListTable.java | 12 +- .../apache/fop/rtf/rtflib/rtfdoc/RtfNull.java | 6 +- .../apache/fop/rtf/rtflib/rtfdoc/RtfPage.java | 70 +- .../fop/rtf/rtflib/rtfdoc/RtfPageArea.java | 10 +- .../fop/rtf/rtflib/rtfdoc/RtfPageNumber.java | 14 +- .../rtflib/rtfdoc/RtfPageNumberCitation.java | 16 +- .../fop/rtf/rtflib/rtfdoc/RtfParagraph.java | 12 +- .../rtfdoc/RtfParagraphKeepTogether.java | 54 +- .../fop/rtf/rtflib/rtfdoc/RtfSection.java | 222 ++-- .../rtf/rtflib/rtfdoc/RtfStyleSheetTable.java | 430 +++---- .../fop/rtf/rtflib/rtfdoc/RtfTable.java | 10 +- .../fop/rtf/rtflib/rtfdoc/RtfTableCell.java | 38 +- .../fop/rtf/rtflib/rtfdoc/RtfTemplate.java | 122 +- .../apache/fop/rtf/rtflib/rtfdoc/RtfText.java | 402 +++---- .../fop/rtf/rtflib/testdocs/BasicLink.java | 72 +- .../rtflib/testdocs/CreateTestDocuments.java | 102 +- .../rtf/rtflib/testdocs/ExternalGraphic.java | 132 +-- .../rtflib/testdocs/ParagraphAlignment.java | 56 +- .../fop/rtf/rtflib/tools/ImageConstants.java | 100 +- .../fop/rtf/rtflib/tools/ImageUtil.java | 378 +++--- 40 files changed, 2592 insertions(+), 2594 deletions(-) diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfBookmarkContainer.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfBookmarkContainer.java index eb0533b15..e5c69afc0 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfBookmarkContainer.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfBookmarkContainer.java @@ -67,15 +67,15 @@ import java.io.IOException; public interface IRtfBookmarkContainer { - /** - * Create a new RTF bookmark. - * - * @param bookmark Name of the bookmark - * - * @return RTF bookmark - * - * @throws IOException On eror - */ - RtfBookmark newBookmark (String bookmark) throws IOException; + /** + * Create a new RTF bookmark. + * + * @param bookmark Name of the bookmark + * + * @return RTF bookmark + * + * @throws IOException On eror + */ + RtfBookmark newBookmark (String bookmark) throws IOException; } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfExternalGraphicContainer.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfExternalGraphicContainer.java index e9085c5a0..6f6eb0c9d 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfExternalGraphicContainer.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfExternalGraphicContainer.java @@ -63,10 +63,10 @@ import java.io.IOException; public interface IRtfExternalGraphicContainer { - /** - * Creates a new image on external graphic base. - * - * @exception IOException On error - */ - RtfExternalGraphic newImage () throws IOException; + /** + * Creates a new image on external graphic base. + * + * @exception IOException On error + */ + RtfExternalGraphic newImage () throws IOException; } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfHyperLinkContainer.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfHyperLinkContainer.java index 815284445..835cd3620 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfHyperLinkContainer.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfHyperLinkContainer.java @@ -65,10 +65,10 @@ import java.io.IOException; */ public interface IRtfHyperLinkContainer extends IRtfTextContainer { - /** - * Creates a new hyperlink. - * - * @exception IOException on error - */ - public RtfHyperLink newHyperLink (String str, RtfAttributes attr) throws IOException; + /** + * Creates a new hyperlink. + * + * @exception IOException on error + */ + public RtfHyperLink newHyperLink (String str, RtfAttributes attr) throws IOException; } \ No newline at end of file diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfJforCmdContainer.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfJforCmdContainer.java index 073d83bf2..9d7e4d1f3 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfJforCmdContainer.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfJforCmdContainer.java @@ -62,5 +62,5 @@ package org.apache.fop.rtf.rtflib.rtfdoc; import java.io.IOException; public interface IRtfJforCmdContainer { - public RtfJforCmd newJforCmd(RtfAttributes attr) throws IOException; + public RtfJforCmd newJforCmd(RtfAttributes attr) throws IOException; } \ No newline at end of file diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfOptions.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfOptions.java index 3769483d4..d97c5766a 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfOptions.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfOptions.java @@ -63,15 +63,15 @@ package org.apache.fop.rtf.rtflib.rtfdoc; */ public interface IRtfOptions { - /** - * Sets the compression rate for the external graphic in percent. - * @param percent Compression rate - */ - public void setRtfExternalGraphicCompressionRate (int percent); + /** + * Sets the compression rate for the external graphic in percent. + * @param percent Compression rate + */ + public void setRtfExternalGraphicCompressionRate (int percent); - /** - * Gets the compression rate for the external graphic in percent. - * @return Compression rate - */ - public int getRtfExternalGraphicCompressionRate (); + /** + * Gets the compression rate for the external graphic in percent. + * @return Compression rate + */ + public int getRtfExternalGraphicCompressionRate (); } \ No newline at end of file diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfTableContainer.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfTableContainer.java index b8d31065d..ae7a0033d 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfTableContainer.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IRtfTableContainer.java @@ -70,8 +70,8 @@ public interface IRtfTableContainer /** close current table if any and start a new one */ public RtfTable newTable(ITableColumnsInfo tc) throws IOException; - /** close current table if any and start a new one + /** close current table if any and start a new one * @param tc added by Boris Poudérous on july 2002 in order to process number-columns-spanned attribute **/ - public RtfTable newTable(RtfAttributes attrs, ITableColumnsInfo tc) throws IOException; + public RtfTable newTable(RtfAttributes attrs, ITableColumnsInfo tc) throws IOException; } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/ITableAttributes.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/ITableAttributes.java index 389bda86f..a2ebc363a 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/ITableAttributes.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/ITableAttributes.java @@ -122,12 +122,12 @@ public interface ITableAttributes { String ROW_KEEP_TOGETHER = "trkeep"; //This control word is nonexistent in RTF, used - //to simulate the FO:keep-with-next attribute. + //to simulate the FO:keep-with-next attribute. String ROW_KEEP_WITH_NEXT = "knext"; - //This control word is nonexistent in RTF, used - //to simulate the FO:keep-with-previous attribute. - String ROW_KEEP_WITH_PREVIOUS = "kprevious"; + //This control word is nonexistent in RTF, used + //to simulate the FO:keep-with-previous attribute. + String ROW_KEEP_WITH_PREVIOUS = "kprevious"; //shading and color, all are unit based attributes String CELL_SHADE = "clshdng"; @@ -144,16 +144,16 @@ public interface ITableAttributes { }; String[] CELL_BORDER = { - CELL_BORDER_TOP, CELL_BORDER_BOTTOM, - CELL_BORDER_LEFT, CELL_BORDER_RIGHT + CELL_BORDER_TOP, CELL_BORDER_BOTTOM, + CELL_BORDER_LEFT, CELL_BORDER_RIGHT }; String[] ROW_BORDER = { - ROW_BORDER_TOP, ROW_BORDER_BOTTOM, ROW_BORDER_LEFT, - ROW_BORDER_RIGHT, ROW_BORDER_HORIZONTAL, ROW_BORDER_VERTICAL + ROW_BORDER_TOP, ROW_BORDER_BOTTOM, ROW_BORDER_LEFT, + ROW_BORDER_RIGHT, ROW_BORDER_HORIZONTAL, ROW_BORDER_VERTICAL }; String[] CELL_COLOR = { - CELL_SHADE, CELL_COLOR_BACKGROUND, CELL_COLOR_FOREGROUND + CELL_SHADE, CELL_COLOR_BACKGROUND, CELL_COLOR_FOREGROUND }; } \ No newline at end of file diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IrtfTemplateContainer.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IrtfTemplateContainer.java index b8f8f2bca..cd5684afa 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IrtfTemplateContainer.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/IrtfTemplateContainer.java @@ -63,12 +63,12 @@ import java.io.IOException; public interface IrtfTemplateContainer { - /** - * Creates a new Template. - * - * @exception IOException on error - */ - public RtfTemplate newTemplate (String str, RtfAttributes attr) throws IOException; + /** + * Creates a new Template. + * + * @exception IOException on error + */ + public RtfTemplate newTemplate (String str, RtfAttributes attr) throws IOException; } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/ParagraphKeeptogetherContext.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/ParagraphKeeptogetherContext.java index b5088fa0a..2abc9c664 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/ParagraphKeeptogetherContext.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/ParagraphKeeptogetherContext.java @@ -60,7 +60,7 @@ package org.apache.fop.rtf.rtflib.rtfdoc; /** * - * This context is used to manage the "keepn" RTF attribute + * This context is used to manage the "keepn" RTF attribute * Used by ParagraphBuilder and JforCmd * */ @@ -69,51 +69,51 @@ public class ParagraphKeeptogetherContext { private static int m_paraKeepTogetherOpen=0; private static boolean m_paraResetProperties=false; - private static ParagraphKeeptogetherContext m_instance = null; + private static ParagraphKeeptogetherContext m_instance = null; - ParagraphKeeptogetherContext() { - } + ParagraphKeeptogetherContext() { + } - /** - * Singelton. - * - * @return The instance of ParagraphKeeptogetherContext - */ - public static ParagraphKeeptogetherContext getInstance() { - if (m_instance==null) m_instance = new ParagraphKeeptogetherContext(); - return m_instance; - } + /** + * Singelton. + * + * @return The instance of ParagraphKeeptogetherContext + */ + public static ParagraphKeeptogetherContext getInstance() { + if (m_instance==null) m_instance = new ParagraphKeeptogetherContext(); + return m_instance; + } - /** Return the level of current "keep whith next" paragraph */ - public static int getKeepTogetherOpenValue() { - return m_paraKeepTogetherOpen; - } + /** Return the level of current "keep whith next" paragraph */ + public static int getKeepTogetherOpenValue() { + return m_paraKeepTogetherOpen; + } - /** Open a new "keep whith next" paragraph */ - public static void KeepTogetherOpen() { - m_paraKeepTogetherOpen++; - } + /** Open a new "keep whith next" paragraph */ + public static void KeepTogetherOpen() { + m_paraKeepTogetherOpen++; + } - /** Close a "keep whith next" paragraph */ - public static void KeepTogetherClose() { - if(m_paraKeepTogetherOpen > 0) { - m_paraKeepTogetherOpen--; + /** Close a "keep whith next" paragraph */ + public static void KeepTogetherClose() { + if(m_paraKeepTogetherOpen > 0) { + m_paraKeepTogetherOpen--; - //If the \pard control word is not present, the current paragraph inherits all paragraph properties. - //Also the next paragraph must reset the properties otherwise the \keepn don't stop. - m_paraResetProperties= (m_paraKeepTogetherOpen==0); - } - } + //If the \pard control word is not present, the current paragraph inherits all paragraph properties. + //Also the next paragraph must reset the properties otherwise the \keepn don't stop. + m_paraResetProperties= (m_paraKeepTogetherOpen==0); + } + } - /** Determine if the next paragraph must reset the properites */ - public static boolean paragraphResetProperties() { - return m_paraResetProperties; - } + /** Determine if the next paragraph must reset the properites */ + public static boolean paragraphResetProperties() { + return m_paraResetProperties; + } - /** Reset the flag if the paragraph properties have been resested */ - public static void setParagraphResetPropertiesUsed() { - m_paraResetProperties=false; - } + /** Reset the flag if the paragraph properties have been resested */ + public static void setParagraphResetPropertiesUsed() { + m_paraResetProperties=false; + } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBookmark.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBookmark.java index 6ee287b5a..9ffc08188 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBookmark.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBookmark.java @@ -69,132 +69,132 @@ import java.io.IOException; */ public class RtfBookmark extends RtfElement { - ////////////////////////////////////////////////// - // @@ Members - ////////////////////////////////////////////////// - - /** Name of the bokkmark */ - private String bookmark = null; - /** Word 2000 supports a length of 40 characters only */ - public static int maxBookmarkLength = 40; - /** Word 2000 converts '.' in bookmarks to "_", thats why we control this replacement. */ - public static char replaceCharacter = '_'; - - - ////////////////////////////////////////////////// - // @@ Construction - ////////////////////////////////////////////////// - - /** - * Constructor. - * - * @param parent a RtfBookmarkContainer value - * @param writer a Writer value - * @param bookmark Name of the bookmark - */ - RtfBookmark (IRtfBookmarkContainer parent, Writer w, String bookmark) throws IOException - { - super ((RtfContainer) parent, w); - - int now = bookmark.length (); - - this.bookmark = bookmark.substring (0, now < maxBookmarkLength ? now : maxBookmarkLength); - this.bookmark = this.bookmark.replace ('.',replaceCharacter); - this.bookmark = this.bookmark.replace (' ',replaceCharacter); - } - - - ////////////////////////////////////////////////// - // @@ RtfElement implementation - ////////////////////////////////////////////////// - - /** - * Is called before writing the Rtf content. - * - * @throws IOException On Error - */ - public void writeRtfPrefix () throws IOException - { - startBookmark (); - } - - /** - * Writes the RTF content to m_writer. - * - * @exception IOException On error - */ - public void writeRtfContent () throws IOException - { -// this.getRtfFile ().getLog ().logInfo ("Write bookmark '" + bookmark + "'."); - // No content to write - } - - /** - * Is called after writing the Rtf content. - * - * @throws IOException On Error - */ - public void writeRtfSuffix () throws IOException - { - endBookmark (); - } - - - ////////////////////////////////////////////////// - // @@ Private methods - ////////////////////////////////////////////////// - - /** - * Writes RTF content to begin the bookmark. - * - * @throws IOException On error - */ - private void startBookmark () throws IOException - { - - // {\*\bkmkstart test} - writeRtfBookmark ("bkmkstart"); - } - - /** - * Writes RTF content to close the bookmark. - * - * @throws IOException On error - */ - private void endBookmark () throws IOException - { - - // {\*\bkmkend test} - writeRtfBookmark ("bkmkend"); - } - - /** - * Writes the rtf bookmark. - * - * @param tag Begin or close tag - * - * @throws IOException On error - */ - private void writeRtfBookmark (String tag) throws IOException - { - if (bookmark == null) - { - return; - - } - - this.writeGroupMark (true); - - //changed. Now using writeStarControlWord - this.writeStarControlWord (tag); - - m_writer.write (bookmark); - this.writeGroupMark (false); - } - - /** true if this element would generate no "useful" RTF content */ - public boolean isEmpty() - { - return bookmark==null || bookmark.trim().length() == 0; - } + ////////////////////////////////////////////////// + // @@ Members + ////////////////////////////////////////////////// + + /** Name of the bokkmark */ + private String bookmark = null; + /** Word 2000 supports a length of 40 characters only */ + public static int maxBookmarkLength = 40; + /** Word 2000 converts '.' in bookmarks to "_", thats why we control this replacement. */ + public static char replaceCharacter = '_'; + + + ////////////////////////////////////////////////// + // @@ Construction + ////////////////////////////////////////////////// + + /** + * Constructor. + * + * @param parent a RtfBookmarkContainer value + * @param writer a Writer value + * @param bookmark Name of the bookmark + */ + RtfBookmark (IRtfBookmarkContainer parent, Writer w, String bookmark) throws IOException + { + super ((RtfContainer) parent, w); + + int now = bookmark.length (); + + this.bookmark = bookmark.substring (0, now < maxBookmarkLength ? now : maxBookmarkLength); + this.bookmark = this.bookmark.replace ('.',replaceCharacter); + this.bookmark = this.bookmark.replace (' ',replaceCharacter); + } + + + ////////////////////////////////////////////////// + // @@ RtfElement implementation + ////////////////////////////////////////////////// + + /** + * Is called before writing the Rtf content. + * + * @throws IOException On Error + */ + public void writeRtfPrefix () throws IOException + { + startBookmark (); + } + + /** + * Writes the RTF content to m_writer. + * + * @exception IOException On error + */ + public void writeRtfContent () throws IOException + { +// this.getRtfFile ().getLog ().logInfo ("Write bookmark '" + bookmark + "'."); + // No content to write + } + + /** + * Is called after writing the Rtf content. + * + * @throws IOException On Error + */ + public void writeRtfSuffix () throws IOException + { + endBookmark (); + } + + + ////////////////////////////////////////////////// + // @@ Private methods + ////////////////////////////////////////////////// + + /** + * Writes RTF content to begin the bookmark. + * + * @throws IOException On error + */ + private void startBookmark () throws IOException + { + + // {\*\bkmkstart test} + writeRtfBookmark ("bkmkstart"); + } + + /** + * Writes RTF content to close the bookmark. + * + * @throws IOException On error + */ + private void endBookmark () throws IOException + { + + // {\*\bkmkend test} + writeRtfBookmark ("bkmkend"); + } + + /** + * Writes the rtf bookmark. + * + * @param tag Begin or close tag + * + * @throws IOException On error + */ + private void writeRtfBookmark (String tag) throws IOException + { + if (bookmark == null) + { + return; + + } + + this.writeGroupMark (true); + + //changed. Now using writeStarControlWord + this.writeStarControlWord (tag); + + m_writer.write (bookmark); + this.writeGroupMark (false); + } + + /** true if this element would generate no "useful" RTF content */ + public boolean isEmpty() + { + return bookmark==null || bookmark.trim().length() == 0; + } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBookmarkContainerImpl.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBookmarkContainerImpl.java index 5e052122a..32acde52f 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBookmarkContainerImpl.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBookmarkContainerImpl.java @@ -69,70 +69,70 @@ import java.io.IOException; */ public class RtfBookmarkContainerImpl extends RtfContainer implements IRtfBookmarkContainer { - ////////////////////////////////////////////////// - // @@ Members - ////////////////////////////////////////////////// + ////////////////////////////////////////////////// + // @@ Members + ////////////////////////////////////////////////// - /** Rtf bookmark */ - RtfBookmark mBookmark = null; + /** Rtf bookmark */ + RtfBookmark mBookmark = null; - ////////////////////////////////////////////////// - // @@ Construction - ////////////////////////////////////////////////// + ////////////////////////////////////////////////// + // @@ Construction + ////////////////////////////////////////////////// - /** - * Constructor. - * Create an RTF container as a child of given container. - * - * @param parent The parent container - * @param w Writer - * - * @exception IOException On error - */ - RtfBookmarkContainerImpl (RtfContainer parent, Writer w) throws IOException - { - super (parent, w, null); - } + /** + * Constructor. + * Create an RTF container as a child of given container. + * + * @param parent The parent container + * @param w Writer + * + * @exception IOException On error + */ + RtfBookmarkContainerImpl (RtfContainer parent, Writer w) throws IOException + { + super (parent, w, null); + } - /** - * Constructor. - * Create an RTF container as a child of given container. - * - * @param parent The parent container - * @param w Writer - * @param attr Rtf attributes - * - * @exception IOException On error - */ - RtfBookmarkContainerImpl (RtfContainer parent, Writer w, RtfAttributes attr) throws IOException - { - super (parent, w, attr); - } + /** + * Constructor. + * Create an RTF container as a child of given container. + * + * @param parent The parent container + * @param w Writer + * @param attr Rtf attributes + * + * @exception IOException On error + */ + RtfBookmarkContainerImpl (RtfContainer parent, Writer w, RtfAttributes attr) throws IOException + { + super (parent, w, attr); + } - ////////////////////////////////////////////////// - // @@ Public methods - ////////////////////////////////////////////////// + ////////////////////////////////////////////////// + // @@ Public methods + ////////////////////////////////////////////////// - /** - * Create a new RTF bookmark. - * - * @param bookmark Name of the bookmark - * - * @return RTF bookmark - * - * @throws IOException On eror - */ - public RtfBookmark newBookmark (String bookmark) throws IOException - { - if (mBookmark != null) - { - mBookmark.close (); - } + /** + * Create a new RTF bookmark. + * + * @param bookmark Name of the bookmark + * + * @return RTF bookmark + * + * @throws IOException On eror + */ + public RtfBookmark newBookmark (String bookmark) throws IOException + { + if (mBookmark != null) + { + mBookmark.close (); + } - mBookmark = new RtfBookmark (this, m_writer, bookmark); + mBookmark = new RtfBookmark (this, m_writer, bookmark); - return mBookmark; - } + return mBookmark; + } } \ No newline at end of file diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfColorTable.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfColorTable.java index 5ef99f4bb..9caae552a 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfColorTable.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfColorTable.java @@ -71,95 +71,95 @@ import java.io.IOException; public class RtfColorTable { - ////////////////////////////////////////////////// - // @@ Symbolic constants - ////////////////////////////////////////////////// + ////////////////////////////////////////////////// + // @@ Symbolic constants + ////////////////////////////////////////////////// - // Defines the bit moving for the colors - private static int RED = 16; - private static int GREEN = 8; - private static int BLUE = 0; + // Defines the bit moving for the colors + private static int RED = 16; + private static int GREEN = 8; + private static int BLUE = 0; - ////////////////////////////////////////////////// - // @@ Members - ////////////////////////////////////////////////// + ////////////////////////////////////////////////// + // @@ Members + ////////////////////////////////////////////////// - /** Singelton instance */ - private static RtfColorTable instance = null; + /** Singelton instance */ + private static RtfColorTable instance = null; - /** Index table for the colors */ - private Hashtable colorIndex = null; - /** Used colors to this vector */ - private Vector colorTable = null; + /** Index table for the colors */ + private Hashtable colorIndex = null; + /** Used colors to this vector */ + private Vector colorTable = null; /** Map of color names to color numbers */ private Hashtable namedColors = null; - ////////////////////////////////////////////////// - // @@ Construction - ////////////////////////////////////////////////// + ////////////////////////////////////////////////// + // @@ Construction + ////////////////////////////////////////////////// - /** - * Constructor. - */ - private RtfColorTable () - { - colorTable = new Vector (); - colorIndex = new Hashtable (); + /** + * Constructor. + */ + private RtfColorTable () + { + colorTable = new Vector (); + colorIndex = new Hashtable (); namedColors = new Hashtable (); - init (); - } - - /** - * Singelton. - * - * @return The instance of RTFColorTable - */ - public static RtfColorTable getInstance () - { - if (instance == null) - { - instance = new RtfColorTable (); - } - - return instance; - } - - - ////////////////////////////////////////////////// - // @@ Initializing - ////////////////////////////////////////////////// - - /** - * Initialize the color table. - */ - private void init () - { - addNamedColor("black",getColorNumber (0, 0, 0)); - addNamedColor("white",getColorNumber (255, 255, 255)); - addNamedColor("red",getColorNumber (255, 0, 0)); - addNamedColor("green",getColorNumber (0, 255, 0)); + init (); + } + + /** + * Singelton. + * + * @return The instance of RTFColorTable + */ + public static RtfColorTable getInstance () + { + if (instance == null) + { + instance = new RtfColorTable (); + } + + return instance; + } + + + ////////////////////////////////////////////////// + // @@ Initializing + ////////////////////////////////////////////////// + + /** + * Initialize the color table. + */ + private void init () + { + addNamedColor("black",getColorNumber (0, 0, 0)); + addNamedColor("white",getColorNumber (255, 255, 255)); + addNamedColor("red",getColorNumber (255, 0, 0)); + addNamedColor("green",getColorNumber (0, 255, 0)); addNamedColor("blue",getColorNumber (0, 0, 255)); addNamedColor("cyan",getColorNumber (0, 255, 255)); - addNamedColor("magenta",getColorNumber (255, 0, 255)); - addNamedColor("yellow",getColorNumber (255, 255, 0)); - - getColorNumber (0, 0, 128); - getColorNumber (0, 128, 128); - getColorNumber (0, 128, 0); - getColorNumber (128, 0, 128); - getColorNumber (128, 0, 0); - getColorNumber (128, 128, 0); - getColorNumber (128, 128, 128); - - // Added by Normand Masse - // Gray color added + addNamedColor("magenta",getColorNumber (255, 0, 255)); + addNamedColor("yellow",getColorNumber (255, 255, 0)); + + getColorNumber (0, 0, 128); + getColorNumber (0, 128, 128); + getColorNumber (0, 128, 0); + getColorNumber (128, 0, 128); + getColorNumber (128, 0, 0); + getColorNumber (128, 128, 0); + getColorNumber (128, 128, 128); + + // Added by Normand Masse + // Gray color added addNamedColor( "gray", getColorNumber( 128, 128, 128 ) ); - getColorNumber (192, 192, 192); - } + getColorNumber (192, 192, 192); + } /** define a named color for getColorNumber(String) */ private void addNamedColor(String name,int colorNumber) @@ -167,125 +167,125 @@ public class RtfColorTable namedColors.put(name.toLowerCase(),new Integer(colorNumber)); } - ////////////////////////////////////////////////// - // @@ Public methods - ////////////////////////////////////////////////// + ////////////////////////////////////////////////// + // @@ Public methods + ////////////////////////////////////////////////// /** get the RTF number of a named color * @return null if name not found */ - public Integer getColorNumber (String name) - { + public Integer getColorNumber (String name) + { return (Integer)namedColors.get(name.toLowerCase()); } - /** - * Gets the number of color in the color table - * - * @param red Color level red - * @param green Color level green - * @param blue Color level blue - * - * @return The number of the color in the table - */ - public int getColorNumber (int red, int green, int blue) - { - Integer identifier = new Integer (determineIdentifier (red, green, blue)); - Object o = colorIndex.get (identifier); - int retVal; - - if (o == null) - { - addColor (identifier); - - retVal = colorTable.size (); - } - else - { - retVal = ((Integer) o).intValue (); - } - - return retVal + 1; - } - - /** - * Writes the color table in the header. - * - * @param header The header container to write in - * - * @throws IOException On error - */ - public void writeColors (RtfHeader header) throws IOException - { - if (colorTable == null || colorTable.size () == 0) - { - return; - } - - header.writeGroupMark (true); - header.writeControlWord ("colortbl;"); - - int len = colorTable.size (); - - for (int i = 0; i < len; i++) - { - int identifier = ((Integer) colorTable.get (i)).intValue (); - - header.write ("\\red" + determineColorLevel (identifier, RED)); - header.write ("\\green" + determineColorLevel (identifier, GREEN)); - header.write ("\\blue" + determineColorLevel (identifier, BLUE) + ";"); - } - - header.writeGroupMark (false); - } - - - ////////////////////////////////////////////////// - // @@ Private methods - ////////////////////////////////////////////////// - - /** - * Adds a color to the table. - * - * @param i Identifier of color - */ - private void addColor (Integer i) - { - colorIndex.put (i, new Integer (colorTable.size () + 1)); - colorTable.addElement (i); - } - - /** - * Determines a identifier for the color. - * - * @param red Color level red - * @param green Color level green - * @param blue Color level blue - * - * @return Unique identifier of color - */ - private int determineIdentifier (int red, int green, int blue) - { - int c = red << RED; - - c += green << GREEN; - c += blue << BLUE; - - return c; - } - - /** - * Determines the color level from the identifier. - * - * @param identifier Unique color identifier - * @param color One of the bit moving constants - * - * @return Color level in byte size - */ - private int determineColorLevel (int identifier, int color) - { - int retVal = (byte) (identifier >> color); - - return retVal < 0 ? retVal + 256 : retVal; - } + /** + * Gets the number of color in the color table + * + * @param red Color level red + * @param green Color level green + * @param blue Color level blue + * + * @return The number of the color in the table + */ + public int getColorNumber (int red, int green, int blue) + { + Integer identifier = new Integer (determineIdentifier (red, green, blue)); + Object o = colorIndex.get (identifier); + int retVal; + + if (o == null) + { + addColor (identifier); + + retVal = colorTable.size (); + } + else + { + retVal = ((Integer) o).intValue (); + } + + return retVal + 1; + } + + /** + * Writes the color table in the header. + * + * @param header The header container to write in + * + * @throws IOException On error + */ + public void writeColors (RtfHeader header) throws IOException + { + if (colorTable == null || colorTable.size () == 0) + { + return; + } + + header.writeGroupMark (true); + header.writeControlWord ("colortbl;"); + + int len = colorTable.size (); + + for (int i = 0; i < len; i++) + { + int identifier = ((Integer) colorTable.get (i)).intValue (); + + header.write ("\\red" + determineColorLevel (identifier, RED)); + header.write ("\\green" + determineColorLevel (identifier, GREEN)); + header.write ("\\blue" + determineColorLevel (identifier, BLUE) + ";"); + } + + header.writeGroupMark (false); + } + + + ////////////////////////////////////////////////// + // @@ Private methods + ////////////////////////////////////////////////// + + /** + * Adds a color to the table. + * + * @param i Identifier of color + */ + private void addColor (Integer i) + { + colorIndex.put (i, new Integer (colorTable.size () + 1)); + colorTable.addElement (i); + } + + /** + * Determines a identifier for the color. + * + * @param red Color level red + * @param green Color level green + * @param blue Color level blue + * + * @return Unique identifier of color + */ + private int determineIdentifier (int red, int green, int blue) + { + int c = red << RED; + + c += green << GREEN; + c += blue << BLUE; + + return c; + } + + /** + * Determines the color level from the identifier. + * + * @param identifier Unique color identifier + * @param color One of the bit moving constants + * + * @return Color level in byte size + */ + private int determineColorLevel (int identifier, int color) + { + int retVal = (byte) (identifier >> color); + + return retVal < 0 ? retVal + 256 : retVal; + } } \ No newline at end of file diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfExternalGraphic.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfExternalGraphic.java index 7bdc39894..c9fe0b7eb 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfExternalGraphic.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfExternalGraphic.java @@ -103,135 +103,135 @@ import java.util.Hashtable; public class RtfExternalGraphic extends RtfElement { - /** Exception thrown when an image file/URL cannot be read */ - public static class ExternalGraphicException extends IOException - { - ExternalGraphicException(String reason) - { - super(reason); - } - } - - ////////////////////////////////////////////////// - // @@ Members - ////////////////////////////////////////////////// - - - /** - * The url of the image - */ - protected URL url = null; - - /** - * The height of the image - */ - protected int height = -1; - - /** - * The desired percent value of the height - */ - protected int heightPercent = -1; - - /** - * The desired height - */ - protected int heightDesired = -1; - - /** - * Flag whether the desired height is a percentage - */ - protected boolean perCentH = false; - - /** - * The width of the image - */ - protected int width = -1; - - /** - * The desired percent value of the width - */ - protected int widthPercent = -1; - - /** - * The desired width - */ - protected int widthDesired = -1; - - /** - * Flag whether the desired width is a percentage - */ - protected boolean perCentW = false; - - /** - * Flag whether the image size shall be adjusted - */ - protected boolean scaleUniform = false; - - /** - * Graphic compression rate - */ - protected int graphicCompressionRate = 80; - - - ////////////////////////////////////////////////// - // @@ Construction - ////////////////////////////////////////////////// - - - /** - * Default constructor. - * Create an RTF element as a child of given container. - * - * @param container a RtfContainer value - * @param writer a Writer value - */ - public RtfExternalGraphic(RtfContainer container, Writer writer) throws IOException { - super (container, writer); - } - - /** - * Default constructor. - * - * @param container a RtfContainer value - * @param writer a Writer value - * @param attributes a RtfAttributes value - */ - public RtfExternalGraphic(RtfContainer container, Writer writer, - RtfAttributes attributes) throws IOException { - super (container, writer, attributes); - } - - - ////////////////////////////////////////////////// - // @@ RtfElement implementation - ////////////////////////////////////////////////// - - /** RtfElement override - catches ExternalGraphicException and writes a warning - * message to the document if image cannot be read - */ - protected void writeRtfContent() throws IOException { - try { - writeRtfContentWithException(); - } catch(ExternalGraphicException ie) { - writeExceptionInRtf(ie); - } - } - - /** - * Writes the RTF content to m_writer - this one throws ExternalGraphicExceptions - * - * @exception IOException On error - */ - protected void writeRtfContentWithException() throws IOException { - - if (m_writer == null) { - return; - } - - - if (url == null) { - throw new ExternalGraphicException("The attribute 'url' of is null."); - } + /** Exception thrown when an image file/URL cannot be read */ + public static class ExternalGraphicException extends IOException + { + ExternalGraphicException(String reason) + { + super(reason); + } + } + + ////////////////////////////////////////////////// + // @@ Members + ////////////////////////////////////////////////// + + + /** + * The url of the image + */ + protected URL url = null; + + /** + * The height of the image + */ + protected int height = -1; + + /** + * The desired percent value of the height + */ + protected int heightPercent = -1; + + /** + * The desired height + */ + protected int heightDesired = -1; + + /** + * Flag whether the desired height is a percentage + */ + protected boolean perCentH = false; + + /** + * The width of the image + */ + protected int width = -1; + + /** + * The desired percent value of the width + */ + protected int widthPercent = -1; + + /** + * The desired width + */ + protected int widthDesired = -1; + + /** + * Flag whether the desired width is a percentage + */ + protected boolean perCentW = false; + + /** + * Flag whether the image size shall be adjusted + */ + protected boolean scaleUniform = false; + + /** + * Graphic compression rate + */ + protected int graphicCompressionRate = 80; + + + ////////////////////////////////////////////////// + // @@ Construction + ////////////////////////////////////////////////// + + + /** + * Default constructor. + * Create an RTF element as a child of given container. + * + * @param container a RtfContainer value + * @param writer a Writer value + */ + public RtfExternalGraphic(RtfContainer container, Writer writer) throws IOException { + super (container, writer); + } + + /** + * Default constructor. + * + * @param container a RtfContainer value + * @param writer a Writer value + * @param attributes a RtfAttributes value + */ + public RtfExternalGraphic(RtfContainer container, Writer writer, + RtfAttributes attributes) throws IOException { + super (container, writer, attributes); + } + + + ////////////////////////////////////////////////// + // @@ RtfElement implementation + ////////////////////////////////////////////////// + + /** RtfElement override - catches ExternalGraphicException and writes a warning + * message to the document if image cannot be read + */ + protected void writeRtfContent() throws IOException { + try { + writeRtfContentWithException(); + } catch(ExternalGraphicException ie) { + writeExceptionInRtf(ie); + } + } + + /** + * Writes the RTF content to m_writer - this one throws ExternalGraphicExceptions + * + * @exception IOException On error + */ + protected void writeRtfContentWithException() throws IOException { + + if (m_writer == null) { + return; + } + + + if (url == null) { + throw new ExternalGraphicException("The attribute 'url' of is null."); + } String linkToRoot = System.getProperty( "jfor_link_to_root" ); if (linkToRoot != null) @@ -244,396 +244,396 @@ public class RtfExternalGraphic extends RtfElement return; } -// getRtfFile ().getLog ().logInfo ("Writing image '" + url + "'."); +// getRtfFile ().getLog ().logInfo ("Writing image '" + url + "'."); - byte[] data = null; - try - { - // image reading patch provided by Michael Krause - final BufferedInputStream bin = new BufferedInputStream(url.openStream()); - final ByteArrayOutputStream bout = new ByteArrayOutputStream(); - while (true) { - final int datum = bin.read(); - if (datum == -1) break; - bout.write(datum); + byte[] data = null; + try + { + // image reading patch provided by Michael Krause + final BufferedInputStream bin = new BufferedInputStream(url.openStream()); + final ByteArrayOutputStream bout = new ByteArrayOutputStream(); + while (true) { + final int datum = bin.read(); + if (datum == -1) break; + bout.write(datum); } bout.flush(); data = bout.toByteArray(); - } - catch (Exception e) { - throw new ExternalGraphicException("The attribute 'src' of has a invalid value: '" + url + "' (" + e + ")"); - } - - if (data == null) { - return; - } - - // Determine image file format - String file = url.getFile (); - int type = determineImageType(data, file.substring(file.lastIndexOf(".") + 1)); - - if (type >= ImageConstants.I_TO_CONVERT_BASIS) { - // convert - int to = ImageConstants.CONVERT_TO [type - ImageConstants.I_TO_CONVERT_BASIS]; - - if (to == ImageConstants.I_JPG) { - ByteArrayOutputStream out = null; -// try { - //convert to jpeg -// out = new ByteArrayOutputStream(); -// Encoder jpgEncoder = new Encoder(graphicCompressionRate, out); -// jpgEncoder.encodeJPEG(data); -// data = out.toByteArray(); -// type = to; -// } -// catch (JPEGException e) { -// e.setMessage("Image from tag could not be created (src = '" + url + "'"); -// } -// finally { - out.close(); -// } - } - else { - type = ImageConstants.I_NOT_SUPPORTED; - } - } - - - if (type == ImageConstants.I_NOT_SUPPORTED) { - throw new ExternalGraphicException("The tag does not support " + file.substring(file.lastIndexOf(".") + 1) + " - image type."); - } - - String rtfImageCode = ImageConstants.RTF_TAGS [type]; - - // Writes the beginning of the rtf image - - writeGroupMark(true); - writeStarControlWord("shppict"); - writeGroupMark(true); - writeControlWord("pict"); - - StringBuffer buf = new StringBuffer(data.length * 3); - - writeControlWord(rtfImageCode); - - if (type == ImageConstants.I_PNG) { - width = ImageUtil.getIntFromByteArray(data, 16, 4, true); - height = ImageUtil.getIntFromByteArray(data, 20, 4, true); - } - else if (type == ImageConstants.I_JPG) { - int basis = -1; - byte ff = (byte) 0xff; - byte c0 = (byte) 0xc0; - for (int i = 0; i < data.length; i++) { - byte b = data[i]; - if (b != ff) - continue; - if (i == data.length - 1) - continue; - b = data[i + 1]; - if (b != c0) - continue; - basis = i + 5; - break; - } - - if (basis != -1) { - width = ImageUtil.getIntFromByteArray(data, basis + 2, 2, true); - height = ImageUtil.getIntFromByteArray(data, basis, 2, true); - } - } - else if (type == ImageConstants.I_EMF) { - width = ImageUtil.getIntFromByteArray(data, 151, 4, false); - height = ImageUtil.getIntFromByteArray(data, 155, 4, false); - } - - // Set image size - if (width != -1) { - writeControlWord("picw" + width); - } - if (height != -1) { - writeControlWord("pich" + height); - } - - if (widthDesired != -1) { - if (perCentW) { - writeControlWord("picscalex" + widthDesired); - } - else { - writeControlWord("picscalex" + widthDesired * 100 / width); - } - - writeControlWord("picwgoal" + widthDesired); - } - else if (scaleUniform && heightDesired != -1) { - if (perCentH) { - writeControlWord("picscalex" + heightDesired); - } - else { - writeControlWord("picscalex" + heightDesired * 100 / height); - } - } - - if (heightDesired != -1) { - if (perCentH) { - writeControlWord("picscaley" + heightDesired); - } - else { - writeControlWord("picscaley" + heightDesired * 100 / height); - } - - writeControlWord("pichgoal" + heightDesired); - } - else if (scaleUniform && widthDesired != -1) { - if (perCentW) { - writeControlWord("picscaley" + widthDesired); - } - else { - writeControlWord("picscaley" + widthDesired * 100 / width); - } - } - - for (int i = 0; i < data.length; i++) { - int iData = data [i]; - - // Make positive byte - if (iData < 0) - iData += 256; - - if (iData < 16) { - // Set leading zero and append - buf.append('0'); - } - - buf.append(Integer.toHexString(iData)); - } - - int len = buf.length(); - char[] chars = new char[len]; - - buf.getChars(0, len, chars, 0); - m_writer.write(chars); - - // Writes the end of RTF image - - writeGroupMark(false); - writeGroupMark(false); - } - - - ////////////////////////////////////////////////// - // @@ Member access - ////////////////////////////////////////////////// - - /** - * Sets the desired height of the image. - * - * @param theHeight The desired image height - */ - public void setHeight(String theHeight) { - this.heightDesired = ImageUtil.getInt(theHeight); - this.perCentH = ImageUtil.isPercent(theHeight); - } - - /** - * Sets the desired width of the image. - * - * @param theWidth The desired image width - */ - public void setWidth(String theWidth) { - this.widthDesired = ImageUtil.getInt(theWidth); - this.perCentW = ImageUtil.isPercent(theWidth); - } - - /** - * Sets the flag whether the image size shall be adjusted. - * - * @param value - * true image width or height shall be adjusted automatically\n - * false no adjustment - */ - public void setScaling(String value) { - if (value.equalsIgnoreCase("uniform")) { - this.scaleUniform = true; - } - } - - /** - * Sets the url of the image. - * - * @param urlString Image url like "file://..." - * @throws IOException On error - */ - public void setURL(String urlString) throws IOException - { - URL tmpUrl = null; - try - { - tmpUrl = new URL (urlString); - } - catch (MalformedURLException e) - { - try - { - tmpUrl = new File (urlString).toURL (); - } - catch (MalformedURLException ee) - { - throw new ExternalGraphicException("The attribute 'src' of has a invalid value: '" + urlString + "' (" + ee + ")"); - } - } - this.url = tmpUrl; - } - - /** - * Gets the compression rate for the image in percent. - * @return Compression rate - */ - public int getCompressionRate () - { - return graphicCompressionRate; - } - - /** - * Sets the compression rate for the image in percent. - * - * @param percent Compression rate - * @return - * true: The compression rate is valid (0..100)\n - * false: The compression rate is invalid - */ - public boolean setCompressionRate (int percent) - { - if (percent < 1 || percent > 100) - return false; - - graphicCompressionRate = percent; - return true; - } - - - ////////////////////////////////////////////////// - // @@ Helpers - ////////////////////////////////////////////////// - - - /** - * Determines wheter the image is a jpeg. - * - * @param data Image - * - * @return - * true If JPEG type\n - * false Other type - */ - private boolean isJPEG(byte[] data) { - // Indentifier "0xFFD8" on position 0 - byte [] pattern = new byte [] {(byte) 0xFF, (byte) 0xD8}; - - return ImageUtil.compareHexValues(pattern, data, 0, true); - } - - /** - * Determines wheter the image is a png. - * - * @param data Image - * - * @return - * true If PNG type\n - * false Other type - */ - private boolean isPNG(byte[] data) { - // Indentifier "PNG" on position 1 - byte [] pattern = new byte [] {(byte) 0x50, (byte) 0x4E, (byte) 0x47}; - - return ImageUtil.compareHexValues(pattern, data, 1, true); - } - - /** - * Determines wheter the image is a emf. - * - * @param data Image - * - * @return - * true If EMF type\n - * false Other type - */ - private boolean isEMF(byte[] data) { - // No offical Indentifier known - byte [] pattern = new byte [] {(byte) 0x01, (byte) 0x00, (byte) 0x00}; - - return ImageUtil.compareHexValues(pattern, data, 0, true); - } - - /** - * Determines wheter the image is a gif. - * - * @param data Image - * - * @return - * true If GIF type\n - * false Other type - */ - private boolean isGIF(byte[] data) { - // Indentifier "GIF8" on position 0 - byte [] pattern = new byte [] {(byte) 0x47, (byte) 0x49, (byte) 0x46, (byte) 0x38}; - - return ImageUtil.compareHexValues(pattern, data, 0, true); - } - - /** - * Determines wheter the image is a gif. - * - * @param data Image - * - * @return - * true If BMP type\n - * false Other type - */ - private boolean isBMP(byte[] data) { - // Indentifier "BM" on position 0 - byte [] pattern = new byte [] {(byte) 0x42, (byte) 0x4D}; - - return ImageUtil.compareHexValues(pattern, data, 0, true); - } - - /** - * Determine image file format. - * - * @param data Image - * @param ext Image extension - * - * @return Image type by ImageConstants.java - */ - private int determineImageType(byte [] data, String ext) { - int type = ImageConstants.I_NOT_SUPPORTED; - - if (isPNG(data)) { - type = ImageConstants.I_PNG; - } - else if (isJPEG(data)) { - type = ImageConstants.I_JPG_C; - } - else if (isEMF(data)) { - type = ImageConstants.I_EMF; - } - else if (isGIF(data)) { - type = ImageConstants.I_GIF; - } - else { - Object tmp = ImageConstants.SUPPORTED_IMAGE_TYPES.get(ext.toLowerCase()); - if (tmp != null) { - type = ((Integer) tmp).intValue(); - } - } - - return type; - } - - /** true if this element would generate no "useful" RTF content */ - public boolean isEmpty() - { - return url==null; - } + } + catch (Exception e) { + throw new ExternalGraphicException("The attribute 'src' of has a invalid value: '" + url + "' (" + e + ")"); + } + + if (data == null) { + return; + } + + // Determine image file format + String file = url.getFile (); + int type = determineImageType(data, file.substring(file.lastIndexOf(".") + 1)); + + if (type >= ImageConstants.I_TO_CONVERT_BASIS) { + // convert + int to = ImageConstants.CONVERT_TO [type - ImageConstants.I_TO_CONVERT_BASIS]; + + if (to == ImageConstants.I_JPG) { + ByteArrayOutputStream out = null; +// try { + //convert to jpeg +// out = new ByteArrayOutputStream(); +// Encoder jpgEncoder = new Encoder(graphicCompressionRate, out); +// jpgEncoder.encodeJPEG(data); +// data = out.toByteArray(); +// type = to; +// } +// catch (JPEGException e) { +// e.setMessage("Image from tag could not be created (src = '" + url + "'"); +// } +// finally { + out.close(); +// } + } + else { + type = ImageConstants.I_NOT_SUPPORTED; + } + } + + + if (type == ImageConstants.I_NOT_SUPPORTED) { + throw new ExternalGraphicException("The tag does not support " + file.substring(file.lastIndexOf(".") + 1) + " - image type."); + } + + String rtfImageCode = ImageConstants.RTF_TAGS [type]; + + // Writes the beginning of the rtf image + + writeGroupMark(true); + writeStarControlWord("shppict"); + writeGroupMark(true); + writeControlWord("pict"); + + StringBuffer buf = new StringBuffer(data.length * 3); + + writeControlWord(rtfImageCode); + + if (type == ImageConstants.I_PNG) { + width = ImageUtil.getIntFromByteArray(data, 16, 4, true); + height = ImageUtil.getIntFromByteArray(data, 20, 4, true); + } + else if (type == ImageConstants.I_JPG) { + int basis = -1; + byte ff = (byte) 0xff; + byte c0 = (byte) 0xc0; + for (int i = 0; i < data.length; i++) { + byte b = data[i]; + if (b != ff) + continue; + if (i == data.length - 1) + continue; + b = data[i + 1]; + if (b != c0) + continue; + basis = i + 5; + break; + } + + if (basis != -1) { + width = ImageUtil.getIntFromByteArray(data, basis + 2, 2, true); + height = ImageUtil.getIntFromByteArray(data, basis, 2, true); + } + } + else if (type == ImageConstants.I_EMF) { + width = ImageUtil.getIntFromByteArray(data, 151, 4, false); + height = ImageUtil.getIntFromByteArray(data, 155, 4, false); + } + + // Set image size + if (width != -1) { + writeControlWord("picw" + width); + } + if (height != -1) { + writeControlWord("pich" + height); + } + + if (widthDesired != -1) { + if (perCentW) { + writeControlWord("picscalex" + widthDesired); + } + else { + writeControlWord("picscalex" + widthDesired * 100 / width); + } + + writeControlWord("picwgoal" + widthDesired); + } + else if (scaleUniform && heightDesired != -1) { + if (perCentH) { + writeControlWord("picscalex" + heightDesired); + } + else { + writeControlWord("picscalex" + heightDesired * 100 / height); + } + } + + if (heightDesired != -1) { + if (perCentH) { + writeControlWord("picscaley" + heightDesired); + } + else { + writeControlWord("picscaley" + heightDesired * 100 / height); + } + + writeControlWord("pichgoal" + heightDesired); + } + else if (scaleUniform && widthDesired != -1) { + if (perCentW) { + writeControlWord("picscaley" + widthDesired); + } + else { + writeControlWord("picscaley" + widthDesired * 100 / width); + } + } + + for (int i = 0; i < data.length; i++) { + int iData = data [i]; + + // Make positive byte + if (iData < 0) + iData += 256; + + if (iData < 16) { + // Set leading zero and append + buf.append('0'); + } + + buf.append(Integer.toHexString(iData)); + } + + int len = buf.length(); + char[] chars = new char[len]; + + buf.getChars(0, len, chars, 0); + m_writer.write(chars); + + // Writes the end of RTF image + + writeGroupMark(false); + writeGroupMark(false); + } + + + ////////////////////////////////////////////////// + // @@ Member access + ////////////////////////////////////////////////// + + /** + * Sets the desired height of the image. + * + * @param theHeight The desired image height + */ + public void setHeight(String theHeight) { + this.heightDesired = ImageUtil.getInt(theHeight); + this.perCentH = ImageUtil.isPercent(theHeight); + } + + /** + * Sets the desired width of the image. + * + * @param theWidth The desired image width + */ + public void setWidth(String theWidth) { + this.widthDesired = ImageUtil.getInt(theWidth); + this.perCentW = ImageUtil.isPercent(theWidth); + } + + /** + * Sets the flag whether the image size shall be adjusted. + * + * @param value + * true image width or height shall be adjusted automatically\n + * false no adjustment + */ + public void setScaling(String value) { + if (value.equalsIgnoreCase("uniform")) { + this.scaleUniform = true; + } + } + + /** + * Sets the url of the image. + * + * @param urlString Image url like "file://..." + * @throws IOException On error + */ + public void setURL(String urlString) throws IOException + { + URL tmpUrl = null; + try + { + tmpUrl = new URL (urlString); + } + catch (MalformedURLException e) + { + try + { + tmpUrl = new File (urlString).toURL (); + } + catch (MalformedURLException ee) + { + throw new ExternalGraphicException("The attribute 'src' of has a invalid value: '" + urlString + "' (" + ee + ")"); + } + } + this.url = tmpUrl; + } + + /** + * Gets the compression rate for the image in percent. + * @return Compression rate + */ + public int getCompressionRate () + { + return graphicCompressionRate; + } + + /** + * Sets the compression rate for the image in percent. + * + * @param percent Compression rate + * @return + * true: The compression rate is valid (0..100)\n + * false: The compression rate is invalid + */ + public boolean setCompressionRate (int percent) + { + if (percent < 1 || percent > 100) + return false; + + graphicCompressionRate = percent; + return true; + } + + + ////////////////////////////////////////////////// + // @@ Helpers + ////////////////////////////////////////////////// + + + /** + * Determines wheter the image is a jpeg. + * + * @param data Image + * + * @return + * true If JPEG type\n + * false Other type + */ + private boolean isJPEG(byte[] data) { + // Indentifier "0xFFD8" on position 0 + byte [] pattern = new byte [] {(byte) 0xFF, (byte) 0xD8}; + + return ImageUtil.compareHexValues(pattern, data, 0, true); + } + + /** + * Determines wheter the image is a png. + * + * @param data Image + * + * @return + * true If PNG type\n + * false Other type + */ + private boolean isPNG(byte[] data) { + // Indentifier "PNG" on position 1 + byte [] pattern = new byte [] {(byte) 0x50, (byte) 0x4E, (byte) 0x47}; + + return ImageUtil.compareHexValues(pattern, data, 1, true); + } + + /** + * Determines wheter the image is a emf. + * + * @param data Image + * + * @return + * true If EMF type\n + * false Other type + */ + private boolean isEMF(byte[] data) { + // No offical Indentifier known + byte [] pattern = new byte [] {(byte) 0x01, (byte) 0x00, (byte) 0x00}; + + return ImageUtil.compareHexValues(pattern, data, 0, true); + } + + /** + * Determines wheter the image is a gif. + * + * @param data Image + * + * @return + * true If GIF type\n + * false Other type + */ + private boolean isGIF(byte[] data) { + // Indentifier "GIF8" on position 0 + byte [] pattern = new byte [] {(byte) 0x47, (byte) 0x49, (byte) 0x46, (byte) 0x38}; + + return ImageUtil.compareHexValues(pattern, data, 0, true); + } + + /** + * Determines wheter the image is a gif. + * + * @param data Image + * + * @return + * true If BMP type\n + * false Other type + */ + private boolean isBMP(byte[] data) { + // Indentifier "BM" on position 0 + byte [] pattern = new byte [] {(byte) 0x42, (byte) 0x4D}; + + return ImageUtil.compareHexValues(pattern, data, 0, true); + } + + /** + * Determine image file format. + * + * @param data Image + * @param ext Image extension + * + * @return Image type by ImageConstants.java + */ + private int determineImageType(byte [] data, String ext) { + int type = ImageConstants.I_NOT_SUPPORTED; + + if (isPNG(data)) { + type = ImageConstants.I_PNG; + } + else if (isJPEG(data)) { + type = ImageConstants.I_JPG_C; + } + else if (isEMF(data)) { + type = ImageConstants.I_EMF; + } + else if (isGIF(data)) { + type = ImageConstants.I_GIF; + } + else { + Object tmp = ImageConstants.SUPPORTED_IMAGE_TYPES.get(ext.toLowerCase()); + if (tmp != null) { + type = ((Integer) tmp).intValue(); + } + } + + return type; + } + + /** true if this element would generate no "useful" RTF content */ + public boolean isEmpty() + { + return url==null; + } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFile.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFile.java index fd16c5659..969c867e7 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFile.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFile.java @@ -71,143 +71,143 @@ import java.io.*; public class RtfFile extends RtfContainer { - private RtfHeader m_header; - private RtfPageArea m_pageArea; - private RtfListTable m_listTable; - private RtfDocumentArea m_docArea; -// private ConverterLogChannel m_log; - private RtfContainer m_listTableContainer; - private int listNum=0; - - /** Create an RTF file that outputs to the given Writer */ - public RtfFile(Writer w) throws IOException { - super(null,w); - } - - /** optional log channel */ -// public void setLogChannel(ConverterLogChannel log) -// { -// m_log = log; -// } - - /** - * Gets the log channel. - * If logchannel not set, it will return a empty log channel. - * @return our log channel, it is never null */ -// ConverterLogChannel getLog() -// { -// if (m_log == null) -// m_log = new ConverterLogChannel (null); -// return m_log; -// } - - /** If called, must be called before startDocumentArea */ - public RtfHeader startHeader() - throws IOException { - if(m_header!=null) throw new RtfStructureException("startHeader called more than once"); - m_header = new RtfHeader(this,m_writer); - m_listTableContainer = new RtfContainer(this,m_writer); - return m_header; - } - - /** Creates the list table.*/ - public RtfListTable startListTable(RtfAttributes attr) - throws IOException{ - listNum++; - m_listTable = new RtfListTable(this,m_writer,new Integer(listNum),attr); - m_listTableContainer.addChild(m_listTable); - return m_listTable; - } - - /** Closes the RtfHeader if not done yet, and starts the docment area. - Like startDocumentArea, is only called once. This is not optimal, - must be able to have multiple page definition, and corresponding - Document areas */ - public RtfPageArea startPageArea() - throws IOException,RtfStructureException { - if(m_pageArea!=null) throw new RtfStructureException("startPageArea called more than once"); - // create an empty header if there was none - if(m_header==null) startHeader(); - m_header.close(); - m_pageArea = new RtfPageArea(this,m_writer); - addChild(m_pageArea); - return m_pageArea; - } - - /** Call startPageArea if needed and return the page area object. */ - public RtfPageArea getPageArea() - throws IOException,RtfStructureException { - if(m_pageArea== null) return startPageArea(); - return m_pageArea; - } - - /** Closes the RtfHeader if not done yet, and starts the document area. - * Must be called once only. - */ - public RtfDocumentArea startDocumentArea() - throws IOException,RtfStructureException { - if(m_docArea!=null) throw new RtfStructureException("startDocumentArea called more than once"); - // create an empty header if there was none - if(m_header==null) startHeader(); - m_header.close(); - m_docArea = new RtfDocumentArea(this,m_writer); - addChild(m_docArea); - return m_docArea; - } - - - - /** Call startDocumentArea if needed and return the document area object. */ - public RtfDocumentArea getDocumentArea() - throws IOException,RtfStructureException { - if(m_docArea == null) return startDocumentArea(); - return m_docArea; - } - - /** overridden to write RTF prefix code, what comes before our children */ - protected void writeRtfPrefix() throws IOException - { - writeGroupMark(true); - writeControlWord("rtf1"); - } - - /** overridden to write RTF suffix code, what comes after our children */ - protected void writeRtfSuffix() throws IOException - { - writeGroupMark(false); - } - - /** must be called when done creating the document */ - public synchronized void flush() throws IOException { - writeRtf(); - m_writer.flush(); - } - - /** minimal test and usage example */ - public static void main(String args[]) - throws Exception { - Writer w = null; - if(args.length != 0) { - final String outFile = args[0]; - System.err.println("Outputting RTF to file '" + outFile + "'"); - w = new BufferedWriter(new FileWriter(outFile)); - } else { - System.err.println("Outputting RTF code to standard output"); - w = new BufferedWriter(new OutputStreamWriter(System.out)); - } - - final RtfFile f = new RtfFile(w); - final RtfSection sect = f.startDocumentArea().newSection(); - - final RtfParagraph p = sect.newParagraph(); - p.newText("Hello, RTF world.\n",null); - final RtfAttributes attr = new RtfAttributes(); - attr.set(RtfText.ATTR_BOLD); - attr.set(RtfText.ATTR_ITALIC); - attr.set(RtfText.ATTR_FONT_SIZE,36); - p.newText("This is bold, italic, 36 points",attr); - - f.flush(); - System.err.println("RtfFile test: all done."); - } + private RtfHeader m_header; + private RtfPageArea m_pageArea; + private RtfListTable m_listTable; + private RtfDocumentArea m_docArea; +// private ConverterLogChannel m_log; + private RtfContainer m_listTableContainer; + private int listNum=0; + + /** Create an RTF file that outputs to the given Writer */ + public RtfFile(Writer w) throws IOException { + super(null,w); + } + + /** optional log channel */ +// public void setLogChannel(ConverterLogChannel log) +// { +// m_log = log; +// } + + /** + * Gets the log channel. + * If logchannel not set, it will return a empty log channel. + * @return our log channel, it is never null */ +// ConverterLogChannel getLog() +// { +// if (m_log == null) +// m_log = new ConverterLogChannel (null); +// return m_log; +// } + + /** If called, must be called before startDocumentArea */ + public RtfHeader startHeader() + throws IOException { + if(m_header!=null) throw new RtfStructureException("startHeader called more than once"); + m_header = new RtfHeader(this,m_writer); + m_listTableContainer = new RtfContainer(this,m_writer); + return m_header; + } + + /** Creates the list table.*/ + public RtfListTable startListTable(RtfAttributes attr) + throws IOException{ + listNum++; + m_listTable = new RtfListTable(this,m_writer,new Integer(listNum),attr); + m_listTableContainer.addChild(m_listTable); + return m_listTable; + } + + /** Closes the RtfHeader if not done yet, and starts the docment area. + Like startDocumentArea, is only called once. This is not optimal, + must be able to have multiple page definition, and corresponding + Document areas */ + public RtfPageArea startPageArea() + throws IOException,RtfStructureException { + if(m_pageArea!=null) throw new RtfStructureException("startPageArea called more than once"); + // create an empty header if there was none + if(m_header==null) startHeader(); + m_header.close(); + m_pageArea = new RtfPageArea(this,m_writer); + addChild(m_pageArea); + return m_pageArea; + } + + /** Call startPageArea if needed and return the page area object. */ + public RtfPageArea getPageArea() + throws IOException,RtfStructureException { + if(m_pageArea== null) return startPageArea(); + return m_pageArea; + } + + /** Closes the RtfHeader if not done yet, and starts the document area. + * Must be called once only. + */ + public RtfDocumentArea startDocumentArea() + throws IOException,RtfStructureException { + if(m_docArea!=null) throw new RtfStructureException("startDocumentArea called more than once"); + // create an empty header if there was none + if(m_header==null) startHeader(); + m_header.close(); + m_docArea = new RtfDocumentArea(this,m_writer); + addChild(m_docArea); + return m_docArea; + } + + + + /** Call startDocumentArea if needed and return the document area object. */ + public RtfDocumentArea getDocumentArea() + throws IOException,RtfStructureException { + if(m_docArea == null) return startDocumentArea(); + return m_docArea; + } + + /** overridden to write RTF prefix code, what comes before our children */ + protected void writeRtfPrefix() throws IOException + { + writeGroupMark(true); + writeControlWord("rtf1"); + } + + /** overridden to write RTF suffix code, what comes after our children */ + protected void writeRtfSuffix() throws IOException + { + writeGroupMark(false); + } + + /** must be called when done creating the document */ + public synchronized void flush() throws IOException { + writeRtf(); + m_writer.flush(); + } + + /** minimal test and usage example */ + public static void main(String args[]) + throws Exception { + Writer w = null; + if(args.length != 0) { + final String outFile = args[0]; + System.err.println("Outputting RTF to file '" + outFile + "'"); + w = new BufferedWriter(new FileWriter(outFile)); + } else { + System.err.println("Outputting RTF code to standard output"); + w = new BufferedWriter(new OutputStreamWriter(System.out)); + } + + final RtfFile f = new RtfFile(w); + final RtfSection sect = f.startDocumentArea().newSection(); + + final RtfParagraph p = sect.newParagraph(); + p.newText("Hello, RTF world.\n",null); + final RtfAttributes attr = new RtfAttributes(); + attr.set(RtfText.ATTR_BOLD); + attr.set(RtfText.ATTR_ITALIC); + attr.set(RtfText.ATTR_FONT_SIZE,36); + p.newText("This is bold, italic, 36 points",attr); + + f.flush(); + System.err.println("RtfFile test: all done."); + } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFontManager.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFontManager.java index 10aea92e7..92d7a9555 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFontManager.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFontManager.java @@ -68,154 +68,154 @@ import java.util.Vector; */ public class RtfFontManager { - ////////////////////////////////////////////////// - // @@ Members - ////////////////////////////////////////////////// - - /** Singelton instance */ - private static RtfFontManager instance = null; - - /** Index table for the fonts */ - private Hashtable fontIndex = null; - /** Used fonts to this vector */ - private Vector fontTable = null; - - - ////////////////////////////////////////////////// - // @@ Construction - ////////////////////////////////////////////////// - - /** - * Constructor. - */ - private RtfFontManager () - { - fontTable = new Vector (); - fontIndex = new Hashtable (); - - init (); - } - - /** - * Singelton. - * - * @return The instance of RtfFontManager - */ - public static RtfFontManager getInstance () - { - if (instance == null) - { - instance = new RtfFontManager (); - } - - return instance; - } - - - ////////////////////////////////////////////////// - // @@ Initializing - ////////////////////////////////////////////////// - - /** - * Initialize the font table. - */ - private void init () - { - -// getFontNumber ("Helvetica"); - //Chanded by R.Marra default font Arial - getFontNumber ("Arial"); - getFontNumber ("Symbol"); // used by RtfListItem.java - getFontNumber ("Times New Roman"); + ////////////////////////////////////////////////// + // @@ Members + ////////////////////////////////////////////////// + + /** Singelton instance */ + private static RtfFontManager instance = null; + + /** Index table for the fonts */ + private Hashtable fontIndex = null; + /** Used fonts to this vector */ + private Vector fontTable = null; + + + ////////////////////////////////////////////////// + // @@ Construction + ////////////////////////////////////////////////// + + /** + * Constructor. + */ + private RtfFontManager () + { + fontTable = new Vector (); + fontIndex = new Hashtable (); + + init (); + } + + /** + * Singelton. + * + * @return The instance of RtfFontManager + */ + public static RtfFontManager getInstance () + { + if (instance == null) + { + instance = new RtfFontManager (); + } + + return instance; + } + + + ////////////////////////////////////////////////// + // @@ Initializing + ////////////////////////////////////////////////// + + /** + * Initialize the font table. + */ + private void init () + { + +// getFontNumber ("Helvetica"); + //Chanded by R.Marra default font Arial + getFontNumber ("Arial"); + getFontNumber ("Symbol"); // used by RtfListItem.java + getFontNumber ("Times New Roman"); /* - {\\f0\\fswiss Helv;} + {\\f0\\fswiss Helv;} - // f1 is used by RtfList and RtfListItem for bullets + // f1 is used by RtfList and RtfListItem for bullets - {\\f1\\froman\\fcharset2 Symbol;} - {\\f2\\froman\\fprq2 Times New Roman;} - {\\f3\\froman Times New Roman;} + {\\f1\\froman\\fcharset2 Symbol;} + {\\f2\\froman\\fprq2 Times New Roman;} + {\\f3\\froman Times New Roman;} */ - } - - - ////////////////////////////////////////////////// - // @@ Public methods - ////////////////////////////////////////////////// - - - /** - * Gets the number of font in the font table - * - * @param family Font family name ('Helvetica') - * - * @return The number of the font in the table - */ - public int getFontNumber (String family) - { - - family = family.toLowerCase (); - Object o = fontIndex.get (family); - int retVal; - - if (o == null) - { - addFont (family); - - retVal = fontTable.size () - 1; - } - else - { - retVal = ((Integer) o).intValue (); - } - - return retVal; - } - - /** - * Writes the font table in the header. - * - * @param header The header container to write in - * - * @throws IOException On error - */ - public void writeFonts (RtfHeader header) throws IOException - { - if (fontTable == null || fontTable.size () == 0) - { - return; - } - - header.writeGroupMark (true); - header.writeControlWord ("fonttbl;"); - - int len = fontTable.size (); - - for (int i = 0; i < len; i++) - { - header.writeGroupMark (true); - header.write ("\\f" + i); - header.write (" " + (String) fontTable.elementAt (i)); - header.writeGroupMark (false); - } - - header.writeGroupMark (false); - } - - - ////////////////////////////////////////////////// - // @@ Private methods - ////////////////////////////////////////////////// - - /** - * Adds a font to the table. - * - * @param i Identifier of font - */ - private void addFont (String family) - { - fontIndex.put (family, new Integer (fontTable.size ())); - fontTable.addElement (family); - } + } + + + ////////////////////////////////////////////////// + // @@ Public methods + ////////////////////////////////////////////////// + + + /** + * Gets the number of font in the font table + * + * @param family Font family name ('Helvetica') + * + * @return The number of the font in the table + */ + public int getFontNumber (String family) + { + + family = family.toLowerCase (); + Object o = fontIndex.get (family); + int retVal; + + if (o == null) + { + addFont (family); + + retVal = fontTable.size () - 1; + } + else + { + retVal = ((Integer) o).intValue (); + } + + return retVal; + } + + /** + * Writes the font table in the header. + * + * @param header The header container to write in + * + * @throws IOException On error + */ + public void writeFonts (RtfHeader header) throws IOException + { + if (fontTable == null || fontTable.size () == 0) + { + return; + } + + header.writeGroupMark (true); + header.writeControlWord ("fonttbl;"); + + int len = fontTable.size (); + + for (int i = 0; i < len; i++) + { + header.writeGroupMark (true); + header.write ("\\f" + i); + header.write (" " + (String) fontTable.elementAt (i)); + header.writeGroupMark (false); + } + + header.writeGroupMark (false); + } + + + ////////////////////////////////////////////////// + // @@ Private methods + ////////////////////////////////////////////////// + + /** + * Adds a font to the table. + * + * @param i Identifier of font + */ + private void addFont (String family) + { + fontIndex.put (family, new Integer (fontTable.size ())); + fontTable.addElement (family); + } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFontTable.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFontTable.java index 98501c175..76220713c 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFontTable.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFontTable.java @@ -68,17 +68,17 @@ import java.io.IOException; class RtfFontTable extends RtfElement { - /** Create an RTF header */ - RtfFontTable(RtfHeader h, Writer w) throws IOException - { - super(h,w); - } + /** Create an RTF header */ + RtfFontTable(RtfHeader h, Writer w) throws IOException + { + super(h,w); + } - /** write our contents to m_writer. */ - protected void writeRtfContent() throws IOException - { - RtfFontManager.getInstance ().writeFonts ((RtfHeader)m_parent); - } + /** write our contents to m_writer. */ + protected void writeRtfContent() throws IOException + { + RtfFontManager.getInstance ().writeFonts ((RtfHeader)m_parent); + } /** true if this element would generate no "useful" RTF content */ public boolean isEmpty() diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfHeader.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfHeader.java index 986778c4a..abd5121c0 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfHeader.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfHeader.java @@ -85,8 +85,8 @@ class RtfHeader extends RtfContainer { writeUserProperties(); RtfColorTable.getInstance().writeColors(this); super.writeRtfContent(); - RtfTemplate.getInstance().writeTemplate(this); - RtfStyleSheetTable.getInstance().writeStyleSheet(this); + RtfTemplate.getInstance().writeTemplate(this); + RtfStyleSheetTable.getInstance().writeStyleSheet(this); } @@ -121,6 +121,6 @@ class RtfHeader extends RtfContainer { /** write to our Writer using an RtfStringConverter */ void writeRtfString(String toWrite) throws IOException { - RtfStringConverter.getInstance().writeRtfString(m_writer,toWrite); + RtfStringConverter.getInstance().writeRtfString(m_writer,toWrite); } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfHyperLink.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfHyperLink.java index b27a50969..191853965 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfHyperLink.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfHyperLink.java @@ -71,164 +71,164 @@ import java.io.IOException; public class RtfHyperLink extends RtfContainer implements IRtfTextContainer { - ////////////////////////////////////////////////// - // @@ Members - ////////////////////////////////////////////////// - - /** The url of the image */ - protected String url = null; - - /** RtfText */ - protected RtfText mText = null; - - ////////////////////////////////////////////////// - // @@ Construction - ////////////////////////////////////////////////// - - - /** - * Default constructor. - * - * @param container a RtfContainer value - * @param writer a Writer value - * @param attributes a RtfAttributes value - */ - public RtfHyperLink (IRtfTextContainer parent, Writer writer, String str, RtfAttributes attr) - throws IOException - { - super ((RtfContainer) parent, writer, attr); - new RtfText (this, writer, str, attr); - } - - - ////////////////////////////////////////////////// - // @@ RtfElement implementation - ////////////////////////////////////////////////// - - /** - * Writes the RTF content to m_writer. - * - * @exception IOException On error - */ - public void writeRtfPrefix () throws IOException - { - super.writeGroupMark (true); - super.writeControlWord ("field"); - - super.writeGroupMark (true); - super.writeStarControlWord ("fldinst"); - - m_writer.write ("HYPERLINK \"" + url + "\" "); - super.writeGroupMark (false); - - super.writeGroupMark (true); - super.writeControlWord ("fldrslt"); - - // start a group for this paragraph and write our own attributes if needed - if (m_attrib != null && m_attrib.isSet ("cs")) - { - writeGroupMark (true); - writeAttributes(m_attrib, new String [] {"cs"}); - } - } - - /** - * Writes the RTF content to m_writer. - * - * @exception IOException On error - */ - public void writeRtfSuffix () throws IOException - { - if (m_attrib != null && m_attrib.isSet ("cs")) - { - writeGroupMark (false); - } - super.writeGroupMark (false); - super.writeGroupMark (false); - } - - - ////////////////////////////////////////////////// - // @@ IRtfContainer implementation - ////////////////////////////////////////////////// - - /** close current text run if any and start a new one with default attributes - * @param str if not null, added to the RtfText created - */ - public RtfText newText (String str) throws IOException { - return newText (str,null); - } - - /** close current text run if any and start a new one - * @param str if not null, added to the RtfText created - */ - public RtfText newText (String str,RtfAttributes attr) throws IOException - { - closeAll (); - mText = new RtfText (this, m_writer, str, attr); - return mText; - } - - /** IRtfTextContainer requirement: return a copy of our attributes */ - public RtfAttributes getTextContainerAttributes() - { - if (m_attrib == null) return null; - return (RtfAttributes) this.m_attrib.clone (); - } - - - /** add a line break */ - public void newLineBreak () throws IOException - { - new RtfLineBreak (this, m_writer); - } - - - ////////////////////////////////////////////////// - // @@ Common container methods - ////////////////////////////////////////////////// - - private void closeCurrentText () throws IOException - { - if (mText != null) mText.close (); - } - - private void closeAll () throws IOException - { - closeCurrentText(); - } - - - ////////////////////////////////////////////////// - // @@ Member access - ////////////////////////////////////////////////// - - /** - * Sets the url of the external link. - * - * @param url Link url like "http://..." - */ - public void setExternalURL (String url) - { - this.url = url; - } - - /** - * Sets the url of the external link. - * - * @param jumpTo Name of the text mark - */ - public void setInternalURL (String jumpTo) - { - int now = jumpTo.length (); - int max = RtfBookmark.maxBookmarkLength; - this.url = "#" + jumpTo.substring (0, now > max ? max : now); - this.url = this.url.replace ('.', RtfBookmark.replaceCharacter); - this.url = this.url.replace (' ', RtfBookmark.replaceCharacter); - } - - public boolean isEmpty () - { - return false; - } + ////////////////////////////////////////////////// + // @@ Members + ////////////////////////////////////////////////// + + /** The url of the image */ + protected String url = null; + + /** RtfText */ + protected RtfText mText = null; + + ////////////////////////////////////////////////// + // @@ Construction + ////////////////////////////////////////////////// + + + /** + * Default constructor. + * + * @param container a RtfContainer value + * @param writer a Writer value + * @param attributes a RtfAttributes value + */ + public RtfHyperLink (IRtfTextContainer parent, Writer writer, String str, RtfAttributes attr) + throws IOException + { + super ((RtfContainer) parent, writer, attr); + new RtfText (this, writer, str, attr); + } + + + ////////////////////////////////////////////////// + // @@ RtfElement implementation + ////////////////////////////////////////////////// + + /** + * Writes the RTF content to m_writer. + * + * @exception IOException On error + */ + public void writeRtfPrefix () throws IOException + { + super.writeGroupMark (true); + super.writeControlWord ("field"); + + super.writeGroupMark (true); + super.writeStarControlWord ("fldinst"); + + m_writer.write ("HYPERLINK \"" + url + "\" "); + super.writeGroupMark (false); + + super.writeGroupMark (true); + super.writeControlWord ("fldrslt"); + + // start a group for this paragraph and write our own attributes if needed + if (m_attrib != null && m_attrib.isSet ("cs")) + { + writeGroupMark (true); + writeAttributes(m_attrib, new String [] {"cs"}); + } + } + + /** + * Writes the RTF content to m_writer. + * + * @exception IOException On error + */ + public void writeRtfSuffix () throws IOException + { + if (m_attrib != null && m_attrib.isSet ("cs")) + { + writeGroupMark (false); + } + super.writeGroupMark (false); + super.writeGroupMark (false); + } + + + ////////////////////////////////////////////////// + // @@ IRtfContainer implementation + ////////////////////////////////////////////////// + + /** close current text run if any and start a new one with default attributes + * @param str if not null, added to the RtfText created + */ + public RtfText newText (String str) throws IOException { + return newText (str,null); + } + + /** close current text run if any and start a new one + * @param str if not null, added to the RtfText created + */ + public RtfText newText (String str,RtfAttributes attr) throws IOException + { + closeAll (); + mText = new RtfText (this, m_writer, str, attr); + return mText; + } + + /** IRtfTextContainer requirement: return a copy of our attributes */ + public RtfAttributes getTextContainerAttributes() + { + if (m_attrib == null) return null; + return (RtfAttributes) this.m_attrib.clone (); + } + + + /** add a line break */ + public void newLineBreak () throws IOException + { + new RtfLineBreak (this, m_writer); + } + + + ////////////////////////////////////////////////// + // @@ Common container methods + ////////////////////////////////////////////////// + + private void closeCurrentText () throws IOException + { + if (mText != null) mText.close (); + } + + private void closeAll () throws IOException + { + closeCurrentText(); + } + + + ////////////////////////////////////////////////// + // @@ Member access + ////////////////////////////////////////////////// + + /** + * Sets the url of the external link. + * + * @param url Link url like "http://..." + */ + public void setExternalURL (String url) + { + this.url = url; + } + + /** + * Sets the url of the external link. + * + * @param jumpTo Name of the text mark + */ + public void setInternalURL (String jumpTo) + { + int now = jumpTo.length (); + int max = RtfBookmark.maxBookmarkLength; + this.url = "#" + jumpTo.substring (0, now > max ? max : now); + this.url = this.url.replace ('.', RtfBookmark.replaceCharacter); + this.url = this.url.replace (' ', RtfBookmark.replaceCharacter); + } + + public boolean isEmpty () + { + return false; + } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfJforCmd.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfJforCmd.java index cc466654b..72743bd18 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfJforCmd.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfJforCmd.java @@ -65,52 +65,52 @@ import java.util.*; import java.io.IOException; /* - * RtfJforCmd process "jfor-cmd" + * RtfJforCmd process "jfor-cmd" * */ public class RtfJforCmd extends RtfContainer { - private final String PARA_KEEP_ON ="para-keep:on"; - private final String PARA_KEEP_OFF ="para-keep:off"; + private final String PARA_KEEP_ON ="para-keep:on"; + private final String PARA_KEEP_OFF ="para-keep:off"; - private final RtfAttributes m_attrib; - private ParagraphKeeptogetherContext m_paragraphKeeptogetherContext; + private final RtfAttributes m_attrib; + private ParagraphKeeptogetherContext m_paragraphKeeptogetherContext; - RtfJforCmd(RtfContainer parent, Writer w, RtfAttributes attrs) throws IOException { - super((RtfContainer)parent,w); - m_attrib = attrs; - m_paragraphKeeptogetherContext=ParagraphKeeptogetherContext.getInstance(); - } + RtfJforCmd(RtfContainer parent, Writer w, RtfAttributes attrs) throws IOException { + super((RtfContainer)parent,w); + m_attrib = attrs; + m_paragraphKeeptogetherContext=ParagraphKeeptogetherContext.getInstance(); + } - public boolean isEmpty() { - return true; - } + public boolean isEmpty() { + return true; + } - public void process() { + public void process() { - //Execute all jfor-cmd commands - //TODO create one class for each jfor command ? + //Execute all jfor-cmd commands + //TODO create one class for each jfor command ? - for(Iterator it = m_attrib.nameIterator(); it.hasNext(); ) { - final String cmd = (String)it.next(); + for(Iterator it = m_attrib.nameIterator(); it.hasNext(); ) { + final String cmd = (String)it.next(); - if (cmd.equals(PARA_KEEP_ON)) { - m_paragraphKeeptogetherContext.KeepTogetherOpen(); - }else if (cmd.equals(PARA_KEEP_OFF)) { - m_paragraphKeeptogetherContext.KeepTogetherClose(); - }else { -// this.getRtfFile ().getLog ().logInfo ("JFOR-CMD ignored, command not recognised:"+cmd); - } + if (cmd.equals(PARA_KEEP_ON)) { + m_paragraphKeeptogetherContext.KeepTogetherOpen(); + }else if (cmd.equals(PARA_KEEP_OFF)) { + m_paragraphKeeptogetherContext.KeepTogetherClose(); + }else { +// this.getRtfFile ().getLog ().logInfo ("JFOR-CMD ignored, command not recognised:"+cmd); + } - } + } - } + } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfListItem.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfListItem.java index d3f8a653d..2577f21fd 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfListItem.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfListItem.java @@ -86,15 +86,15 @@ implements IRtfParagraphContainer { if(m_parentList.isBulletedList()) { writeGroupMark(true); writeControlWord("pntext"); - writeControlWord("f" + RtfFontManager.getInstance().getFontNumber("Symbol")); + writeControlWord("f" + RtfFontManager.getInstance().getFontNumber("Symbol")); writeControlWord("'b7"); writeControlWord("tab"); writeGroupMark(false); }else{ - writeGroupMark(true); - writeControlWord("pntext"); - writeGroupMark(false); - } + writeGroupMark(true); + writeControlWord("pntext"); + writeGroupMark(false); + } } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfListTable.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfListTable.java index 9369a0b0c..5fe03d8e0 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfListTable.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfListTable.java @@ -99,12 +99,12 @@ public class RtfListTable extends RtfContainer{ public static final String LIST_NUMBER = "ls"; public static final String [] LIST_TABLE_ATTR = { - LIST_TABLE, LIST, LIST_TEMPLATE_ID, - LIST_NUMBER_TYPE, LIST_JUSTIFICATION, LIST_FOLLOWING_CHAR, - LIST_START_AT, LIST_SPACE, LIST_INDENT, - LIST_TEXT_FORM, LIST_NUM_POSITION, LIST_ID, - LIST_OVR_TABLE, LIST_OVR, LIST_OVR_COUNT, - LIST_NUMBER, LIST_LEVEL + LIST_TABLE, LIST, LIST_TEMPLATE_ID, + LIST_NUMBER_TYPE, LIST_JUSTIFICATION, LIST_FOLLOWING_CHAR, + LIST_START_AT, LIST_SPACE, LIST_INDENT, + LIST_TEXT_FORM, LIST_NUM_POSITION, LIST_ID, + LIST_OVR_TABLE, LIST_OVR, LIST_OVR_COUNT, + LIST_NUMBER, LIST_LEVEL }; /**RtfListTable Constructor: sets the number of the list, and allocates diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfNull.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfNull.java index 4f99e0c8a..da1ece236 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfNull.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfNull.java @@ -68,7 +68,7 @@ import java.io.IOException; public class RtfNull extends RtfContainer{ - RtfNull(RtfPage parent, Writer w) throws IOException { - super((RtfContainer)parent,w); - } + RtfNull(RtfPage parent, Writer w) throws IOException { + super((RtfContainer)parent,w); + } } \ No newline at end of file diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPage.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPage.java index c02af9849..a4a23cd16 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPage.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPage.java @@ -63,39 +63,39 @@ import java.io.*; import java.util.*; import java.io.IOException; /** Specifies rtf control words. Is the container for page attributes. - * Overrides okToWriteRtf. + * Overrides okToWriteRtf. * @author Christopher Scott, scottc@westinghouse.com */ public class RtfPage extends RtfContainer{ - private final RtfAttributes m_attrib; + private final RtfAttributes m_attrib; - /**RtfPage attributes*/ - public final static String PAGE_WIDTH = "paperw"; - public final static String PAGE_HEIGHT = "paperh"; + /**RtfPage attributes*/ + public final static String PAGE_WIDTH = "paperw"; + public final static String PAGE_HEIGHT = "paperh"; - public final static String MARGIN_TOP = "margt"; - public final static String MARGIN_BOTTOM = "margb"; - public final static String MARGIN_LEFT = "margl"; - public final static String MARGIN_RIGHT = "margr"; + public final static String MARGIN_TOP = "margt"; + public final static String MARGIN_BOTTOM = "margb"; + public final static String MARGIN_LEFT = "margl"; + public final static String MARGIN_RIGHT = "margr"; - public final static String[] PAGE_ATTR = new String[]{ - PAGE_WIDTH, PAGE_HEIGHT, MARGIN_TOP, MARGIN_BOTTOM, - MARGIN_LEFT, MARGIN_RIGHT - }; + public final static String[] PAGE_ATTR = new String[]{ + PAGE_WIDTH, PAGE_HEIGHT, MARGIN_TOP, MARGIN_BOTTOM, + MARGIN_LEFT, MARGIN_RIGHT + }; - /** RtfPage creates new page attributes with the parent container, the writer - and the attributes*/ - RtfPage(RtfPageArea parent, Writer w, RtfAttributes attrs) throws IOException { - super((RtfContainer)parent,w); - m_attrib = attrs; - } + /** RtfPage creates new page attributes with the parent container, the writer + and the attributes*/ + RtfPage(RtfPageArea parent, Writer w, RtfAttributes attrs) throws IOException { + super((RtfContainer)parent,w); + m_attrib = attrs; + } - /** RtfPage writes the attributes the attributes contained in the string - PAGE_ATTR, if not null */ - protected void writeRtfContent() throws IOException { - writeAttributes(m_attrib, PAGE_ATTR); + /** RtfPage writes the attributes the attributes contained in the string + PAGE_ATTR, if not null */ + protected void writeRtfContent() throws IOException { + writeAttributes(m_attrib, PAGE_ATTR); if (m_attrib != null) { @@ -108,19 +108,19 @@ extends RtfContainer{ writeControlWord( "landscape" ); } } - } + } - /** RtfPage - attributes accessor */ - public RtfAttributes getAttributes(){ - return m_attrib; - } + /** RtfPage - attributes accessor */ + public RtfAttributes getAttributes(){ + return m_attrib; + } - /** RtfPage - is overwritten here because page attributes have no content - only attributes. RtfContainer is defined not to write when empty. - Therefore must make this true to print.*/ - protected boolean okToWriteRtf() - { - return true; - } + /** RtfPage - is overwritten here because page attributes have no content + only attributes. RtfContainer is defined not to write when empty. + Therefore must make this true to print.*/ + protected boolean okToWriteRtf() + { + return true; + } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageArea.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageArea.java index 45f372658..7cd2f0a00 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageArea.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageArea.java @@ -81,15 +81,15 @@ extends RtfContainer public RtfPage newPage(RtfAttributes attr) throws IOException { if(m_currentPage != null){ - m_currentPage.close(); + m_currentPage.close(); } m_currentPage = new RtfPage(this,m_writer,attr); return m_currentPage; } - protected boolean okToWriteRtf() - { - return true; - } + protected boolean okToWriteRtf() + { + return true; + } } \ No newline at end of file diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageNumber.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageNumber.java index 571482a67..73296ce71 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageNumber.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageNumber.java @@ -65,12 +65,12 @@ import java.io.IOException; public class RtfPageNumber extends RtfContainer { /** RtfText attributes: fields */ - //must be carefull of group markings and star control - //ie page field: - // "{\field {\*\fldinst {PAGE}} {\fldrslt}}" - public static String RTF_FIELD = "field"; - public static String RTF_FIELD_PAGE = "fldinst { PAGE }"; - public static String RTF_FIELD_RESULT = "fldrslt"; + //must be carefull of group markings and star control + //ie page field: + // "{\field {\*\fldinst {PAGE}} {\fldrslt}}" + public static String RTF_FIELD = "field"; + public static String RTF_FIELD_PAGE = "fldinst { PAGE }"; + public static String RTF_FIELD_RESULT = "fldrslt"; /** Create an RTF paragraph as a child of given container with default attributes */ RtfPageNumber(IRtfPageNumberContainer parent, Writer w) throws IOException @@ -113,5 +113,3 @@ public class RtfPageNumber extends RtfContainer return false; } } - - \ No newline at end of file diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java index 618cb004e..b1598025c 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java @@ -68,15 +68,15 @@ import java.io.IOException; public class RtfPageNumberCitation extends RtfContainer { - // Page field : - // "{\field {\*\fldinst {PAGEREF xx}} {\fldrslt}}" where xx represents the - // 'id' of the referenced page - public static final String RTF_FIELD = "field"; - public static final String RTF_FIELD_PAGEREF_MODEL = "fldinst { PAGEREF }"; - public static final String RTF_FIELD_RESULT = "fldrslt"; + // Page field : + // "{\field {\*\fldinst {PAGEREF xx}} {\fldrslt}}" where xx represents the + // 'id' of the referenced page + public static final String RTF_FIELD = "field"; + public static final String RTF_FIELD_PAGEREF_MODEL = "fldinst { PAGEREF }"; + public static final String RTF_FIELD_RESULT = "fldrslt"; - // The 'id' of the referenced page - private String id = null; + // The 'id' of the referenced page + private String id = null; /** Create an RTF page number citation as a child of given container with default attributes */ RtfPageNumberCitation (IRtfPageNumberCitationContainer parent, Writer w, String id) throws IOException diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfParagraph.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfParagraph.java index bb30c76aa..5e5e1e758 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfParagraph.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfParagraph.java @@ -77,7 +77,7 @@ IRtfPageNumberContainer,IRtfPageNumberCitationContainer { private RtfPageNumber m_pageNumber; private RtfPageNumberCitation m_pageNumberCitation; // Line added by Boris POUDEROUS on 2002/07/09 private boolean m_keepn=false; - private boolean m_resetProperties=false; + private boolean m_resetProperties=false; /* needed for importing Rtf into FrameMaker FrameMaker is not as forgiving as word in rtf @@ -106,12 +106,12 @@ IRtfPageNumberContainer,IRtfPageNumberCitationContainer { /** Set the keepn attribute for this paragraph */ public void setKeepn() { - this.m_keepn=true; + this.m_keepn=true; } /** Force reset properties */ public void setResetProperties() { - this.m_resetProperties=true; + this.m_resetProperties=true; } /** IRtfTextContainer requirement: return a copy of our attributes */ @@ -131,9 +131,9 @@ IRtfPageNumberContainer,IRtfPageNumberCitationContainer { } //Reset paragraph properties if needed - if(m_resetProperties) { - writeControlWord("pard"); - } + if(m_resetProperties) { + writeControlWord("pard"); + } // do not write text attributes here, they are handled // by RtfText diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfParagraphKeepTogether.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfParagraphKeepTogether.java index bb6458a1d..660a5b553 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfParagraphKeepTogether.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfParagraphKeepTogether.java @@ -66,45 +66,45 @@ import java.io.IOException; public class RtfParagraphKeepTogether extends RtfContainer{ - public static final int STATUS_NULL=0; - public static final int STATUS_OPEN_PARAGRAPH=1; - public static final int STATUS_CLOSE_PARAGRAPH=2; - private int m_status =STATUS_NULL; + public static final int STATUS_NULL=0; + public static final int STATUS_OPEN_PARAGRAPH=1; + public static final int STATUS_CLOSE_PARAGRAPH=2; + private int m_status =STATUS_NULL; - /** RtfParagraphKeepTogether*/ - RtfParagraphKeepTogether(IRtfParagraphContainer parent, Writer w) throws IOException { - super((RtfContainer)parent,w); - } + /** RtfParagraphKeepTogether*/ + RtfParagraphKeepTogether(IRtfParagraphContainer parent, Writer w) throws IOException { + super((RtfContainer)parent,w); + } - protected void writeRtfContent() throws IOException { + protected void writeRtfContent() throws IOException { - //First reet paragraph properties - // create a new one with keepn - if (m_status==STATUS_OPEN_PARAGRAPH) { - writeControlWord("pard"); - writeControlWord("par"); - writeControlWord("keepn"); - writeGroupMark(true); - m_status = STATUS_NULL; - } + //First reet paragraph properties + // create a new one with keepn + if (m_status==STATUS_OPEN_PARAGRAPH) { + writeControlWord("pard"); + writeControlWord("par"); + writeControlWord("keepn"); + writeGroupMark(true); + m_status = STATUS_NULL; + } - if (m_status == STATUS_CLOSE_PARAGRAPH) { - writeGroupMark(false); - m_status = STATUS_NULL; - } + if (m_status == STATUS_CLOSE_PARAGRAPH) { + writeGroupMark(false); + m_status = STATUS_NULL; + } - } + } - public void setStatus(int status) { - m_status = status; - } + public void setStatus(int status) { + m_status = status; + } - /** true if this element would generate no "useful" RTF content */ + /** true if this element would generate no "useful" RTF content */ public boolean isEmpty() { return false; diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfSection.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfSection.java index 4cb29d280..f42a65f2d 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfSection.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfSection.java @@ -80,127 +80,127 @@ implements IRtfAfterContainer, IRtfJforCmdContainer { - private RtfParagraph m_paragraph; - private RtfTable m_table; - private RtfList m_list; - private RtfExternalGraphic m_externalGraphic; - private RtfBefore m_before; + private RtfParagraph m_paragraph; + private RtfTable m_table; + private RtfList m_list; + private RtfExternalGraphic m_externalGraphic; + private RtfBefore m_before; private RtfAfter m_after; private RtfJforCmd m_jforCmd; - /** Create an RTF container as a child of given container */ - RtfSection(RtfDocumentArea parent, Writer w) throws IOException { - super(parent,w); - } - - /** start a new external graphic after closing current paragraph, list and table */ - public RtfExternalGraphic newImage() throws IOException { - closeAll(); - m_externalGraphic = new RtfExternalGraphic(this,m_writer); - return m_externalGraphic; - } - - /** start a new paragraph after closing current paragraph, list and table */ - public RtfParagraph newParagraph(RtfAttributes attrs) throws IOException { - closeAll(); - m_paragraph = new RtfParagraph(this,m_writer,attrs); - return m_paragraph; - } - - /** close current paragraph if any and start a new one with default attributes */ - public RtfParagraph newParagraph() throws IOException { - return newParagraph(null); - } - - /** close current paragraph if any and start a new one */ - public RtfParagraphKeepTogether newParagraphKeepTogether() throws IOException { - return new RtfParagraphKeepTogether(this,m_writer); - } - - /** start a new table after closing current paragraph, list and table + /** Create an RTF container as a child of given container */ + RtfSection(RtfDocumentArea parent, Writer w) throws IOException { + super(parent,w); + } + + /** start a new external graphic after closing current paragraph, list and table */ + public RtfExternalGraphic newImage() throws IOException { + closeAll(); + m_externalGraphic = new RtfExternalGraphic(this,m_writer); + return m_externalGraphic; + } + + /** start a new paragraph after closing current paragraph, list and table */ + public RtfParagraph newParagraph(RtfAttributes attrs) throws IOException { + closeAll(); + m_paragraph = new RtfParagraph(this,m_writer,attrs); + return m_paragraph; + } + + /** close current paragraph if any and start a new one with default attributes */ + public RtfParagraph newParagraph() throws IOException { + return newParagraph(null); + } + + /** close current paragraph if any and start a new one */ + public RtfParagraphKeepTogether newParagraphKeepTogether() throws IOException { + return new RtfParagraphKeepTogether(this,m_writer); + } + + /** start a new table after closing current paragraph, list and table * @param tc Table context used for number-columns-spanned attribute (added by Boris Poudérous on july 2002) */ - public RtfTable newTable(ITableColumnsInfo tc) throws IOException { - closeAll(); - m_table = new RtfTable(this,m_writer,tc); - return m_table; - } + public RtfTable newTable(ITableColumnsInfo tc) throws IOException { + closeAll(); + m_table = new RtfTable(this,m_writer,tc); + return m_table; + } - /** start a new table after closing current paragraph, list and table + /** start a new table after closing current paragraph, list and table * @param tc Table context used for number-columns-spanned attribute (added by Boris Poudérous on july 2002) */ - public RtfTable newTable(RtfAttributes attrs, ITableColumnsInfo tc) throws IOException - { - closeAll(); - m_table = new RtfTable(this,m_writer, attrs, tc); - return m_table; - } - - /** start a new list after closing current paragraph, list and table */ - public RtfList newList(RtfAttributes attrs) throws IOException { - closeAll(); - m_list = new RtfList(this,m_writer, attrs); - return m_list; - } + public RtfTable newTable(RtfAttributes attrs, ITableColumnsInfo tc) throws IOException + { + closeAll(); + m_table = new RtfTable(this,m_writer, attrs, tc); + return m_table; + } + + /** start a new list after closing current paragraph, list and table */ + public RtfList newList(RtfAttributes attrs) throws IOException { + closeAll(); + m_list = new RtfList(this,m_writer, attrs); + return m_list; + } /** IRtfBeforeContainer */ - public RtfBefore newBefore(RtfAttributes attrs) throws IOException { - closeAll(); - m_before = new RtfBefore(this,m_writer,attrs); - return m_before; - } + public RtfBefore newBefore(RtfAttributes attrs) throws IOException { + closeAll(); + m_before = new RtfBefore(this,m_writer,attrs); + return m_before; + } /** IRtfAfterContainer */ - public RtfAfter newAfter(RtfAttributes attrs) throws IOException { - closeAll(); - m_after = new RtfAfter(this,m_writer,attrs); - return m_after; - } - - - public RtfJforCmd newJforCmd(RtfAttributes attrs) throws IOException { - m_jforCmd = new RtfJforCmd(this,m_writer,attrs); - return m_jforCmd; - } - - - - /** can be overridden to write RTF prefix code, what comes before our children */ - protected void writeRtfPrefix() throws IOException { - writeControlWord("sectd"); - } - - /** can be overridden to write RTF suffix code, what comes after our children */ - protected void writeRtfSuffix() throws IOException { - writeControlWord("sect"); - } - - private void closeCurrentTable() throws IOException { - if(m_table != null) m_table.close(); - } - - private void closeCurrentParagraph() throws IOException { - if(m_paragraph!=null) m_paragraph.close(); - } - - private void closeCurrentList() throws IOException { - if(m_list!=null) m_list.close(); - } - - private void closeCurrentExternalGraphic() throws IOException { - if(m_externalGraphic!=null) m_externalGraphic.close(); - } - - private void closeCurrentBefore() throws IOException { - if(m_before!=null) m_before.close(); - } - - private void closeAll() - throws IOException { - closeCurrentTable(); - closeCurrentParagraph(); - closeCurrentList(); - closeCurrentExternalGraphic(); - closeCurrentBefore(); - } + public RtfAfter newAfter(RtfAttributes attrs) throws IOException { + closeAll(); + m_after = new RtfAfter(this,m_writer,attrs); + return m_after; + } + + + public RtfJforCmd newJforCmd(RtfAttributes attrs) throws IOException { + m_jforCmd = new RtfJforCmd(this,m_writer,attrs); + return m_jforCmd; + } + + + + /** can be overridden to write RTF prefix code, what comes before our children */ + protected void writeRtfPrefix() throws IOException { + writeControlWord("sectd"); + } + + /** can be overridden to write RTF suffix code, what comes after our children */ + protected void writeRtfSuffix() throws IOException { + writeControlWord("sect"); + } + + private void closeCurrentTable() throws IOException { + if(m_table != null) m_table.close(); + } + + private void closeCurrentParagraph() throws IOException { + if(m_paragraph!=null) m_paragraph.close(); + } + + private void closeCurrentList() throws IOException { + if(m_list!=null) m_list.close(); + } + + private void closeCurrentExternalGraphic() throws IOException { + if(m_externalGraphic!=null) m_externalGraphic.close(); + } + + private void closeCurrentBefore() throws IOException { + if(m_before!=null) m_before.close(); + } + + private void closeAll() + throws IOException { + closeCurrentTable(); + closeCurrentParagraph(); + closeCurrentList(); + closeCurrentExternalGraphic(); + closeCurrentBefore(); + } } \ No newline at end of file diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfStyleSheetTable.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfStyleSheetTable.java index 794d0ab0b..d274be636 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfStyleSheetTable.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfStyleSheetTable.java @@ -70,220 +70,220 @@ import java.util.Iterator; */ public class RtfStyleSheetTable { - ////////////////////////////////////////////////// - // @@ Symbolic constants - ////////////////////////////////////////////////// - - /** Start index number for the stylesheet reference table */ - private static int startIndex = 15; + ////////////////////////////////////////////////// + // @@ Symbolic constants + ////////////////////////////////////////////////// + + /** Start index number for the stylesheet reference table */ + private static int startIndex = 15; - /** OK status value for attribute handling */ - public static int STATUS_OK = 0; - /** Status value for attribute handling, if the stylesheet not found and - * the stylesheet set to the default stylesheet */ - public static int STATUS_DEFAULT = 1; - - /** Standard style name */ - private static String STANDARD_STYLE = "Standard"; - - - ////////////////////////////////////////////////// - // @@ Singleton - ////////////////////////////////////////////////// - - /** Singelton instance */ - private static RtfStyleSheetTable instance = null; - - - ////////////////////////////////////////////////// - // @@ Members - ////////////////////////////////////////////////// - - - /** Table of styles */ - private Hashtable styles = null; - - /** Used, style attributes to this vector */ - private Hashtable attrTable = null; - - /** Used, style names to this vector */ - private Vector nameTable = null; - - /** Default style */ - private String defaultStyleName = STANDARD_STYLE; - - - ////////////////////////////////////////////////// - // @@ Construction - ////////////////////////////////////////////////// - - /** - * Constructor. - */ - private RtfStyleSheetTable () - { - styles = new Hashtable (); - attrTable = new Hashtable (); - nameTable = new Vector (); - } - - /** - * Singelton. - * - * @return The instance of RtfStyleSheetTable - */ - public static RtfStyleSheetTable getInstance () - { - if (instance == null) - { - instance = new RtfStyleSheetTable (); - } - - return instance; - } - - - ////////////////////////////////////////////////// - // @@ Member access - ////////////////////////////////////////////////// - - /** - * Sets the default style. - * @param styleName Name of the default style, defined in the stylesheet - */ - public void setDefaultStyle (String styleName) - { - this.defaultStyleName = styleName; - } - - /** - * Gets the name of the default style. - * @return Default style name. - */ - public String getDefaultStyleName () - { - if (attrTable.get (defaultStyleName) != null) - return defaultStyleName; - - if (attrTable.get (STANDARD_STYLE) != null) - { - defaultStyleName = STANDARD_STYLE; - return defaultStyleName; - } - - return null; - } - - - ////////////////////////////////////////////////// - // @@ Public methods - ////////////////////////////////////////////////// - - /** - * Adds a style to the table. - * @param name Name of style to add - * @param attrs Rtf attributes which defines the style - */ - public void addStyle (String name, RtfAttributes attrs) - { - nameTable.addElement (name); - if (attrs != null) - attrTable.put (name, attrs); - styles.put (name, new Integer (nameTable.size () - 1 + startIndex)); - } - - /** - * Adds the style attributes to the given attributes. - * @param name Name of style, of which the attributes will copied to attr - * @param attrs Default rtf attributes - * @return Status value - */ - public int addStyleToAttributes (String name, RtfAttributes attr) - { - // Sets status to ok - int status = STATUS_OK; - - // Gets the style number from table - Integer style = (Integer) styles.get (name); - - if (style == null && !name.equals (defaultStyleName)) - { - // If style not found, and style was not the default style, try the default style - name = defaultStyleName; - style = (Integer) styles.get (name); - // set status for default style setting - status = STATUS_DEFAULT; - } - - // Returns the status for invalid styles - if (style == null) - return status; - - // Adds the attributes to default attributes, if not available in default attributes - attr.set ("cs", style.intValue ()); - - Object o = attrTable.get (name); - if (o != null) - { - RtfAttributes rtfAttr = (RtfAttributes) o; - - for (Iterator names = rtfAttr.nameIterator (); names.hasNext ();) - { - String attrName = (String) names.next (); - if (! attr.isSet (attrName)) - { - Integer i = (Integer) rtfAttr.getValue (attrName); - if (i == null) - attr.set (attrName); - else - attr.set (attrName, i.intValue ()); - } - } - } - return status; - } - - /** - * Writes the rtf style sheet table. - * @param header Rtf header is the parent - * @throws IOException On write error - */ - public void writeStyleSheet (RtfHeader header) throws IOException - { - if (styles == null || styles.size () == 0) - { - return; - } - header.writeGroupMark (true); - header.writeControlWord ("stylesheet"); - - int number = nameTable.size (); - for (int i = 0; i < number; i++) - { - String name = (String) nameTable.elementAt (i); - header.writeGroupMark (true); - header.writeControlWord ("*\\" + this.getRtfStyleReference (name)); - - Object o = attrTable.get (name); - if (o != null) - { - header.writeAttributes ((RtfAttributes) o, RtfText.ATTR_NAMES); - header.writeAttributes ((RtfAttributes) o, RtfText.ALIGNMENT); - } - - header.write (name + ";"); - header.writeGroupMark (false); - } - header.writeGroupMark (false); - } - - /** - * Gets the rtf style reference from the table. - * @param name Name of Style - * @return Rtf attribute of the style reference - */ - private String getRtfStyleReference (String name) - { - return "cs" + styles.get (name).toString (); - } + /** OK status value for attribute handling */ + public static int STATUS_OK = 0; + /** Status value for attribute handling, if the stylesheet not found and + * the stylesheet set to the default stylesheet */ + public static int STATUS_DEFAULT = 1; + + /** Standard style name */ + private static String STANDARD_STYLE = "Standard"; + + + ////////////////////////////////////////////////// + // @@ Singleton + ////////////////////////////////////////////////// + + /** Singelton instance */ + private static RtfStyleSheetTable instance = null; + + + ////////////////////////////////////////////////// + // @@ Members + ////////////////////////////////////////////////// + + + /** Table of styles */ + private Hashtable styles = null; + + /** Used, style attributes to this vector */ + private Hashtable attrTable = null; + + /** Used, style names to this vector */ + private Vector nameTable = null; + + /** Default style */ + private String defaultStyleName = STANDARD_STYLE; + + + ////////////////////////////////////////////////// + // @@ Construction + ////////////////////////////////////////////////// + + /** + * Constructor. + */ + private RtfStyleSheetTable () + { + styles = new Hashtable (); + attrTable = new Hashtable (); + nameTable = new Vector (); + } + + /** + * Singelton. + * + * @return The instance of RtfStyleSheetTable + */ + public static RtfStyleSheetTable getInstance () + { + if (instance == null) + { + instance = new RtfStyleSheetTable (); + } + + return instance; + } + + + ////////////////////////////////////////////////// + // @@ Member access + ////////////////////////////////////////////////// + + /** + * Sets the default style. + * @param styleName Name of the default style, defined in the stylesheet + */ + public void setDefaultStyle (String styleName) + { + this.defaultStyleName = styleName; + } + + /** + * Gets the name of the default style. + * @return Default style name. + */ + public String getDefaultStyleName () + { + if (attrTable.get (defaultStyleName) != null) + return defaultStyleName; + + if (attrTable.get (STANDARD_STYLE) != null) + { + defaultStyleName = STANDARD_STYLE; + return defaultStyleName; + } + + return null; + } + + + ////////////////////////////////////////////////// + // @@ Public methods + ////////////////////////////////////////////////// + + /** + * Adds a style to the table. + * @param name Name of style to add + * @param attrs Rtf attributes which defines the style + */ + public void addStyle (String name, RtfAttributes attrs) + { + nameTable.addElement (name); + if (attrs != null) + attrTable.put (name, attrs); + styles.put (name, new Integer (nameTable.size () - 1 + startIndex)); + } + + /** + * Adds the style attributes to the given attributes. + * @param name Name of style, of which the attributes will copied to attr + * @param attrs Default rtf attributes + * @return Status value + */ + public int addStyleToAttributes (String name, RtfAttributes attr) + { + // Sets status to ok + int status = STATUS_OK; + + // Gets the style number from table + Integer style = (Integer) styles.get (name); + + if (style == null && !name.equals (defaultStyleName)) + { + // If style not found, and style was not the default style, try the default style + name = defaultStyleName; + style = (Integer) styles.get (name); + // set status for default style setting + status = STATUS_DEFAULT; + } + + // Returns the status for invalid styles + if (style == null) + return status; + + // Adds the attributes to default attributes, if not available in default attributes + attr.set ("cs", style.intValue ()); + + Object o = attrTable.get (name); + if (o != null) + { + RtfAttributes rtfAttr = (RtfAttributes) o; + + for (Iterator names = rtfAttr.nameIterator (); names.hasNext ();) + { + String attrName = (String) names.next (); + if (! attr.isSet (attrName)) + { + Integer i = (Integer) rtfAttr.getValue (attrName); + if (i == null) + attr.set (attrName); + else + attr.set (attrName, i.intValue ()); + } + } + } + return status; + } + + /** + * Writes the rtf style sheet table. + * @param header Rtf header is the parent + * @throws IOException On write error + */ + public void writeStyleSheet (RtfHeader header) throws IOException + { + if (styles == null || styles.size () == 0) + { + return; + } + header.writeGroupMark (true); + header.writeControlWord ("stylesheet"); + + int number = nameTable.size (); + for (int i = 0; i < number; i++) + { + String name = (String) nameTable.elementAt (i); + header.writeGroupMark (true); + header.writeControlWord ("*\\" + this.getRtfStyleReference (name)); + + Object o = attrTable.get (name); + if (o != null) + { + header.writeAttributes ((RtfAttributes) o, RtfText.ATTR_NAMES); + header.writeAttributes ((RtfAttributes) o, RtfText.ALIGNMENT); + } + + header.write (name + ";"); + header.writeGroupMark (false); + } + header.writeGroupMark (false); + } + + /** + * Gets the rtf style reference from the table. + * @param name Name of Style + * @return Rtf attribute of the style reference + */ + private String getRtfStyleReference (String name) + { + return "cs" + styles.get (name).toString (); + } } \ No newline at end of file diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfTable.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfTable.java index 9d9b37a35..2b9273b73 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfTable.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfTable.java @@ -82,15 +82,15 @@ public class RtfTable extends RtfContainer m_table_context = tc; } - /** Create an RTF element as a child of given container + /** Create an RTF element as a child of given container * Modified by Boris Poudérous in order to process 'number-columns-spanned' attribute */ RtfTable(IRtfTableContainer parent, Writer w, RtfAttributes attrs, ITableColumnsInfo tc) throws IOException - { - super((RtfContainer)parent,w,attrs); + { + super((RtfContainer)parent,w,attrs); // Line added by Boris Poudérous on 07/22/2002 m_table_context = tc; - } + } /** close current row if any and start a new one */ public RtfTableRow newTableRow() throws IOException @@ -135,7 +135,7 @@ public class RtfTable extends RtfContainer public boolean isHighestRow(int id) { - return (highestRow == id) ? true : false; + return (highestRow == id) ? true : false; } /** Added by Boris Poudérous on 07/22/2002 */ diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfTableCell.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfTableCell.java index 871ea5d9f..6a507ba9f 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfTableCell.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfTableCell.java @@ -75,7 +75,7 @@ implements IRtfParagraphContainer,IRtfListContainer,IRtfTableContainer,IRtfExter private RtfExternalGraphic m_externalGraphic; private final RtfTableRow m_parentRow; private boolean set_center; - private boolean set_right; + private boolean set_right; private int id; public static final int DEFAULT_CELL_WIDTH = 2000; @@ -165,20 +165,20 @@ implements IRtfParagraphContainer,IRtfListContainer,IRtfTableContainer,IRtfExter m_paragraph = new RtfParagraph(this,m_writer,attrs); if(m_paragraph.m_attrib.isSet("qc")) - { - set_center=true; + { + set_center=true; attrs.set("qc"); - } - else if(m_paragraph.m_attrib.isSet("qr")) - { - set_right=true; + } + else if(m_paragraph.m_attrib.isSet("qr")) + { + set_right=true; attrs.set("qr"); - } + } else { attrs.set("ql"); } - attrs.set("intbl"); + attrs.set("intbl"); //lines modified by Chris Scott, Westinghouse @@ -256,10 +256,10 @@ implements IRtfParagraphContainer,IRtfListContainer,IRtfTableContainer,IRtfExter //these lines added by Chris Scott, Westinghouse //some attributes need to be writting before opening block - if(set_center) - { - writeControlWord("qc"); - } + if(set_center) + { + writeControlWord("qc"); + } else if (set_right) { writeControlWord("qr"); @@ -269,11 +269,11 @@ implements IRtfParagraphContainer,IRtfListContainer,IRtfTableContainer,IRtfExter writeControlWord("ql"); } - writeControlWord("cellx" + xPos); + writeControlWord("cellx" + xPos); writeControlWord( "ql" ); - return xPos; + return xPos; } @@ -284,9 +284,9 @@ implements IRtfParagraphContainer,IRtfListContainer,IRtfTableContainer,IRtfExter // but if is not here we generate invalid RTF for word97 if(set_center) - { - writeControlWord("qc"); - } + { + writeControlWord("qc"); + } else if (set_right) { writeControlWord("qr"); @@ -303,7 +303,7 @@ implements IRtfParagraphContainer,IRtfListContainer,IRtfTableContainer,IRtfExter //R.Marra this create useless paragraph //Seem working into Word97 with the "intbl" only -// writeControlWord("par"); +// writeControlWord("par"); } writeControlWord("cell"); diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfTemplate.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfTemplate.java index 0defc15ba..1d5492a47 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfTemplate.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfTemplate.java @@ -70,67 +70,67 @@ import java.io.File; public class RtfTemplate { - /** Singelton instance */ - private static RtfTemplate instance = null; - - private String templateFilePath = null; - - /** - * Constructor. - */ - private RtfTemplate () - { - - } - - - /** - * Singelton. - * - * @return The instance of RtfTemplate - */ - public static RtfTemplate getInstance () - { - if (instance == null) { - instance = new RtfTemplate(); - } - - return instance; - } - - - /** - *Set the template file and adjust tha path separator - * - *@param templateFilePath The full path of the template - **/ - public void setTemplateFilePath(String templateFilePath) throws IOException { - // no validity checks here - leave this to the RTF client - if(templateFilePath == null) { - this.templateFilePath = null; - } else { - this.templateFilePath = templateFilePath.trim(); - } - } - - /** - * Write the rtf template - * @param header Rtf header is the parent - * @throws IOException On write error - */ - public void writeTemplate (RtfHeader header) throws IOException - { - if (templateFilePath == null || templateFilePath.length() == 0) return; - - header.writeGroupMark (true); - header.writeControlWord ("template"); - header.writeRtfString(this.templateFilePath); - header.writeGroupMark (false); - - header.writeGroupMark (true); - header.writeControlWord ("linkstyles"); - header.writeGroupMark (false); - } + /** Singelton instance */ + private static RtfTemplate instance = null; + + private String templateFilePath = null; + + /** + * Constructor. + */ + private RtfTemplate () + { + + } + + + /** + * Singelton. + * + * @return The instance of RtfTemplate + */ + public static RtfTemplate getInstance () + { + if (instance == null) { + instance = new RtfTemplate(); + } + + return instance; + } + + + /** + *Set the template file and adjust tha path separator + * + *@param templateFilePath The full path of the template + **/ + public void setTemplateFilePath(String templateFilePath) throws IOException { + // no validity checks here - leave this to the RTF client + if(templateFilePath == null) { + this.templateFilePath = null; + } else { + this.templateFilePath = templateFilePath.trim(); + } + } + + /** + * Write the rtf template + * @param header Rtf header is the parent + * @throws IOException On write error + */ + public void writeTemplate (RtfHeader header) throws IOException + { + if (templateFilePath == null || templateFilePath.length() == 0) return; + + header.writeGroupMark (true); + header.writeControlWord ("template"); + header.writeRtfString(this.templateFilePath); + header.writeGroupMark (false); + + header.writeGroupMark (true); + header.writeControlWord ("linkstyles"); + header.writeGroupMark (false); + } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfText.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfText.java index 4a69b463d..b4d0433c7 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfText.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfText.java @@ -80,139 +80,139 @@ public class RtfText extends RtfElement private static final int CHAR_BOLD_START = 130; private static final int CHAR_BOLD_END = 131; - /** members */ - private String m_text; - private final RtfAttributes m_attr; - - - /** RtfText attributes: attribute names are RTF control word names to avoid additional mapping */ - public static final String ATTR_BOLD = "b"; - public static final String ATTR_ITALIC = "i"; - public static final String ATTR_UNDERLINE = "ul"; - public static final String ATTR_FONT_SIZE = "fs"; - public static final String ATTR_FONT_FAMILY = "f"; - public static final String ATTR_FONT_COLOR = "cf"; - public static final String ATTR_BACKGROUND_COLOR = "chcbpat"; // Added by Boris on 06/25//02 - - /** RtfText attributes: alignment attributes */ - public static String ALIGN_CENTER = "qc"; - public static String ALIGN_LEFT = "ql"; - public static String ALIGN_RIGHT = "qr"; - public static String ALIGN_JUSTIFIED = "qj"; - public static String ALIGN_DISTRIBUTED = "qd"; - - /** RtfText attributes: border attributes */ - //added by Chris Scott - public static String BDR_BOTTOM_SINGLE = "brdrb\\brsp40\\brdrs"; - public static String BDR_BOTTOM_DOUBLE = "brdrb\\brsp40\\brdrdb"; - public static String BDR_BOTTOM_EMBOSS = "brdrb\\brsp40\\brdremboss"; - public static String BDR_BOTTOM_DOTTED = "brdrb\\brsp40\\brdrdot"; - public static String BDR_BOTTOM_DASH = "brdrb\\brsp40\\brdrdash"; - - /** RtfText attributes: fields */ - //must be carefull of group markings and star control - //ie page field: - // "{\field {\*\fldinst {PAGE}} {\fldrslt}}" - public static String RTF_FIELD = "field"; - public static String RTF_FIELD_PAGE = "fldinst { PAGE }"; - public static String RTF_FIELD_RESULT = "fldrslt"; - - /**RtfText attributes: indentation attributes */ - //added by Chris Scott - public static String LEFT_INDENT_BODY = "li"; - public static String LEFT_INDENT_FIRST = "fi-"; - - public static String TAB_CENTER = "tqc\\tx"; - public static String TAB_RIGHT = "tqr\\tx"; - public static String TAB_LEADER_DOTS = "tldot"; - public static String TAB_LEADER_HYPHEN = "tlhyph"; - public static String TAB_LEADER_UNDER = "tlul"; - public static String TAB_LEADER_THICK = "tlth"; - public static String TAB_LEADER_EQUALS = "tleq"; - - /** Space before/after a paragraph */ - //these lines were added by Boris Pouderous - public static final String SPACE_BEFORE = "sb"; - public static final String SPACE_AFTER = "sa"; - - /** RtfText attributes: this must contain all allignment attributes names */ - public static String[] ALIGNMENT = new String [] - { - ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_JUSTIFIED, ALIGN_DISTRIBUTED - }; - - /** RtfText attributes:: this must contain all border attribute names*/ - //this line added by Chris Scott, Westinghouse - public static String[] BORDER = new String [] - { - BDR_BOTTOM_SINGLE,BDR_BOTTOM_DOUBLE,BDR_BOTTOM_EMBOSS,BDR_BOTTOM_DOTTED,BDR_BOTTOM_DASH - }; - - public static String[] INDENT = new String [] - { - LEFT_INDENT_BODY, LEFT_INDENT_FIRST - }; - - public static String[] TABS = new String [] - { - TAB_CENTER ,TAB_RIGHT,TAB_LEADER_DOTS,TAB_LEADER_HYPHEN,TAB_LEADER_UNDER, - TAB_LEADER_THICK,TAB_LEADER_EQUALS - }; - - - /** RtfText attributes: this must contain all attribute names */ - public static final String [] ATTR_NAMES = { - ATTR_BOLD, - ATTR_ITALIC, - ATTR_UNDERLINE, - ATTR_FONT_SIZE, - ATTR_FONT_FAMILY, - ATTR_FONT_COLOR, - ATTR_BACKGROUND_COLOR - }; - - /** Create an RtfText in given IRtfTextContainer. - * @param str optional initial text content - */ - RtfText(IRtfTextContainer parent,Writer w,String str,RtfAttributes attr) throws IOException - { - super((RtfContainer)parent,w); - m_text = str; - m_attr = attr; - } - - /** write our text to the RTF stream */ - public void writeRtfContent() throws IOException - { + /** members */ + private String m_text; + private final RtfAttributes m_attr; + + + /** RtfText attributes: attribute names are RTF control word names to avoid additional mapping */ + public static final String ATTR_BOLD = "b"; + public static final String ATTR_ITALIC = "i"; + public static final String ATTR_UNDERLINE = "ul"; + public static final String ATTR_FONT_SIZE = "fs"; + public static final String ATTR_FONT_FAMILY = "f"; + public static final String ATTR_FONT_COLOR = "cf"; + public static final String ATTR_BACKGROUND_COLOR = "chcbpat"; // Added by Boris on 06/25//02 + + /** RtfText attributes: alignment attributes */ + public static String ALIGN_CENTER = "qc"; + public static String ALIGN_LEFT = "ql"; + public static String ALIGN_RIGHT = "qr"; + public static String ALIGN_JUSTIFIED = "qj"; + public static String ALIGN_DISTRIBUTED = "qd"; + + /** RtfText attributes: border attributes */ + //added by Chris Scott + public static String BDR_BOTTOM_SINGLE = "brdrb\\brsp40\\brdrs"; + public static String BDR_BOTTOM_DOUBLE = "brdrb\\brsp40\\brdrdb"; + public static String BDR_BOTTOM_EMBOSS = "brdrb\\brsp40\\brdremboss"; + public static String BDR_BOTTOM_DOTTED = "brdrb\\brsp40\\brdrdot"; + public static String BDR_BOTTOM_DASH = "brdrb\\brsp40\\brdrdash"; + + /** RtfText attributes: fields */ + //must be carefull of group markings and star control + //ie page field: + // "{\field {\*\fldinst {PAGE}} {\fldrslt}}" + public static String RTF_FIELD = "field"; + public static String RTF_FIELD_PAGE = "fldinst { PAGE }"; + public static String RTF_FIELD_RESULT = "fldrslt"; + + /**RtfText attributes: indentation attributes */ + //added by Chris Scott + public static String LEFT_INDENT_BODY = "li"; + public static String LEFT_INDENT_FIRST = "fi-"; + + public static String TAB_CENTER = "tqc\\tx"; + public static String TAB_RIGHT = "tqr\\tx"; + public static String TAB_LEADER_DOTS = "tldot"; + public static String TAB_LEADER_HYPHEN = "tlhyph"; + public static String TAB_LEADER_UNDER = "tlul"; + public static String TAB_LEADER_THICK = "tlth"; + public static String TAB_LEADER_EQUALS = "tleq"; + + /** Space before/after a paragraph */ + //these lines were added by Boris Pouderous + public static final String SPACE_BEFORE = "sb"; + public static final String SPACE_AFTER = "sa"; + + /** RtfText attributes: this must contain all allignment attributes names */ + public static String[] ALIGNMENT = new String [] + { + ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_JUSTIFIED, ALIGN_DISTRIBUTED + }; + + /** RtfText attributes:: this must contain all border attribute names*/ + //this line added by Chris Scott, Westinghouse + public static String[] BORDER = new String [] + { + BDR_BOTTOM_SINGLE,BDR_BOTTOM_DOUBLE,BDR_BOTTOM_EMBOSS,BDR_BOTTOM_DOTTED,BDR_BOTTOM_DASH + }; + + public static String[] INDENT = new String [] + { + LEFT_INDENT_BODY, LEFT_INDENT_FIRST + }; + + public static String[] TABS = new String [] + { + TAB_CENTER ,TAB_RIGHT,TAB_LEADER_DOTS,TAB_LEADER_HYPHEN,TAB_LEADER_UNDER, + TAB_LEADER_THICK,TAB_LEADER_EQUALS + }; + + + /** RtfText attributes: this must contain all attribute names */ + public static final String [] ATTR_NAMES = { + ATTR_BOLD, + ATTR_ITALIC, + ATTR_UNDERLINE, + ATTR_FONT_SIZE, + ATTR_FONT_FAMILY, + ATTR_FONT_COLOR, + ATTR_BACKGROUND_COLOR + }; + + /** Create an RtfText in given IRtfTextContainer. + * @param str optional initial text content + */ + RtfText(IRtfTextContainer parent,Writer w,String str,RtfAttributes attr) throws IOException + { + super((RtfContainer)parent,w); + m_text = str; + m_attr = attr; + } + + /** write our text to the RTF stream */ + public void writeRtfContent() throws IOException + { writeChars: { - //these lines were added by Boris Pouderous - if (m_attr != null) { + //these lines were added by Boris Pouderous + if (m_attr != null) { writeAttributes(m_attr,new String[] {RtfText.SPACE_BEFORE}); writeAttributes(m_attr,new String[] {RtfText.SPACE_AFTER}); } - if(isTab()){ - writeControlWord("tab"); - }else if(isNewLine()){ - break writeChars; - }else if(isBold(true)){ - writeControlWord("b"); - }else if(isBold(false)){ - writeControlWord("b0"); - } - // TODO not optimal, consecutive RtfText with same attributes could be written without group marks - else{ - writeGroupMark(true); - if(m_attr != null && mustWriteAttributes()) { - writeAttributes(m_attr,RtfText.ATTR_NAMES); - } - RtfStringConverter.getInstance().writeRtfString(m_writer,m_text); - writeGroupMark(false); - } - - } - } + if(isTab()){ + writeControlWord("tab"); + }else if(isNewLine()){ + break writeChars; + }else if(isBold(true)){ + writeControlWord("b"); + }else if(isBold(false)){ + writeControlWord("b0"); + } + // TODO not optimal, consecutive RtfText with same attributes could be written without group marks + else{ + writeGroupMark(true); + if(m_attr != null && mustWriteAttributes()) { + writeAttributes(m_attr,RtfText.ATTR_NAMES); + } + RtfStringConverter.getInstance().writeRtfString(m_writer,m_text); + writeGroupMark(false); + } + + } + } /** true if our text attributes must be written */ private boolean mustWriteAttributes() @@ -220,81 +220,81 @@ public class RtfText extends RtfElement return !isEmpty() && !isNbsp(); } - /** IRtfTextContainer requirement: return a copy of our attributes */ - public RtfAttributes getTextContainerAttributes() { - if(m_attrib == null) return null; - return (RtfAttributes)this.m_attrib.clone(); - } - - /** direct access to our text */ - String getText() - { - return m_text; - } - - /** direct access to our text */ - void setText(String str) - { - m_text = str; - } - - /** - * Checks whether the text is empty. - * - * @return - * true If m_text is null\n - * false m_text is set - */ - public boolean isEmpty () - { - return m_text == null || m_text.trim().length() == 0; - } - - /** - * True if text contains a single non-breaking space (#160). + /** IRtfTextContainer requirement: return a copy of our attributes */ + public RtfAttributes getTextContainerAttributes() { + if(m_attrib == null) return null; + return (RtfAttributes)this.m_attrib.clone(); + } + + /** direct access to our text */ + String getText() + { + return m_text; + } + + /** direct access to our text */ + void setText(String str) + { + m_text = str; + } + + /** + * Checks whether the text is empty. + * + * @return + * true If m_text is null\n + * false m_text is set + */ + public boolean isEmpty () + { + return m_text == null || m_text.trim().length() == 0; + } + + /** + * True if text contains a single non-breaking space (#160). * TODO make this more general and/or merge with isEmpty? <-- what happen with empty paragraphs, if they will be removed, than NO, else ok - * - * @return - * true If m_text is character 160\n - * false m_text is not a nbsp - */ - public boolean isNbsp () - { - if (! isEmpty ()) - if (m_text.trim ().length () == 1 && m_text.charAt (0) == CHAR_NBSP) - return true; - return false; - } - - public boolean isTab() - { - if(m_text.trim().length()==1 && m_text.charAt(0)== CHAR_TAB) - return true; - else - return false; - } - - public boolean isNewLine() - { - if(m_text.trim().length()==1 && m_text.charAt(0)== CHAR_NEW_LINE) - return true; - else - return false; - } - - public boolean isBold(boolean isStart) - { - if(isStart){ - if(m_text.trim().length()==1 && m_text.charAt(0)== CHAR_BOLD_START) - return true; - }else{ - if(m_text.trim().length()==1 && m_text.charAt(0)== CHAR_BOLD_END) - return true; - else - return false; - } - return false; - } + * + * @return + * true If m_text is character 160\n + * false m_text is not a nbsp + */ + public boolean isNbsp () + { + if (! isEmpty ()) + if (m_text.trim ().length () == 1 && m_text.charAt (0) == CHAR_NBSP) + return true; + return false; + } + + public boolean isTab() + { + if(m_text.trim().length()==1 && m_text.charAt(0)== CHAR_TAB) + return true; + else + return false; + } + + public boolean isNewLine() + { + if(m_text.trim().length()==1 && m_text.charAt(0)== CHAR_NEW_LINE) + return true; + else + return false; + } + + public boolean isBold(boolean isStart) + { + if(isStart){ + if(m_text.trim().length()==1 && m_text.charAt(0)== CHAR_BOLD_START) + return true; + }else{ + if(m_text.trim().length()==1 && m_text.charAt(0)== CHAR_BOLD_END) + return true; + else + return false; + } + return false; + } /** get the attributes of our text */ public RtfAttributes getTextAttributes(){ diff --git a/src/java/org/apache/fop/rtf/rtflib/testdocs/BasicLink.java b/src/java/org/apache/fop/rtf/rtflib/testdocs/BasicLink.java index 3fb29c4dc..4841ebb02 100755 --- a/src/java/org/apache/fop/rtf/rtflib/testdocs/BasicLink.java +++ b/src/java/org/apache/fop/rtf/rtflib/testdocs/BasicLink.java @@ -69,44 +69,44 @@ import java.io.IOException; public class BasicLink extends TestDocument { - ////////////////////////////////////////////////// - // @@ Construction - ////////////////////////////////////////////////// + ////////////////////////////////////////////////// + // @@ Construction + ////////////////////////////////////////////////// - /** - * Default constructor. - */ - public BasicLink() - { - } + /** + * Default constructor. + */ + public BasicLink() + { + } - /** generate the body of the test document */ - protected void generateDocument(RtfDocumentArea rda, RtfSection sect) throws IOException - { - RtfParagraph p = sect.newParagraph (); - p.newLineBreak(); - p.newLineBreak(); - p.newLineBreak(); - p.newText ("external link: "); - RtfHyperLink link = p.newHyperLink ("click here to go to the hompage", null); - link.setExternalURL ("http://www.skynamics.com"); - p.close(); + /** generate the body of the test document */ + protected void generateDocument(RtfDocumentArea rda, RtfSection sect) throws IOException + { + RtfParagraph p = sect.newParagraph (); + p.newLineBreak(); + p.newLineBreak(); + p.newLineBreak(); + p.newText ("external link: "); + RtfHyperLink link = p.newHyperLink ("click here to go to the hompage", null); + link.setExternalURL ("http://www.skynamics.com"); + p.close(); - p = sect.newParagraph (); - p.newLineBreak(); - p.newText ("here we will demonstrate internal link to a bookmark"); - p.newLineBreak(); - p.newText ("internal link: "); - link = p.newHyperLink ("click here to go to the bookmark", null); - link.setInternalURL ("testBookmark"); - p.close(); + p = sect.newParagraph (); + p.newLineBreak(); + p.newText ("here we will demonstrate internal link to a bookmark"); + p.newLineBreak(); + p.newText ("internal link: "); + link = p.newHyperLink ("click here to go to the bookmark", null); + link.setInternalURL ("testBookmark"); + p.close(); - p = sect.newParagraph(); - p.newLineBreak(); - p.newLineBreak(); - p.newLineBreak(); - p.newPageBreak(); - p.newBookmark("testBookmark"); - p.newText("testBookmark"); - } + p = sect.newParagraph(); + p.newLineBreak(); + p.newLineBreak(); + p.newLineBreak(); + p.newPageBreak(); + p.newBookmark("testBookmark"); + p.newText("testBookmark"); + } } diff --git a/src/java/org/apache/fop/rtf/rtflib/testdocs/CreateTestDocuments.java b/src/java/org/apache/fop/rtf/rtflib/testdocs/CreateTestDocuments.java index 7c4f190bd..807d2ab31 100755 --- a/src/java/org/apache/fop/rtf/rtflib/testdocs/CreateTestDocuments.java +++ b/src/java/org/apache/fop/rtf/rtflib/testdocs/CreateTestDocuments.java @@ -68,61 +68,61 @@ import java.io.IOException; */ public class CreateTestDocuments { - public static final String TESTDOCS_PACKAGE = "org.apache.fop.rtf.rtflib.testdocs"; + public static final String TESTDOCS_PACKAGE = "org.apache.fop.rtf.rtflib.testdocs"; - /** List of all TestDocument subclasses from this package */ - private final static String [] classNames = { - "SimpleDocument", - "TextAttributes", - "SimpleTable", - "SimpleLists", - "ListInTable", - "Whitespace", - "MergedTableCells", - "NestedTable", - "ExternalGraphic", - "BasicLink", - "ParagraphAlignment" - }; + /** List of all TestDocument subclasses from this package */ + private final static String [] classNames = { + "SimpleDocument", + "TextAttributes", + "SimpleTable", + "SimpleLists", + "ListInTable", + "Whitespace", + "MergedTableCells", + "NestedTable", + "ExternalGraphic", + "BasicLink", + "ParagraphAlignment" + }; - CreateTestDocuments(File outDir) - throws Exception { - if(!outDir.isDirectory() || !outDir.canWrite()) { - throw new IOException("output directory (" + outDir + ") must exist and be writable"); - } + CreateTestDocuments(File outDir) + throws Exception { + if(!outDir.isDirectory() || !outDir.canWrite()) { + throw new IOException("output directory (" + outDir + ") must exist and be writable"); + } - for(int i=0; i < classNames.length; i++) { - createOneTestDocument(classNames[i],outDir); - } - } + for(int i=0; i < classNames.length; i++) { + createOneTestDocument(classNames[i],outDir); + } + } - /** instantiate one TestDocument and let it generate its document */ - void createOneTestDocument(String className,File outDir) - throws Exception { - className = TESTDOCS_PACKAGE + "." + className; - TestDocument td = null; - try { - td = (TestDocument)Class.forName(className).newInstance(); - } catch(Exception e) { - throw new Exception("unable to instantiate '" + className + " as a TestDocument object: " + e); - } - td.setOutputDir(outDir); - td.generateOutput(); - } + /** instantiate one TestDocument and let it generate its document */ + void createOneTestDocument(String className,File outDir) + throws Exception { + className = TESTDOCS_PACKAGE + "." + className; + TestDocument td = null; + try { + td = (TestDocument)Class.forName(className).newInstance(); + } catch(Exception e) { + throw new Exception("unable to instantiate '" + className + " as a TestDocument object: " + e); + } + td.setOutputDir(outDir); + td.generateOutput(); + } - /** execute this to create test documents from all classes listed in classNames array */ - public static void main(String args[]) - throws Exception { - if(args.length < 1) { - System.err.println("usage: CreateTestDocuments "); - System.exit(1); - } + /** execute this to create test documents from all classes listed in classNames array */ + public static void main(String args[]) + throws Exception { + if(args.length < 1) { + System.err.println("usage: CreateTestDocuments "); + System.exit(1); + } -// System.err.println("CreateTestDocuments - using " + JForVersionInfo.getLongVersionInfo()); - System.err.println("Generates documents to test the jfor RTF library."); - final File outDir = new File(args[0]); - new CreateTestDocuments(outDir); - System.err.println("CreateTestDocuments - all done."); - System.exit(0); - } +// System.err.println("CreateTestDocuments - using " + JForVersionInfo.getLongVersionInfo()); + System.err.println("Generates documents to test the jfor RTF library."); + final File outDir = new File(args[0]); + new CreateTestDocuments(outDir); + System.err.println("CreateTestDocuments - all done."); + System.exit(0); + } } diff --git a/src/java/org/apache/fop/rtf/rtflib/testdocs/ExternalGraphic.java b/src/java/org/apache/fop/rtf/rtflib/testdocs/ExternalGraphic.java index 4b21aee8d..5545658c9 100755 --- a/src/java/org/apache/fop/rtf/rtflib/testdocs/ExternalGraphic.java +++ b/src/java/org/apache/fop/rtf/rtflib/testdocs/ExternalGraphic.java @@ -71,80 +71,80 @@ import java.io.IOException; */ class ExternalGraphic extends TestDocument { - private String file = "file:///tmp/jfor-images/logo."; + private String file = "file:///tmp/jfor-images/logo."; - ////////////////////////////////////////////////// - // @@ Construction - ////////////////////////////////////////////////// + ////////////////////////////////////////////////// + // @@ Construction + ////////////////////////////////////////////////// - /** - * Default constructor. - */ - public ExternalGraphic () - { + /** + * Default constructor. + */ + public ExternalGraphic () + { - } - /** generate the body of the test document */ - protected void generateDocument (RtfDocumentArea rda, RtfSection sect) throws IOException - { - RtfParagraph p = sect.newParagraph (); - p.newLineBreak(); - p.newLineBreak(); - p.newLineBreak(); - p.newText ("EMF image with 150 % height"); - p.newLineBreak(); - RtfExternalGraphic imageA = p.newImage (); - imageA.setURL (file + "emf"); - imageA.setHeight ("150%"); - p.newLineBreak(); - p.close(); + } + /** generate the body of the test document */ + protected void generateDocument (RtfDocumentArea rda, RtfSection sect) throws IOException + { + RtfParagraph p = sect.newParagraph (); + p.newLineBreak(); + p.newLineBreak(); + p.newLineBreak(); + p.newText ("EMF image with 150 % height"); + p.newLineBreak(); + RtfExternalGraphic imageA = p.newImage (); + imageA.setURL (file + "emf"); + imageA.setHeight ("150%"); + p.newLineBreak(); + p.close(); - p = sect.newParagraph( ); - p.newLineBreak(); - p.newText ("PNG image with 150 % width"); - p.newLineBreak(); - RtfExternalGraphic imageB = sect.newImage (); - imageB.setURL (file + "png"); - imageB.setWidth ("150%"); - p.newLineBreak(); - p.close(); + p = sect.newParagraph( ); + p.newLineBreak(); + p.newText ("PNG image with 150 % width"); + p.newLineBreak(); + RtfExternalGraphic imageB = sect.newImage (); + imageB.setURL (file + "png"); + imageB.setWidth ("150%"); + p.newLineBreak(); + p.close(); - p = sect.newParagraph( ); - p.newLineBreak(); - p.newLineBreak(); - p.newText ("JPG image with width = 200px and height = 20 px"); - p.newLineBreak(); - RtfExternalGraphic imageC = sect.newImage (); - imageC.setURL (file + "jpg"); - imageC.setWidth ("200"); - imageC.setHeight ("20"); - p.newLineBreak(); - p.close(); + p = sect.newParagraph( ); + p.newLineBreak(); + p.newLineBreak(); + p.newText ("JPG image with width = 200px and height = 20 px"); + p.newLineBreak(); + RtfExternalGraphic imageC = sect.newImage (); + imageC.setURL (file + "jpg"); + imageC.setWidth ("200"); + imageC.setHeight ("20"); + p.newLineBreak(); + p.close(); - p = sect.newParagraph( ); - p.newLineBreak(); - p.newLineBreak(); - p.newText ("GIF image with width = 200px and scaling = 'uniform', that means the image " + - "size will adjusted automatically"); - p.newLineBreak(); - RtfExternalGraphic imageD = sect.newImage (); - imageD.setURL (file + "gif"); - imageD.setWidth ("200"); - imageD.setScaling ("uniform"); - p.newLineBreak(); - p.close(); + p = sect.newParagraph( ); + p.newLineBreak(); + p.newLineBreak(); + p.newText ("GIF image with width = 200px and scaling = 'uniform', that means the image " + + "size will adjusted automatically"); + p.newLineBreak(); + RtfExternalGraphic imageD = sect.newImage (); + imageD.setURL (file + "gif"); + imageD.setWidth ("200"); + imageD.setScaling ("uniform"); + p.newLineBreak(); + p.close(); - p = sect.newParagraph( ); - p.newLineBreak(); - p.newLineBreak(); - p.newText ("GIF image"); - p.newLineBreak(); - RtfExternalGraphic imageE = sect.newImage (); - imageE.setURL (file + "gif"); - p.newLineBreak(); - p.close(); + p = sect.newParagraph( ); + p.newLineBreak(); + p.newLineBreak(); + p.newText ("GIF image"); + p.newLineBreak(); + RtfExternalGraphic imageE = sect.newImage (); + imageE.setURL (file + "gif"); + p.newLineBreak(); + p.close(); - } + } diff --git a/src/java/org/apache/fop/rtf/rtflib/testdocs/ParagraphAlignment.java b/src/java/org/apache/fop/rtf/rtflib/testdocs/ParagraphAlignment.java index ac7e2992a..379ebeb60 100755 --- a/src/java/org/apache/fop/rtf/rtflib/testdocs/ParagraphAlignment.java +++ b/src/java/org/apache/fop/rtf/rtflib/testdocs/ParagraphAlignment.java @@ -71,34 +71,34 @@ import org.apache.fop.rtf.rtflib.rtfdoc.RtfAttributes; public class ParagraphAlignment extends TestDocument { - public ParagraphAlignment() - { - } - protected void generateDocument(RtfDocumentArea rda, RtfSection sect) throws java.io.IOException - { - RtfAttributes attr = new RtfAttributes (); - attr.set(RtfText.ALIGN_CENTER); - RtfParagraph p = sect.newParagraph (attr); - p.newLineBreak(); - p.newLineBreak(); - p.newText ("Centered title"); - p.newLineBreak(); - p.close(); + public ParagraphAlignment() + { + } + protected void generateDocument(RtfDocumentArea rda, RtfSection sect) throws java.io.IOException + { + RtfAttributes attr = new RtfAttributes (); + attr.set(RtfText.ALIGN_CENTER); + RtfParagraph p = sect.newParagraph (attr); + p.newLineBreak(); + p.newLineBreak(); + p.newText ("Centered title"); + p.newLineBreak(); + p.close(); - attr = new RtfAttributes (); - attr.set(RtfText.ALIGN_LEFT); - p = sect.newParagraph (attr); - p.newLineBreak(); - p.newText ("This is the left aligned text."); - p.newLineBreak(); - p.close(); + attr = new RtfAttributes (); + attr.set(RtfText.ALIGN_LEFT); + p = sect.newParagraph (attr); + p.newLineBreak(); + p.newText ("This is the left aligned text."); + p.newLineBreak(); + p.close(); - attr = new RtfAttributes (); - attr.set(RtfText.ALIGN_RIGHT); - p = sect.newParagraph (attr); - p.newLineBreak(); - p.newText ("This is the right aligned text."); - p.newLineBreak(); - p.close(); - } + attr = new RtfAttributes (); + attr.set(RtfText.ALIGN_RIGHT); + p = sect.newParagraph (attr); + p.newLineBreak(); + p.newText ("This is the right aligned text."); + p.newLineBreak(); + p.close(); + } } diff --git a/src/java/org/apache/fop/rtf/rtflib/tools/ImageConstants.java b/src/java/org/apache/fop/rtf/rtflib/tools/ImageConstants.java index 479cab708..0e217d480 100755 --- a/src/java/org/apache/fop/rtf/rtflib/tools/ImageConstants.java +++ b/src/java/org/apache/fop/rtf/rtflib/tools/ImageConstants.java @@ -67,63 +67,63 @@ import java.util.Hashtable; public class ImageConstants { - ////////////////////////////////////////////////// - // @@ Symbolic constants - ////////////////////////////////////////////////// + ////////////////////////////////////////////////// + // @@ Symbolic constants + ////////////////////////////////////////////////// - /** Defines the case, if image is not supported */ - public static int I_NOT_SUPPORTED = -1; + /** Defines the case, if image is not supported */ + public static int I_NOT_SUPPORTED = -1; - public static int I_EMF = 0; - public static int I_PNG = 1; - public static int I_JPG = 2; + public static int I_EMF = 0; + public static int I_PNG = 1; + public static int I_JPG = 2; - /** Defines the RTF properties */ - public static String [] RTF_TAGS = new String [] - { - "emfblip", "pngblip", "jpegblip" - }; + /** Defines the RTF properties */ + public static String [] RTF_TAGS = new String [] + { + "emfblip", "pngblip", "jpegblip" + }; - public static int I_TO_CONVERT_BASIS = 50; - public static int I_GIF = 50; - public static int I_JPG_C = 51; + public static int I_TO_CONVERT_BASIS = 50; + public static int I_GIF = 50; + public static int I_JPG_C = 51; - /** Defines the types for converting rtf supported image types */ - public static int [] CONVERT_TO = new int [] - { - I_JPG, I_JPG - }; + /** Defines the types for converting rtf supported image types */ + public static int [] CONVERT_TO = new int [] + { + I_JPG, I_JPG + }; - /** EMF file extension */ - public static String EMF_EXT = "emf"; - /** PNG file extension */ - public static String PNG_EXT = "png"; - /** JPG file extension */ - public static String JPG_EXT = "jpg"; - /** JPEG file extension */ - public static String JPEG_EXT = "jpeg"; - /** GIF file extension */ - public static String GIF_EXT = "gif"; + /** EMF file extension */ + public static String EMF_EXT = "emf"; + /** PNG file extension */ + public static String PNG_EXT = "png"; + /** JPG file extension */ + public static String JPG_EXT = "jpg"; + /** JPEG file extension */ + public static String JPEG_EXT = "jpeg"; + /** GIF file extension */ + public static String GIF_EXT = "gif"; - /** Defines the file extensions and the RTF property belongs to */ - public static Hashtable SUPPORTED_IMAGE_TYPES = new Hashtable (); - static - { - SUPPORTED_IMAGE_TYPES.put (EMF_EXT, new Integer (I_EMF)); - SUPPORTED_IMAGE_TYPES.put (PNG_EXT, new Integer (I_PNG)); - SUPPORTED_IMAGE_TYPES.put (JPG_EXT, new Integer (I_JPG_C)); - SUPPORTED_IMAGE_TYPES.put (JPEG_EXT,new Integer (I_JPG_C)); - SUPPORTED_IMAGE_TYPES.put (GIF_EXT, new Integer (I_GIF)); - } + /** Defines the file extensions and the RTF property belongs to */ + public static Hashtable SUPPORTED_IMAGE_TYPES = new Hashtable (); + static + { + SUPPORTED_IMAGE_TYPES.put (EMF_EXT, new Integer (I_EMF)); + SUPPORTED_IMAGE_TYPES.put (PNG_EXT, new Integer (I_PNG)); + SUPPORTED_IMAGE_TYPES.put (JPG_EXT, new Integer (I_JPG_C)); + SUPPORTED_IMAGE_TYPES.put (JPEG_EXT,new Integer (I_JPG_C)); + SUPPORTED_IMAGE_TYPES.put (GIF_EXT, new Integer (I_GIF)); + } - ////////////////////////////////////////////////// - // @@ Construction - ////////////////////////////////////////////////// + ////////////////////////////////////////////////// + // @@ Construction + ////////////////////////////////////////////////// - /** - * Private constructor. - */ - private ImageConstants() - { - } + /** + * Private constructor. + */ + private ImageConstants() + { + } } diff --git a/src/java/org/apache/fop/rtf/rtflib/tools/ImageUtil.java b/src/java/org/apache/fop/rtf/rtflib/tools/ImageUtil.java index a09907835..25cc51f2a 100755 --- a/src/java/org/apache/fop/rtf/rtflib/tools/ImageUtil.java +++ b/src/java/org/apache/fop/rtf/rtflib/tools/ImageUtil.java @@ -65,192 +65,192 @@ package org.apache.fop.rtf.rtflib.tools; public class ImageUtil { - ////////////////////////////////////////////////// - // @@ Construction - ////////////////////////////////////////////////// - - /** - * Private constructor. - */ - private ImageUtil () - { - } - - - ////////////////////////////////////////////////// - // @@ Public static methods - ////////////////////////////////////////////////// - - /** - * Determines the digits from a string. - * - * @param value String with digits - * - * @return - * -1 There is no digit\n - * number The digits as integer - */ - public static int getInt (String value) - { - String retString = new String (); - StringBuffer s = new StringBuffer (value); - int len = s.length (); - - for (int i = 0; i < len; i++) - { - if (Character.isDigit (s.charAt (i))) - { - retString += s.charAt (i); - } - } - - if (retString.length () == 0) - { - return -1; - } - else - { - return Integer.parseInt (retString); - } - } - - /** - * Checks the string for percent character at the end of string. - * - * @param value String with digits - * - * @return - * true The string contains a % value - * false Other string - */ - public static boolean isPercent (String value) - { - if (value.endsWith ("%")) - { - return true; - - } - - return false; - } - - /** - * Compares two hexadecimal values. - * - * @param pattern Target - * @param data Data - * @param searchAt Position to start compare - * @param searchForward Direction to compare byte arrays - * - * @return - * true If equal\n - * false If different - */ - public static boolean compareHexValues (byte[] pattern, byte[] data, int searchAt, - boolean searchForward) - { - if (searchAt >= data.length) - { - return false; - - } - - int pLen = pattern.length; - - if (searchForward) - { - if (pLen >= (data.length - searchAt)) - { - return false; - - } - - for (int i = 0; i < pLen; i++) - { - if (pattern[i] != data[searchAt + i]) - { - return false; - } - } - - return true; - } - else - { - if (pLen > (searchAt + 1)) - { - return false; - - } - - for (int i = 0; i < pLen; i++) - { - if (pattern[pLen - i - 1] != data[searchAt - i]) - { - return false; - } - } - - return true; - } - } - - /** - * Determines a integer value from a hexadecimal byte array. - * - * @param data Image - * @param start Start index to read from - * @param end End index until to read - * - * @return A number - */ - public static int getIntFromByteArray (byte[] data, int startAt, int length, - boolean searchForward) - { - int bit = 8; - int bitMoving = length * bit; - int retVal = 0; - - if (startAt >= data.length) - { - return retVal; - - } - - if (searchForward) - { - if (length >= (data.length - startAt)) - { - return retVal; - - } - - for (int i = 0; i < length; i++) - { - bitMoving -= bit; - int iData = (int) data[startAt + i]; - if (iData < 0) - iData += 256; - retVal += iData << bitMoving; - } - } - else - { - if (length > (startAt + 1)) - { - return retVal; - - } - - for (int i = 0; i < length; i++) - { - bitMoving -= bit; - int iData = (int) data[startAt - i]; - if (iData < 0) - iData += 256; - retVal += iData << bitMoving; } - } - - return retVal; - } -} \ No newline at end of file + ////////////////////////////////////////////////// + // @@ Construction + ////////////////////////////////////////////////// + + /** + * Private constructor. + */ + private ImageUtil () + { + } + + + ////////////////////////////////////////////////// + // @@ Public static methods + ////////////////////////////////////////////////// + + /** + * Determines the digits from a string. + * + * @param value String with digits + * + * @return + * -1 There is no digit\n + * number The digits as integer + */ + public static int getInt (String value) + { + String retString = new String (); + StringBuffer s = new StringBuffer (value); + int len = s.length (); + + for (int i = 0; i < len; i++) + { + if (Character.isDigit (s.charAt (i))) + { + retString += s.charAt (i); + } + } + + if (retString.length () == 0) + { + return -1; + } + else + { + return Integer.parseInt (retString); + } + } + + /** + * Checks the string for percent character at the end of string. + * + * @param value String with digits + * + * @return + * true The string contains a % value + * false Other string + */ + public static boolean isPercent (String value) + { + if (value.endsWith ("%")) + { + return true; + + } + + return false; + } + + /** + * Compares two hexadecimal values. + * + * @param pattern Target + * @param data Data + * @param searchAt Position to start compare + * @param searchForward Direction to compare byte arrays + * + * @return + * true If equal\n + * false If different + */ + public static boolean compareHexValues (byte[] pattern, byte[] data, int searchAt, + boolean searchForward) + { + if (searchAt >= data.length) + { + return false; + + } + + int pLen = pattern.length; + + if (searchForward) + { + if (pLen >= (data.length - searchAt)) + { + return false; + + } + + for (int i = 0; i < pLen; i++) + { + if (pattern[i] != data[searchAt + i]) + { + return false; + } + } + + return true; + } + else + { + if (pLen > (searchAt + 1)) + { + return false; + + } + + for (int i = 0; i < pLen; i++) + { + if (pattern[pLen - i - 1] != data[searchAt - i]) + { + return false; + } + } + + return true; + } + } + + /** + * Determines a integer value from a hexadecimal byte array. + * + * @param data Image + * @param start Start index to read from + * @param end End index until to read + * + * @return A number + */ + public static int getIntFromByteArray (byte[] data, int startAt, int length, + boolean searchForward) + { + int bit = 8; + int bitMoving = length * bit; + int retVal = 0; + + if (startAt >= data.length) + { + return retVal; + + } + + if (searchForward) + { + if (length >= (data.length - startAt)) + { + return retVal; + + } + + for (int i = 0; i < length; i++) + { + bitMoving -= bit; + int iData = (int) data[startAt + i]; + if (iData < 0) + iData += 256; + retVal += iData << bitMoving; + } + } + else + { + if (length > (startAt + 1)) + { + return retVal; + + } + + for (int i = 0; i < length; i++) + { + bitMoving -= bit; + int iData = (int) data[startAt - i]; + if (iData < 0) + iData += 256; + retVal += iData << bitMoving; } + } + + return retVal; + } +} -- 2.39.5