aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render
diff options
context:
space:
mode:
authorGlen Mazza <gmazza@apache.org>2003-11-04 23:59:14 +0000
committerGlen Mazza <gmazza@apache.org>2003-11-04 23:59:14 +0000
commita47a0676d84c199f2208fafbf234a6cf7041a883 (patch)
tree4f190fb003bad92382cf3ba78a9e6e16b6c0e820 /src/java/org/apache/fop/render
parenta2056453e3b648eb7d58ed8f487a0b87023de504 (diff)
downloadxmlgraphics-fop-a47a0676d84c199f2208fafbf234a6cf7041a883.tar.gz
xmlgraphics-fop-a47a0676d84c199f2208fafbf234a6cf7041a883.zip
RTF structural renderer moved from root to render.rtf, joining all the other renderers
RTF Library moved from root to render.rtf.rtflib, but kept separate from renderer itself. See: http://marc.theaimsgroup.com/?l=fop-dev&m=106753338719406&w=2 git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196981 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render')
-rw-r--r--src/java/org/apache/fop/render/rtf/BuilderContext.java198
-rw-r--r--src/java/org/apache/fop/render/rtf/FoUnitsConverter.java176
-rw-r--r--src/java/org/apache/fop/render/rtf/PageAttributesConverter.java123
-rw-r--r--src/java/org/apache/fop/render/rtf/RTFHandler.java773
-rw-r--r--src/java/org/apache/fop/render/rtf/TableAttributesConverter.java473
-rw-r--r--src/java/org/apache/fop/render/rtf/TableContext.java214
-rw-r--r--src/java/org/apache/fop/render/rtf/TextAttributesConverter.java345
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/exceptions/RtfException.java71
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/exceptions/RtfStructureException.java72
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/exceptions/package.html6
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/interfaces/ITableColumnsInfo.java85
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/interfaces/package.html6
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/BorderAttributesConverter.java182
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfAfterContainer.java72
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfBeforeContainer.java75
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfBookmarkContainer.java77
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfExternalGraphicContainer.java74
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfHyperLinkContainer.java75
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfJforCmdContainer.java75
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfListContainer.java74
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfOptions.java76
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfPageBreakContainer.java72
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfPageContainer.java74
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfPageNumberCitationContainer.java74
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfPageNumberContainer.java74
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfParagraphContainer.java85
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfParagraphKeepTogetherContainer.java74
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTableContainer.java86
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTextContainer.java96
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTextrunContainer.java74
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableAttributes.java212
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IrtfTemplateContainer.java78
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ParagraphKeeptogetherContext.java126
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfAfter.java84
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfAfterBeforeBase.java164
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfAttributes.java239
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfBefore.java85
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfBookmark.java193
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfBookmarkContainerImpl.java134
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfColorTable.java274
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfContainer.java239
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfDocumentArea.java89
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfElement.java365
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java633
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExtraRowSet.java343
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFile.java273
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFontManager.java208
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFontTable.java84
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfHeader.java130
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfHyperLink.java243
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfJforCmd.java116
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfLineBreak.java86
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfList.java215
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListItem.java136
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListTable.java244
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfNull.java73
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfOptions.java83
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPage.java138
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageArea.java99
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageBreak.java88
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumber.java128
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java148
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfParagraph.java377
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfParagraphKeepTogether.java125
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfSection.java271
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfString.java100
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfStringConverter.java153
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfStyleSheetTable.java275
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTable.java196
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java486
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java388
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTemplate.java132
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfText.java350
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java286
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/WhitespaceCollapser.java150
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/package.html7
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/testdocs/BasicLink.java117
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/testdocs/CreateTestDocuments.java136
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/testdocs/DummyTableColumnsInfo.java90
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/testdocs/ExternalGraphic.java148
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/testdocs/ListInTable.java110
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/testdocs/MergedTableCells.java149
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/testdocs/NestedTable.java246
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/testdocs/ParagraphAlignment.java111
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/testdocs/SimpleDocument.java85
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/testdocs/SimpleLists.java109
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/testdocs/SimpleTable.java104
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/testdocs/TestDocument.java121
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/testdocs/TextAttributes.java99
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/testdocs/Whitespace.java99
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/testdocs/package.html7
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/tools/ImageConstants.java131
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/tools/ImageUtil.java226
-rw-r--r--src/java/org/apache/fop/render/rtf/rtflib/tools/package.html6
94 files changed, 15171 insertions, 0 deletions
diff --git a/src/java/org/apache/fop/render/rtf/BuilderContext.java b/src/java/org/apache/fop/render/rtf/BuilderContext.java
new file mode 100644
index 000000000..a1b9ad1b6
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/BuilderContext.java
@@ -0,0 +1,198 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+package org.apache.fop.render.rtf;
+
+import java.util.Stack;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfOptions;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfContainer;
+
+
+/** A BuilderContext holds context information when building an RTF document
+ *
+ * @author Bertrand Delacretaz <bdelacretaz@codeconsult.ch>
+ * @author putzi
+ * @author Peter Herweg <pherweg@web.de>
+ *
+ * This class was originally developed by Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ * for the JFOR project and is now integrated into FOP.
+ */
+
+
+class BuilderContext {
+ /** stack of RtfContainers */
+ private final Stack m_containers = new Stack();
+
+ /** stack of TableContexts */
+ private final Stack m_tableContexts = new Stack();
+
+ /** stack of IBuilders */
+ private final Stack m_builders = new Stack();
+
+ /** Rtf options */
+ IRtfOptions m_options;
+
+ BuilderContext(IRtfOptions rtfOptions) {
+ m_options = rtfOptions;
+ }
+
+ /** find first object of given class from top of stack s
+ * @return null if not found
+ */
+ private Object getObjectFromStack(Stack s, Class desiredClass) {
+ Object result = null;
+ final Stack copy = (Stack)s.clone();
+ while (!copy.isEmpty()) {
+ final Object o = copy.pop();
+ if (desiredClass.isAssignableFrom(o.getClass())) {
+ result = o;
+ break;
+ }
+ }
+ return result;
+ }
+
+ /* find the "nearest" IBuilder of given class /
+ Object getBuilder(Class builderClass,boolean required)
+ throws Exception
+ {
+ final IBuilder result = (IBuilder)getObjectFromStack(m_builders,builderClass);
+ if(result == null && required) {
+ throw new Exception(
+ "IBuilder of class '" + builderClass.getName() + "' not found on builders stack"
+ );
+ }
+ return result;
+ }*/
+
+ /** find the "nearest" container that implements the given interface on our stack
+ * @param required if true, ConverterException is thrown if no container found
+ * @param forWhichBuilder used in error message if container not found
+ */
+ RtfContainer getContainer(Class containerClass, boolean required,
+ Object /*IBuilder*/ forWhichBuilder) throws Exception {
+ // TODO what to do if the desired container is not at the top of the stack?
+ // close top-of-stack container?
+ final RtfContainer result = (RtfContainer)getObjectFromStack(m_containers,
+ containerClass);
+
+ if (result == null && required) {
+ throw new Exception(
+ "No RtfContainer of class '" + containerClass.getName()
+ + "' available for '" + forWhichBuilder.getClass().getName() + "' builder"
+ );
+ }
+
+ return result;
+ }
+
+ /** push an RtfContainer on our stack */
+ void pushContainer(RtfContainer c) {
+ m_containers.push(c);
+ }
+
+ /**
+ * In some cases an RtfContainer must be replaced by another one on the
+ * stack. This happens when handling nested fo:blocks for example: after
+ * handling a nested block the enclosing block must switch to a new
+ * paragraph container to handle what follows the nested block.
+ * TODO: what happens to elements that are "more on top" than oldC on the
+ * stack? shouldn't they be closed or something?
+ */
+ void replaceContainer(RtfContainer oldC, RtfContainer newC)
+ throws Exception {
+ // treating the Stack as a Vector allows such manipulations (yes, I hear you screaming ;-)
+ final int index = m_containers.indexOf(oldC);
+ if (index < 0) {
+ throw new Exception("container to replace not found:" + oldC);
+ }
+ m_containers.setElementAt(newC, index);
+ }
+
+ /** pop the topmost RtfContainer from our stack */
+ void popContainer() {
+ m_containers.pop();
+ }
+
+ /* push an IBuilder to our stack /
+ void pushBuilder(IBuilder b)
+ {
+ m_builders.push(b);
+ }*/
+
+ /** pop the topmost IBuilder from our stack and return previous builder on stack
+ * @return null if builders stack is empty
+
+ IBuilder popBuilderAndGetPreviousOne()
+ {
+ IBuilder result = null;
+ m_builders.pop();
+ if(!m_builders.isEmpty()) {
+ result = (IBuilder)m_builders.peek();
+ }
+ return result;
+ }
+ */
+ /** return the current TableContext */
+ TableContext getTableContext() {
+ return (TableContext)m_tableContexts.peek();
+ }
+
+ /** push a TableContext to our stack */
+ void pushTableContext(TableContext tc) {
+ m_tableContexts.push(tc);
+ }
+
+ /** pop a TableContext from our stack */
+ void popTableContext() {
+ m_tableContexts.pop();
+ }
+
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/FoUnitsConverter.java b/src/java/org/apache/fop/render/rtf/FoUnitsConverter.java
new file mode 100644
index 000000000..04d1884e3
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/FoUnitsConverter.java
@@ -0,0 +1,176 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+package org.apache.fop.render.rtf;
+
+import java.util.Map;
+import java.util.HashMap;
+
+//FOP
+import org.apache.fop.apps.FOPException;
+
+
+/** Converts XSL-FO units to RTF units
+ *
+ * @author Bertrand Delacretaz <bdelacretaz@codeconsult.ch>
+ * @author putzi
+ * @author Peter Herweg <pherweg@web.de>
+ *
+ * This class was originally developed by Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ * for the JFOR project and is now integrated into FOP.
+ */
+
+class FoUnitsConverter {
+ private static final FoUnitsConverter m_instance = new FoUnitsConverter();
+
+ /** points to twips: 1 twip is 1/20 of a point */
+ public static final float POINT_TO_TWIPS = 20f;
+
+ /** millimeters and centimeters to twips: , one point is 1/72 of an inch, one inch is 25.4 mm */
+ public static final float IN_TO_TWIPS = 72f * POINT_TO_TWIPS;
+ public static final float MM_TO_TWIPS = IN_TO_TWIPS / 25.4f;
+ public static final float CM_TO_TWIPS = 10 * MM_TO_TWIPS;
+
+
+ /** conversion factors keyed by xsl:fo units names */
+ private static final Map m_twipFactors = new HashMap();
+ static {
+ m_twipFactors.put("mm", new Float(MM_TO_TWIPS));
+ m_twipFactors.put("cm", new Float(CM_TO_TWIPS));
+ m_twipFactors.put("pt", new Float(POINT_TO_TWIPS));
+ m_twipFactors.put("in", new Float(IN_TO_TWIPS));
+ }
+
+ /** singleton pattern */
+ private FoUnitsConverter() {
+ }
+
+ /** singleton pattern */
+ static FoUnitsConverter getInstance() {
+ return m_instance;
+ }
+
+ /** convert given value to RTF units
+ * @param foValue a value like "12mm"
+ * TODO: tested with "mm" units only, needs work to comply with FO spec
+ * Why does it search for period instead of simply breaking last two
+ * Characters into another units string? - Chris
+ */
+ float convertToTwips(String foValue)
+ throws FOPException {
+ foValue = foValue.trim();
+
+ // break value into number and units
+ final StringBuffer number = new StringBuffer();
+ final StringBuffer units = new StringBuffer();
+
+ for (int i = 0; i < foValue.length(); i++) {
+ final char c = foValue.charAt(i);
+ if (Character.isDigit(c) || c == '.') {
+ number.append(c);
+ } else {
+ // found the end of the digits
+ units.append(foValue.substring(i).trim());
+ break;
+ }
+ }
+
+ return numberToTwips(number.toString(), units.toString());
+ }
+
+
+ /** convert given value to twips according to given units */
+ private float numberToTwips(String number, String units)
+ throws FOPException {
+ float result = 0;
+
+ // convert number to integer
+ try {
+ if (number != null && number.trim().length() > 0) {
+ result = Float.valueOf(number).floatValue();
+ }
+ } catch (Exception e) {
+ throw new FOPException("number format error: cannot convert '"
+ + number + "' to float value");
+ }
+
+ // find conversion factor
+ if (units != null && units.trim().length() > 0) {
+ final Float factor = (Float)m_twipFactors.get(units.toLowerCase());
+ if (factor == null) {
+ throw new FOPException("conversion factor not found for '" + units + "' units");
+ }
+ result *= factor.floatValue();
+ }
+
+ return result;
+ }
+
+ /** convert a font size given in points like "12pt" */
+ int convertFontSize(String size) throws FOPException {
+ size = size.trim();
+ final String FONT_SUFFIX = "pt";
+ if (!size.endsWith(FONT_SUFFIX)) {
+ throw new FOPException("Invalid font size '" + size + "', must end with '"
+ + FONT_SUFFIX + "'");
+ }
+
+ float result = 0;
+ size = size.substring(0, size.length() - FONT_SUFFIX.length());
+ try {
+ result = (Float.valueOf(size).floatValue());
+ } catch (Exception e) {
+ throw new FOPException("Invalid font size value '" + size + "'");
+ }
+
+ // RTF font size units are in half-points
+ return (int)(result * 2.0);
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/PageAttributesConverter.java b/src/java/org/apache/fop/render/rtf/PageAttributesConverter.java
new file mode 100644
index 000000000..f65b3bf0c
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/PageAttributesConverter.java
@@ -0,0 +1,123 @@
+/*
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+package org.apache.fop.render.rtf;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.logger.ConsoleLogger;
+
+//FOP
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfPage;
+import org.apache.fop.fo.PropertyList;
+import org.apache.fop.fo.Property;
+
+
+/** Converts simple-page-master attributes into strings as defined in RtfPage.
+ * @author Christopher Scott, scottc@westinghouse.com
+ * @author Peter Herweg, pherweg@web.de
+ */
+
+class PageAttributesConverter {
+
+ private static Logger log = new ConsoleLogger();
+
+ /** convert xsl:fo attributes to RTF text attributes */
+ static RtfAttributes convertPageAttributes(PropertyList props, PropertyList defProps) {
+ RtfAttributes attrib = null;
+
+ try {
+ Property p;
+
+ if (defProps != null) {
+ attrib = convertPageAttributes(defProps, null);
+ } else {
+ attrib = new RtfAttributes();
+ }
+
+ if ((p = props.get("page-width")) != null) {
+ Float f = new Float(p.getLength().getValue() / 1000f);
+ attrib.set(RtfPage.PAGE_WIDTH,
+ (int)FoUnitsConverter.getInstance().convertToTwips(f.toString() + "pt"));
+ }
+ if ((p = props.get("page-height")) != null) {
+ Float f = new Float(p.getLength().getValue() / 1000f);
+ attrib.set(RtfPage.PAGE_HEIGHT,
+ (int)FoUnitsConverter.getInstance().convertToTwips(f.toString() + "pt"));
+ }
+ if ((p = props.get("margin-top")) != null) {
+ Float f = new Float(p.getLength().getValue() / 1000f);
+ attrib.set(RtfPage.MARGIN_TOP,
+ (int)FoUnitsConverter.getInstance().convertToTwips(f.toString() + "pt"));
+ }
+ if ((p = props.get("margin-bottom")) != null) {
+ Float f = new Float(p.getLength().getValue() / 1000f);
+ attrib.set(RtfPage.MARGIN_BOTTOM,
+ (int)FoUnitsConverter.getInstance().convertToTwips(f.toString() + "pt"));
+ }
+ if ((p = props.get("margin-left")) != null) {
+ Float f = new Float(p.getLength().getValue() / 1000f);
+ attrib.set(RtfPage.MARGIN_LEFT,
+ (int)FoUnitsConverter.getInstance().convertToTwips(f.toString() + "pt"));
+ }
+ if ((p = props.get("margin-right")) != null) {
+ Float f = new Float(p.getLength().getValue() / 1000f);
+ attrib.set(RtfPage.MARGIN_RIGHT,
+ (int)FoUnitsConverter.getInstance().convertToTwips(f.toString() + "pt"));
+ }
+ } catch (FOPException e) {
+ log.error("Exception in convertPageAttributes: " + e.getMessage() + "- page attributes ignored");
+ attrib=new RtfAttributes();
+ }
+
+ return attrib;
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java
new file mode 100644
index 000000000..85c07e96a
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java
@@ -0,0 +1,773 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+package org.apache.fop.render.rtf;
+
+// Java
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.datatypes.ColorType;
+import org.apache.fop.fo.FOInputHandler;
+import org.apache.fop.fo.flow.Block;
+import org.apache.fop.fo.flow.ExternalGraphic;
+import org.apache.fop.fo.flow.Inline;
+import org.apache.fop.fo.flow.InstreamForeignObject;
+import org.apache.fop.fo.flow.Leader;
+import org.apache.fop.fo.flow.ListBlock;
+import org.apache.fop.fo.flow.ListItem;
+import org.apache.fop.fo.flow.PageNumber;
+import org.apache.fop.fo.flow.Table;
+import org.apache.fop.fo.flow.TableColumn;
+import org.apache.fop.fo.flow.TableBody;
+import org.apache.fop.fo.flow.TableCell;
+import org.apache.fop.fo.flow.TableRow;
+import org.apache.fop.fo.pagination.Flow;
+import org.apache.fop.fo.pagination.PageSequence;
+import org.apache.fop.fo.pagination.SimplePageMaster;
+import org.apache.fop.fo.properties.Constants;
+import org.apache.fop.fo.Property;
+import org.apache.fop.fo.PropertyList;
+import org.apache.fop.apps.Document;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfAfterContainer;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfBeforeContainer;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfPageNumberContainer;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfParagraphContainer;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfTextrunContainer;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAfter;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfBefore;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfColorTable;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfElement;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfFile;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfFontManager;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfParagraph;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfText;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTextrun;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTable;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableRow;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableCell;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfTableContainer;
+import org.xml.sax.SAXException;
+
+/**
+ * RTF Handler: generates RTF output using the structure events from
+ * the FO Tree sent to this structure handler.
+ *
+ * @author Bertrand Delacretaz <bdelacretaz@codeconsult.ch>
+ * @author Trembicki-Guy, Ed <GuyE@DNB.com>
+ * @author Boris Poudérous <boris.pouderous@eads-telecom.com>
+ * @author Peter Herweg <pherweg@web.de>
+ */
+public class RTFHandler extends FOInputHandler {
+
+ private RtfFile rtfFile;
+ private final OutputStream os;
+ private final Logger log = new ConsoleLogger();
+ private RtfSection sect;
+ private RtfDocumentArea docArea;
+ private RtfParagraph para;
+ private boolean warned = false;
+ private boolean bPrevHeaderSpecified = false;//true, if there has been a
+ //header in any page-sequence
+ private boolean bPrevFooterSpecified = false;//true, if there has been a
+ //footer in any page-sequence
+ private boolean bHeaderSpecified = false; //true, if there is a header
+ //in current page-sequence
+ private boolean bFooterSpecified = false; //true, if there is a footer
+ //in current page-sequence
+ private BuilderContext builderContext = new BuilderContext(null);
+
+ private static final String ALPHA_WARNING = "WARNING: RTF renderer is "
+ + "veryveryalpha at this time, see class org.apache.fop.rtf.renderer.RTFHandler";
+
+ /**
+ * Creates a new RTF structure handler.
+ * @param doc the Document for which this RTFHandler is processing
+ * @param os OutputStream to write to
+ */
+ public RTFHandler(Document doc, OutputStream os) {
+ super(doc);
+ this.os = os;
+ // use pdf fonts for now, this is only for resolving names
+ org.apache.fop.render.pdf.FontSetup.setup(doc, null);
+ log.warn(ALPHA_WARNING);
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#startDocument()
+ */
+ public void startDocument() throws SAXException {
+ // TODO sections should be created
+ try {
+ rtfFile = new RtfFile(new OutputStreamWriter(os));
+ docArea = rtfFile.startDocumentArea();
+ } catch (IOException ioe) {
+ // TODO could we throw Exception in all FOInputHandler events?
+ throw new SAXException(ioe);
+ }
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#endDocument()
+ */
+ public void endDocument() throws SAXException {
+ try {
+ rtfFile.flush();
+ } catch (IOException ioe) {
+ // TODO could we throw Exception in all FOInputHandler events?
+ throw new SAXException(ioe);
+ }
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler
+ */
+ public void startPageSequence(PageSequence pageSeq) {
+ try {
+ sect = docArea.newSection();
+
+ //read page size and margins, if specified
+ Property prop;
+ if((prop=pageSeq.properties.get("master-reference"))!=null) {
+ String reference=prop.getString();
+
+ SimplePageMaster pagemaster=
+ pageSeq.getLayoutMasterSet().getSimplePageMaster(reference);
+
+ //only simple-page-master supported, so pagemaster may be null
+ if(pagemaster!=null) {
+ sect.getRtfAttributes().set(
+ PageAttributesConverter.convertPageAttributes(
+ pagemaster.properties,null));
+ }
+ }
+
+ builderContext.pushContainer(sect);
+
+ bHeaderSpecified = false;
+ bFooterSpecified = false;
+ } catch (IOException ioe) {
+ // TODO could we throw Exception in all FOInputHandler events?
+ log.error("startPageSequence: " + ioe.getMessage());
+ //TODO throw new FOPException(ioe);
+ }
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#endPageSequence(PageSequence)
+ */
+ public void endPageSequence(PageSequence pageSeq) throws FOPException {
+ builderContext.popContainer();
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#startFlow(Flow)
+ */
+ public void startFlow(Flow fl) {
+ try {
+ if (fl.getFlowName().equals("xsl-region-body")) {
+ // if there is no header in current page-sequence but there has been
+ // a header in a previous page-sequence, insert an empty header.
+ if (bPrevHeaderSpecified && !bHeaderSpecified) {
+ RtfAttributes attr = new RtfAttributes();
+ attr.set(RtfBefore.HEADER);
+
+ final IRtfBeforeContainer contBefore =
+ (IRtfBeforeContainer)builderContext.getContainer
+ (IRtfBeforeContainer.class, true, this);
+ contBefore.newBefore(attr);
+ }
+
+ // if there is no footer in current page-sequence but there has been
+ // a footer in a previous page-sequence, insert an empty footer.
+ if (bPrevFooterSpecified && !bFooterSpecified) {
+ RtfAttributes attr = new RtfAttributes();
+ attr.set(RtfAfter.FOOTER);
+
+ final IRtfAfterContainer contAfter =
+ (IRtfAfterContainer)builderContext.getContainer
+ (IRtfAfterContainer.class, true, this);
+ contAfter.newAfter(attr);
+ }
+
+ // print ALPHA_WARNING
+ if (!warned) {
+ sect.newParagraph().newText(ALPHA_WARNING);
+ warned = true;
+ }
+ } else if (fl.getFlowName().equals("xsl-region-before")) {
+ bHeaderSpecified = true;
+ bPrevHeaderSpecified = true;
+
+ final IRtfBeforeContainer c =
+ (IRtfBeforeContainer)builderContext.getContainer(IRtfBeforeContainer.class,
+ true, this);
+
+ RtfAttributes beforeAttributes = ((RtfElement)c).getRtfAttributes();
+ if (beforeAttributes == null) {
+ beforeAttributes = new RtfAttributes();
+ }
+ beforeAttributes.set(RtfBefore.HEADER);
+
+ RtfBefore before = c.newBefore(beforeAttributes);
+ builderContext.pushContainer(before);
+ } else if (fl.getFlowName().equals("xsl-region-after")) {
+ bFooterSpecified = true;
+ bPrevFooterSpecified = true;
+
+ final IRtfAfterContainer c =
+ (IRtfAfterContainer)builderContext.getContainer(IRtfAfterContainer.class,
+ true, this);
+
+ RtfAttributes afterAttributes = ((RtfElement)c).getRtfAttributes();
+ if (afterAttributes == null) {
+ afterAttributes = new RtfAttributes();
+ }
+
+ afterAttributes.set(RtfAfter.FOOTER);
+
+ RtfAfter after = c.newAfter(afterAttributes);
+ builderContext.pushContainer(after);
+ }
+ } catch (IOException ioe) {
+ log.error("startFlow: " + ioe.getMessage());
+ throw new Error(ioe.getMessage());
+ } catch (Exception e) {
+ log.error("startFlow: " + e.getMessage());
+ throw new Error(e.getMessage());
+ }
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#endFlow(Flow)
+ */
+ public void endFlow(Flow fl) {
+ try {
+ if (fl.getFlowName().equals("xsl-region-body")) {
+ //just do nothing
+ } else if (fl.getFlowName().equals("xsl-region-before")) {
+ builderContext.popContainer();
+ } else if (fl.getFlowName().equals("xsl-region-after")) {
+ builderContext.popContainer();
+ }
+ } catch (Exception e) {
+ log.error("endFlow: " + e.getMessage());
+ throw new Error(e.getMessage());
+ }
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#startBlock(Block)
+ */
+ public void startBlock(Block bl) {
+ try {
+ RtfAttributes rtfAttr =
+ TextAttributesConverter.convertAttributes(bl.properties, null);
+
+ IRtfTextrunContainer container =
+ (IRtfTextrunContainer)builderContext.getContainer(IRtfTextrunContainer.class,
+ true,this);
+
+ RtfTextrun textrun=container.getTextrun();
+
+ textrun.addParagraphBreak();
+ textrun.pushAttributes(rtfAttr);
+ } catch (IOException ioe) {
+ // TODO could we throw Exception in all FOInputHandler events?
+ log.error("startBlock: " + ioe.getMessage());
+ throw new Error("IOException: " + ioe);
+ } catch (Exception e) {
+ log.error("startBlock: " + e.getMessage());
+ throw new Error("Exception: " + e);
+ }
+ }
+
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#endBlock(Block)
+ */
+ public void endBlock(Block bl) {
+ try {
+ IRtfTextrunContainer container =
+ (IRtfTextrunContainer)builderContext.getContainer(IRtfTextrunContainer.class,
+ true,this);
+
+ RtfTextrun textrun=container.getTextrun();
+
+ textrun.addParagraphBreak();
+ textrun.popAttributes();
+
+ } catch (IOException ioe) {
+ log.error("startBlock:" + ioe.getMessage());
+ throw new Error(ioe.getMessage());
+ } catch (Exception e) {
+ log.error("startBlock:" + e.getMessage());
+ throw new Error(e.getMessage());
+ }
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#startTable(Table)
+ */
+ public void startTable(Table tbl) {
+ // create an RtfTable in the current table container
+ TableContext tableContext = new TableContext(builderContext);
+ RtfAttributes atts = new RtfAttributes();
+
+ try {
+ final IRtfTableContainer tc =
+ (IRtfTableContainer)builderContext.getContainer(IRtfTableContainer.class,
+ true, null);
+ builderContext.pushContainer(tc.newTable(atts, tableContext));
+ } catch (Exception e) {
+ log.error("startTable:" + e.getMessage());
+ throw new Error(e.getMessage());
+ }
+
+ builderContext.pushTableContext(tableContext);
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#endTable(Table)
+ */
+ public void endTable(Table tbl) {
+ builderContext.popTableContext();
+ builderContext.popContainer();
+ }
+
+ /**
+ *
+ * @param tc TableColumn that is starting;
+ */
+
+ public void startColumn(TableColumn tc) {
+ try {
+ Integer iWidth = new Integer(tc.getColumnWidth() / 1000);
+ builderContext.getTableContext().setNextColumnWidth(iWidth.toString() + "pt");
+ builderContext.getTableContext().setNextColumnRowSpanning(new Integer(0), null);
+ } catch (Exception e) {
+ log.error("startColumn: " + e.getMessage());
+ throw new Error(e.getMessage());
+ }
+
+ }
+
+ /**
+ *
+ * @param tc TableColumn that is ending;
+ */
+
+ public void endColumn(TableColumn tc) {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#startHeader(TableBody)
+ */
+ public void startHeader(TableBody th) {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#endHeader(TableBody)
+ */
+ public void endHeader(TableBody th) {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#startFooter(TableBody)
+ */
+ public void startFooter(TableBody tf) {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#endFooter(TableBody)
+ */
+ public void endFooter(TableBody tf) {
+ }
+
+ /**
+ *
+ * @param inl Inline that is starting.
+ */
+ public void startInline(Inline inl){
+
+ try {
+ RtfAttributes rtfAttr =
+ TextAttributesConverter.convertCharacterAttributes(inl.properties, null);
+
+ IRtfTextrunContainer container =
+ (IRtfTextrunContainer)builderContext.getContainer(IRtfTextrunContainer.class,
+ true,this);
+
+ RtfTextrun textrun=container.getTextrun();
+ textrun.pushAttributes(rtfAttr);
+ } catch (IOException ioe) {
+ log.error("startInline:" + ioe.getMessage());
+ throw new Error(ioe.getMessage());
+ } catch (FOPException fe) {
+ log.error("startInline:" + fe.getMessage());
+ throw new Error(fe.getMessage());
+ } catch (Exception e) {
+ log.error("startInline:" + e.getMessage());
+ throw new Error(e.getMessage());
+ }
+ }
+
+ /**
+ *
+ * @param inl Inline that is ending.
+ */
+ public void endInline(Inline inl){
+ try {
+ IRtfTextrunContainer container =
+ (IRtfTextrunContainer)builderContext.getContainer(IRtfTextrunContainer.class,
+ true,this);
+
+ RtfTextrun textrun=container.getTextrun();
+ textrun.popAttributes();
+ } catch (IOException ioe) {
+ log.error("startInline:" + ioe.getMessage());
+ throw new Error(ioe.getMessage());
+ } catch (Exception e) {
+ log.error("startInline:" + e.getMessage());
+ throw new Error(e.getMessage());
+ }
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#startBody(TableBody)
+ */
+ public void startBody(TableBody tb) {
+ try {
+ RtfAttributes atts = TableAttributesConverter.convertRowAttributes (tb.properties,
+ null, null);
+
+ RtfTable tbl = (RtfTable)builderContext.getContainer(RtfTable.class, true, this);
+ tbl.setHeaderAttribs(atts);
+ } catch (Exception e) {
+ log.error("startBody: " + e.getMessage());
+ throw new Error(e.getMessage());
+ }
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#endBody(TableBody)
+ */
+ public void endBody(TableBody tb) {
+ try {
+ RtfTable tbl = (RtfTable)builderContext.getContainer(RtfTable.class, true, this);
+ tbl.setHeaderAttribs(null);
+ } catch (Exception e) {
+ log.error("endBody: " + e.getMessage());
+ throw new Error(e.getMessage());
+ }
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#startRow(TableRow)
+ */
+ public void startRow(TableRow tr) {
+ try {
+ // create an RtfTableRow in the current RtfTable
+ final RtfTable tbl = (RtfTable)builderContext.getContainer(RtfTable.class,
+ true, null);
+
+ RtfAttributes tblAttribs = tbl.getRtfAttributes();
+ RtfAttributes tblRowAttribs = new RtfAttributes();
+ RtfAttributes atts = TableAttributesConverter.convertRowAttributes(tr.properties,
+ null, tbl.getHeaderAttribs());
+
+ builderContext.pushContainer(tbl.newTableRow(atts));
+
+ // reset column iteration index to correctly access column widths
+ builderContext.getTableContext().selectFirstColumn();
+ } catch (Exception e) {
+ log.error("startRow: " + e.getMessage());
+ throw new Error(e.getMessage());
+ }
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#endRow(TableRow)
+ */
+ public void endRow(TableRow tr) {
+ builderContext.popContainer();
+ builderContext.getTableContext().decreaseRowSpannings();
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#startCell(TableCell)
+ */
+ public void startCell(TableCell tc) {
+ try {
+ TableContext tctx = builderContext.getTableContext();
+ final RtfTableRow row = (RtfTableRow)builderContext.getContainer(RtfTableRow.class,
+ true, null);
+
+
+ //while the current column is in row-spanning, act as if
+ //a vertical merged cell would have been specified.
+ while (tctx.getNumberOfColumns() > tctx.getColumnIndex()
+ && tctx.getColumnRowSpanningNumber().intValue() > 0) {
+ row.newTableCellMergedVertically((int)tctx.getColumnWidth(),
+ tctx.getColumnRowSpanningAttrs());
+ tctx.selectNextColumn();
+ }
+
+ //get the width of the currently started cell
+ float width = tctx.getColumnWidth();
+
+ // create an RtfTableCell in the current RtfTableRow
+ RtfAttributes atts = TableAttributesConverter.convertCellAttributes(tc.properties,
+ null);
+ RtfTableCell cell = row.newTableCell((int)width, atts);
+
+ //process number-rows-spanned attribute
+ Property p = null;
+ if ((p = tc.properties.get("number-rows-spanned")) != null && false) {
+ // Start vertical merge
+ cell.setVMerge(RtfTableCell.MERGE_START);
+
+ // set the number of rows spanned
+ tctx.setCurrentColumnRowSpanning(new Integer(p.getNumber().intValue()),
+ cell.getRtfAttributes());
+ } else {
+ tctx.setCurrentColumnRowSpanning(new Integer(1), null);
+ }
+
+ builderContext.pushContainer(cell);
+ } catch (Exception e) {
+ log.error("startCell: " + e.getMessage());
+ throw new Error(e.getMessage());
+ }
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#endCell(TableCell)
+ */
+ public void endCell(TableCell tc) {
+ builderContext.popContainer();
+ builderContext.getTableContext().selectNextColumn();
+ }
+
+ // Lists
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#startList(ListBlock)
+ */
+ public void startList(ListBlock lb) {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#endList(ListBlock)
+ */
+ public void endList(ListBlock lb) {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#startListItem(ListItem)
+ */
+ public void startListItem(ListItem li) {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#endListItem(ListItem)
+ */
+ public void endListItem(ListItem li) {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#startListLabel()
+ */
+ public void startListLabel() {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#endListLabel()
+ */
+ public void endListLabel() {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#startListBody()
+ */
+ public void startListBody() {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#endListBody()
+ */
+ public void endListBody() {
+ }
+
+ // Static Regions
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#startStatic()
+ */
+ public void startStatic() {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#endStatic()
+ */
+ public void endStatic() {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#startMarkup()
+ */
+ public void startMarkup() {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#endMarkup()
+ */
+ public void endMarkup() {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#startLink()
+ */
+ public void startLink() {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#endLink()
+ */
+ public void endLink() {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#image(ExternalGraphic)
+ */
+ public void image(ExternalGraphic eg) {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#pageRef()
+ */
+ public void pageRef() {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#foreignObject(InstreamForeignObject)
+ */
+ public void foreignObject(InstreamForeignObject ifo) {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#footnote()
+ */
+ public void footnote() {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#leader(Leader)
+ */
+ public void leader(Leader l) {
+ }
+
+ /**
+ * @see org.apache.fop.fo.FOInputHandler#characters(char[], int, int)
+ */
+ public void characters(char data[], int start, int length) {
+ try {
+ IRtfTextrunContainer container =
+ (IRtfTextrunContainer)builderContext.getContainer(IRtfTextrunContainer.class,
+ true,this);
+
+ RtfTextrun textrun=container.getTextrun();
+ textrun.addString(new String(data, start, length));
+ } catch (IOException ioe) {
+ // FIXME could we throw Exception in all FOInputHandler events?
+ log.error("characters: " + ioe.getMessage());
+ throw new Error(ioe.getMessage());
+ } catch (Exception e) {
+ log.error("characters:" + e.getMessage());
+ throw new Error(e.getMessage());
+ }
+ }
+
+ /**
+ *
+ * @param pagenum PageNumber that is starting.
+ */
+ public void startPageNumber(PageNumber pagenum) {
+ try {
+ RtfAttributes rtfAttr =
+ TextAttributesConverter.convertCharacterAttributes(pagenum.properties, null);
+
+ IRtfTextrunContainer container =
+ (IRtfTextrunContainer)builderContext.getContainer(IRtfTextrunContainer.class,
+ true,this);
+
+ RtfTextrun textrun=container.getTextrun();
+ textrun.addPageNumber(rtfAttr);
+ } catch (IOException ioe) {
+ log.error("startPageNumber:" + ioe.getMessage());
+ throw new Error(ioe.getMessage());
+ } catch (Exception e) {
+ log.error("startPageNumber: " + e.getMessage());
+ throw new Error(e.getMessage());
+ }
+ }
+
+ /**
+ *
+ * @param pagenum PageNumber that is ending.
+ */
+ public void endPageNumber(PageNumber pagenum) {
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java
new file mode 100644
index 000000000..3a08ee0c0
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java
@@ -0,0 +1,473 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+package org.apache.fop.render.rtf;
+
+//RTF
+import org.apache.fop.render.rtf.rtflib.rtfdoc.BorderAttributesConverter;
+
+//FOP
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.fo.EnumProperty;
+import org.apache.fop.fo.expr.NCnameProperty;
+import org.apache.fop.fo.properties.Constants;
+import org.apache.fop.fo.LengthProperty;
+import org.apache.fop.fo.ListProperty;
+import org.apache.fop.fo.PropertyList;
+import org.apache.fop.fo.Property;
+import org.apache.fop.fo.ColorTypeProperty;
+import org.apache.fop.fo.NumberProperty;
+import org.apache.fop.datatypes.ColorType;
+
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.ITableAttributes;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfColorTable;
+
+/**
+ * Contributor(s):
+ * @author Roberto Marra <roberto@link-u.com>
+ * @author Boris Poudérous <boris.pouderous@eads-telecom.com>
+ * @author Normand Massé
+ * @author Peter Herweg <pherweg@web.de>
+ *
+ * This class was originally developed for the JFOR project and
+ * is now integrated into FOP.
+-----------------------------------------------------------------------------*/
+
+/**
+ * Provides methods to convert the attributes to RtfAttributes.
+ */
+
+public class TableAttributesConverter {
+
+ private static Logger log = new ConsoleLogger();
+
+ //////////////////////////////////////////////////
+ // @@ Construction
+ //////////////////////////////////////////////////
+
+ /**
+ * Constructor.
+ */
+ private TableAttributesConverter() {
+ }
+
+ //////////////////////////////////////////////////
+ // @@ Static converter methods
+ //////////////////////////////////////////////////
+
+
+ /**
+ * Converts cell attributes to rtf attributes.
+ * @param attrs Given attributes
+ * @param defaultAttributes Default rtf attributes
+ *
+ * @return All valid rtf attributes together
+ *
+ * @throws ConverterException On convertion error
+ */
+ static RtfAttributes convertCellAttributes(PropertyList props, PropertyList defProps)
+ throws FOPException {
+
+ Property p;
+ EnumProperty ep;
+ RtfColorTable colorTable = RtfColorTable.getInstance();
+
+ RtfAttributes attrib = null;
+
+ if (defProps != null) {
+ attrib = convertCellAttributes(defProps, null);
+ } else {
+ attrib = new RtfAttributes();
+ }
+
+ boolean isBorderPresent = false;
+
+ // Cell background color
+ if ((p = props.getNearestSpecified("background-color")) != null) {
+ ColorType color = p.getColorType();
+ if (color != null) {
+ if (color.getAlpha() != 0
+ || color.getRed() != 0
+ || color.getGreen() != 0
+ || color.getBlue() != 0) {
+ attrib.set(
+ ITableAttributes.CELL_COLOR_BACKGROUND,
+ TextAttributesConverter.convertFOPColorToRTF(color));
+ }
+ } else {
+ log.warn("Named color '" + p.toString() + "' not found. ");
+ }
+
+ }
+
+ // Cell borders :
+ if ((p = props.getExplicit("border-color")) != null) {
+ ListProperty listprop = (ListProperty)p;
+ ColorType color = null;
+ if (listprop.getList().get(0) instanceof NCnameProperty) {
+ color = new ColorType(((NCnameProperty)listprop.getList().get(0)).getNCname());
+ } else if (listprop.getList().get(0) instanceof ColorTypeProperty) {
+ color = ((ColorTypeProperty)listprop.getList().get(0)).getColorType();
+ }
+
+ attrib.set(
+ BorderAttributesConverter.BORDER_COLOR,
+ colorTable.getColorNumber((int)color.getRed(), (int)color.getGreen(),
+ (int)color.getBlue()).intValue());
+ }
+ if ((p = props.getExplicit("border-top-color")) != null) {
+ ColorType color = p.getColorType();
+ attrib.set(
+ BorderAttributesConverter.BORDER_COLOR,
+ colorTable.getColorNumber((int)color.getRed(), (int)color.getGreen(),
+ (int)color.getBlue()).intValue());
+ }
+ if ((p = props.getExplicit("border-bottom-color")) != null) {
+ ColorType color = p.getColorType();
+ attrib.set(
+ BorderAttributesConverter.BORDER_COLOR,
+ colorTable.getColorNumber((int)color.getRed(), (int)color.getGreen(),
+ (int)color.getBlue()).intValue());
+ }
+ if ((p = props.getExplicit("border-left-color")) != null) {
+ ColorType color = p.getColorType();
+ attrib.set(
+ BorderAttributesConverter.BORDER_COLOR,
+ colorTable.getColorNumber((int)color.getRed(), (int)color.getGreen(),
+ (int)color.getBlue()).intValue());
+ }
+ if ((p = props.getExplicit("border-right-color")) != null) {
+ ColorType color = p.getColorType();
+ attrib.set(
+ BorderAttributesConverter.BORDER_COLOR,
+ colorTable.getColorNumber((int)color.getRed(), (int)color.getGreen(),
+ (int)color.getBlue()).intValue());
+ }
+
+ // Border styles do not inherit from parent
+ if ((p = props.get("border-style")) != null) {
+ log.warn("border-style not implemented. Please use border-style-left, "
+ + "...-right, ...-top or ...-bottom");
+ /*
+ attrib.set(ITableAttributes.CELL_BORDER_LEFT, "\\"+convertAttributetoRtf(e.getEnum()));
+ attrib.set(ITableAttributes.CELL_BORDER_RIGHT, "\\"+convertAttributetoRtf(e.getEnum()));
+ attrib.set(ITableAttributes.CELL_BORDER_BOTTOM,"\\"+convertAttributetoRtf(e.getEnum()));
+ attrib.set(ITableAttributes.CELL_BORDER_TOP, "\\"+convertAttributetoRtf(e.getEnum()));
+ isBorderPresent=true;
+ */
+ }
+ ep = (EnumProperty)props.get("border-top-style");
+ if (ep != null && ep.getEnum() != Constants.NONE) {
+ attrib.set(ITableAttributes.CELL_BORDER_TOP, "\\"
+ + convertAttributetoRtf(ep.getEnum()));
+ isBorderPresent = true;
+ }
+ ep = (EnumProperty)props.get("border-bottom-style");
+ if (ep != null && ep.getEnum() != Constants.NONE) {
+ attrib.set(ITableAttributes.CELL_BORDER_BOTTOM, "\\"
+ + convertAttributetoRtf(ep.getEnum()));
+ isBorderPresent = true;
+ }
+ ep = (EnumProperty)props.get("border-left-style");
+ if (ep != null && ep.getEnum() != Constants.NONE) {
+ attrib.set(ITableAttributes.CELL_BORDER_LEFT, "\\"
+ + convertAttributetoRtf(ep.getEnum()));
+ isBorderPresent = true;
+ }
+ ep = (EnumProperty)props.get("border-right-style");
+ if (ep != null && ep.getEnum() != Constants.NONE) {
+ attrib.set(ITableAttributes.CELL_BORDER_RIGHT, "\\"
+ + convertAttributetoRtf(ep.getEnum()));
+ isBorderPresent = true;
+ }
+
+ if ((p = props.get("border-width")) != null) {
+ ListProperty listprop = (ListProperty)p;
+ LengthProperty lengthprop = (LengthProperty)listprop.getList().get(0);
+
+ Float f = new Float(lengthprop.getLength().getValue() / 1000f);
+ String sValue = f.toString() + "pt";
+
+ attrib.set(BorderAttributesConverter.BORDER_WIDTH,
+ (int)FoUnitsConverter.getInstance().convertToTwips(sValue));
+ } else if (isBorderPresent) {
+ //if not defined, set default border width
+ //note 20 twips = 1 point
+ attrib.set(BorderAttributesConverter.BORDER_WIDTH,
+ (int)FoUnitsConverter.getInstance().convertToTwips("1pt"));
+ }
+
+
+ // Column spanning :
+ NumberProperty n = (NumberProperty)props.get("number-columns-spanned");
+ if (n != null && n.getNumber().intValue() > 1) {
+ attrib.set(ITableAttributes.COLUMN_SPAN, n.getNumber().intValue());
+ }
+
+ return attrib;
+ }
+
+
+ /**
+ * Converts table and row attributes to rtf attributes.
+ *
+ * @param attrs Given attributes
+ * @param defaultAttributes Default rtf attributes
+ *
+ * @return All valid rtf attributes together
+ *
+ * @throws ConverterException On convertion error
+ */
+ static RtfAttributes convertRowAttributes(PropertyList props,
+ PropertyList defProps, RtfAttributes rtfatts)
+ throws FOPException {
+
+ Property p;
+ EnumProperty ep;
+ RtfColorTable colorTable = RtfColorTable.getInstance();
+
+ RtfAttributes attrib = null;
+
+ if (defProps != null) {
+ attrib = convertRowAttributes(defProps, null, rtfatts);
+ } else {
+ if (rtfatts == null) {
+ attrib = new RtfAttributes();
+ } else {
+ attrib = rtfatts;
+ }
+ }
+
+ String attrValue;
+ boolean isBorderPresent = false;
+ //need to set a default width
+
+ //check for keep-together row attribute
+ if ((p = props.get("keep-together.within-page")) != null) {
+ attrib.set(ITableAttributes.ROW_KEEP_TOGETHER);
+ }
+
+ if ((p = props.get("keep-together")) != null) {
+ attrib.set(ITableAttributes.ROW_KEEP_TOGETHER);
+ }
+
+ //Check for keep-with-next row attribute.
+ if ((p = props.get("keep-together")) != null) {
+ attrib.set(ITableAttributes.ROW_KEEP_WITH_NEXT);
+ }
+
+ //Check for keep-with-previous row attribute.
+ if ((p = props.get("keep-with-previous")) != null) {
+ attrib.set(ITableAttributes.ROW_KEEP_WITH_PREVIOUS);
+ }
+
+ //Check for height row attribute.
+ if ((p = props.get("height")) != null) {
+ Float f = new Float(p.getLength().getValue() / 1000);
+ attrValue = f.toString() + "pt";
+ attrib.set(ITableAttributes.ROW_HEIGHT,
+ (int)FoUnitsConverter.getInstance().convertToTwips(attrValue));
+ }
+
+ /* to write a border to a side of a cell one must write the directional
+ * side (ie. left, right) and the inside value if one needs to be taken
+ * out ie if the cell lies on the edge of a table or not, the offending
+ * value will be taken out by RtfTableRow. This is because you can't
+ * say BORDER_TOP and BORDER_HORIZONTAL if the cell lies at the top of
+ * the table. Similarly using BORDER_BOTTOM and BORDER_HORIZONTAL will
+ * not work if the cell lies at th bottom of the table. The same rules
+ * apply for left right and vertical.
+
+ * Also, the border type must be written after every control word. Thus
+ * it is implemented that the border type is the value of the border
+ * place.
+ */
+ if ((p = props.get("border-style")) != null) {
+ log.warn("border-style not implemented. Please use border-style-left, "
+ + "...-right, ...-top or ...-bottom");
+/*
+ attrValue = new String(AbstractBuilder.getValue( attrs, "border-style", defAttrs ));
+ attrib.set(ITableAttributes.ROW_BORDER_LEFT,"\\"
+ + BorderAttributesConverter.convertAttributetoRtf(attrValue));
+ attrib.set(ITableAttributes.ROW_BORDER_RIGHT,"\\"
+ + BorderAttributesConverter.convertAttributetoRtf(attrValue));
+ attrib.set(ITableAttributes.ROW_BORDER_HORIZONTAL,"\\"
+ + BorderAttributesConverter.convertAttributetoRtf(attrValue));
+ attrib.set(ITableAttributes.ROW_BORDER_VERTICAL,"\\"
+ + BorderAttributesConverter.convertAttributetoRtf(attrValue));
+ attrib.set(ITableAttributes.ROW_BORDER_BOTTOM,"\\"
+ + BorderAttributesConverter.convertAttributetoRtf(attrValue));
+ attrib.set(ITableAttributes.ROW_BORDER_TOP,"\\"
+ + BorderAttributesConverter.convertAttributetoRtf(attrValue));
+ isBorderPresent=true;
+*/
+ }
+ ep = (EnumProperty)props.get("border-top-style");
+ if (ep != null && ep.getEnum() != Constants.NONE) {
+ attrib.set(ITableAttributes.ROW_BORDER_TOP, "\\"
+ + convertAttributetoRtf(ep.getEnum()));
+ attrib.set(ITableAttributes.ROW_BORDER_HORIZONTAL, "\\"
+ + convertAttributetoRtf(ep.getEnum()));
+ isBorderPresent = true;
+ }
+ ep = (EnumProperty)props.get("border-bottom-style");
+ if (ep != null && ep.getEnum() != Constants.NONE) {
+ attrib.set(ITableAttributes.ROW_BORDER_BOTTOM, "\\"
+ + convertAttributetoRtf(ep.getEnum()));
+ attrib.set(ITableAttributes.ROW_BORDER_HORIZONTAL, "\\"
+ + convertAttributetoRtf(ep.getEnum()));
+ isBorderPresent = true;
+ }
+ ep = (EnumProperty)props.get("border-left-style");
+ if (ep != null && ep.getEnum() != Constants.NONE) {
+ attrib.set(ITableAttributes.ROW_BORDER_LEFT, "\\"
+ + convertAttributetoRtf(ep.getEnum()));
+ attrib.set(ITableAttributes.ROW_BORDER_VERTICAL, "\\"
+ + convertAttributetoRtf(ep.getEnum()));
+ isBorderPresent = true;
+ }
+ ep = (EnumProperty)props.get("border-right-style");
+ if (ep != null && ep.getEnum() != Constants.NONE) {
+ attrib.set(ITableAttributes.ROW_BORDER_RIGHT, "\\"
+ + convertAttributetoRtf(ep.getEnum()));
+ attrib.set(ITableAttributes.ROW_BORDER_VERTICAL, "\\"
+ + convertAttributetoRtf(ep.getEnum()));
+ isBorderPresent = true;
+ }
+ ep = (EnumProperty)props.get("border-horizontal-style");
+ if (ep != null && ep.getEnum() != Constants.NONE) {
+ attrib.set(ITableAttributes.ROW_BORDER_HORIZONTAL, "\\"
+ + convertAttributetoRtf(ep.getEnum()));
+ attrib.set(ITableAttributes.ROW_BORDER_TOP, "\\"
+ + convertAttributetoRtf(ep.getEnum()));
+ attrib.set(ITableAttributes.ROW_BORDER_BOTTOM, "\\"
+ + convertAttributetoRtf(ep.getEnum()));
+ isBorderPresent = true;
+ }
+ ep = (EnumProperty)props.get("border-vertical-style");
+ if (ep != null && ep.getEnum() != Constants.NONE) {
+ attrib.set(ITableAttributes.ROW_BORDER_VERTICAL, "\\"
+ + convertAttributetoRtf(ep.getEnum()));
+ attrib.set(ITableAttributes.ROW_BORDER_LEFT, "\\"
+ + convertAttributetoRtf(ep.getEnum()));
+ attrib.set(ITableAttributes.ROW_BORDER_RIGHT, "\\"
+ + convertAttributetoRtf(ep.getEnum()));
+ isBorderPresent = true;
+ }
+
+ if ((p = props.get("border-width")) != null) {
+ ListProperty listprop = (ListProperty)p;
+ LengthProperty lengthprop = (LengthProperty)listprop.getList().get(0);
+
+ Float f = new Float(lengthprop.getLength().getValue() / 1000f);
+ String sValue = f.toString() + "pt";
+
+ attrib.set(BorderAttributesConverter.BORDER_WIDTH,
+ (int)FoUnitsConverter.getInstance().convertToTwips(sValue));
+ } else if (isBorderPresent) {
+ //if not defined, set default border width
+ //note 20 twips = 1 point
+ attrib.set(BorderAttributesConverter.BORDER_WIDTH,
+ (int)FoUnitsConverter.getInstance().convertToTwips("1pt"));
+ }
+
+ return attrib;
+ }
+
+
+ /**
+ *
+ * @param iBorderStyle the border style to be converted
+ * @return String with the converted border style
+ */
+ public static String convertAttributetoRtf(int iBorderStyle) {
+ // Added by Normand Masse
+ // "solid" is interpreted like "thin"
+ if (iBorderStyle == Constants.SOLID) {
+ return BorderAttributesConverter.BORDER_SINGLE_THICKNESS;
+/* } else if (iBorderStyle==Constants.THIN) {
+ return BorderAttributesConverter.BORDER_SINGLE_THICKNESS;
+ } else if (iBorderStyle==Constants.THICK) {
+ return BorderAttributesConverter.BORDER_DOUBLE_THICKNESS;
+ } else if (iBorderStyle==Constants. value.equals("shadowed")) {
+ return BorderAttributesConverter.BORDER_SHADOWED;*/
+ } else if (iBorderStyle == Constants.DOUBLE) {
+ return BorderAttributesConverter.BORDER_DOUBLE;
+ } else if (iBorderStyle == Constants.DOTTED) {
+ return BorderAttributesConverter.BORDER_DOTTED;
+ } else if (iBorderStyle == Constants.DASHED) {
+ return BorderAttributesConverter.BORDER_DASH;
+/* } else if (iBorderStyle==Constants value.equals("hairline")) {
+ return BorderAttributesConverter.BORDER_HAIRLINE;*/
+/* } else if (iBorderStyle==Constant value.equals("dot-dash")) {
+ return BorderAttributesConverter.BORDER_DOT_DASH;
+ } else if (iBorderStyle==Constant value.equals("dot-dot-dash")) {
+ return BorderAttributesConverter.BORDER_DOT_DOT_DASH;
+ } else if (iBorderStyle==Constant value.equals("triple")) {
+ return BorderAttributesConverter.BORDER_TRIPLE;
+ } else if (iBorderStyle==Constant value.equals("wavy")) {
+ return BorderAttributesConverter.BORDER_WAVY;
+ } else if (iBorderStyle==Constant value.equals("wavy-double")) {
+ return BorderAttributesConverter.BORDER_WAVY_DOUBLE;
+ } else if (iBorderStyle==Constant value.equals("striped")) {
+ return BorderAttributesConverter.BORDER_STRIPED;
+ } else if (iBorderStyle==Constant value.equals("emboss")) {
+ return BorderAttributesConverter.BORDER_EMBOSS;
+ } else if (iBorderStyle==Constant value.equals("engrave")) {
+ return BorderAttributesConverter.BORDER_ENGRAVE;*/
+ } else {
+ return null;
+ }
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/rtf/TableContext.java b/src/java/org/apache/fop/render/rtf/TableContext.java
new file mode 100644
index 000000000..2f2baa72e
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/TableContext.java
@@ -0,0 +1,214 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+package org.apache.fop.render.rtf;
+
+import java.util.ArrayList;
+
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes;
+import org.apache.fop.render.rtf.rtflib.interfaces.ITableColumnsInfo;
+
+
+/** Used when handling fo:table to hold information to build the table.
+ *
+ * Contributor(s):
+ * @author Bertrand Delacretaz <bdelacretaz@codeconsult.ch>
+ * @author Trembicki-Guy, Ed <GuyE@DNB.com>
+ * @author Boris Poudérous <boris.pouderous@eads-telecom.com>
+ * @author Peter Herweg <pherweg@web.de>
+ *
+ * This class was originally developed for the JFOR project and
+ * is now integrated into FOP.
+ */
+
+class TableContext implements ITableColumnsInfo {
+ private final Logger log = new ConsoleLogger();
+ private final BuilderContext m_context;
+ private final ArrayList m_colWidths = new ArrayList();
+ private int m_colIndex;
+
+ /**
+ * Added by Peter Herweg on 2002-06-29
+ * This ArrayList contains one element for each column in the table.
+ * value == 0 means there is no row-spanning
+ * value > 0 means there is row-spanning
+ * Each value in the list is decreased by 1 after each finished table-row
+ */
+ private final ArrayList m_colRowSpanningNumber = new ArrayList();
+
+ /**
+ * Added by Peter Herweg on 2002-06-29
+ * If there has a vertical merged cell to be created, its attributes are
+ * inherited from the corresponding MERGE_START-cell.
+ * For this purpose the attributes of a cell are stored in this array, as soon
+ * as a number-rows-spanned attribute has been found.
+ */
+ private final ArrayList m_colRowSpanningAttrs = new ArrayList();
+
+ private boolean m_bNextRowBelongsToHeader = false;
+
+ public void setNextRowBelongsToHeader(boolean bNextRowBelongsToHeader) {
+ m_bNextRowBelongsToHeader = bNextRowBelongsToHeader;
+ }
+
+ public boolean getNextRowBelongsToHeader() {
+ return m_bNextRowBelongsToHeader;
+ }
+
+ TableContext(BuilderContext ctx) {
+ m_context = ctx;
+ }
+
+ void setNextColumnWidth(String strWidth)
+ throws Exception {
+ m_colWidths.add(new Float(FoUnitsConverter.getInstance().convertToTwips(strWidth)));
+ }
+
+ //Added by Peter Herweg on 2002-06-29
+ RtfAttributes getColumnRowSpanningAttrs() {
+ return (RtfAttributes)m_colRowSpanningAttrs.get(m_colIndex);
+ }
+
+ //Added by Peter Herweg on 2002-06-29
+ Integer getColumnRowSpanningNumber() {
+ return (Integer)m_colRowSpanningNumber.get(m_colIndex);
+ }
+
+ //Added by Peter Herweg on 2002-06-29
+ void setCurrentColumnRowSpanning(Integer iRowSpanning, RtfAttributes attrs)
+ throws Exception {
+
+ if (m_colIndex < m_colRowSpanningNumber.size()) {
+ m_colRowSpanningNumber.set(m_colIndex, iRowSpanning);
+ m_colRowSpanningAttrs.set(m_colIndex, attrs);
+ } else {
+ m_colRowSpanningNumber.add(iRowSpanning);
+ m_colRowSpanningAttrs.add(m_colIndex, attrs);
+ }
+ }
+
+ //Added by Peter Herweg on 2002-06-29
+ public void setNextColumnRowSpanning(Integer iRowSpanning,
+ RtfAttributes attrs) {
+ m_colRowSpanningNumber.add(iRowSpanning);
+ m_colRowSpanningAttrs.add(m_colIndex, attrs);
+ }
+
+ /**
+ * Added by Peter Herweg on 2002-06-29
+ * This function is called after each finished table-row.
+ * It decreases all values in m_colRowSpanningNumber by 1. If a value
+ * reaches 0 row-spanning is finished, and the value won't be decreased anymore.
+ */
+ public void decreaseRowSpannings() {
+ for (int z = 0; z < m_colRowSpanningNumber.size(); ++z) {
+ Integer i = (Integer)m_colRowSpanningNumber.get(z);
+
+ if (i.intValue() > 0) {
+ i = new Integer(i.intValue() - 1);
+ }
+
+ m_colRowSpanningNumber.set(z, i);
+
+ if (i.intValue() == 0) {
+ m_colRowSpanningAttrs.set(z, null);
+ }
+ }
+ }
+
+ /**
+ * Reset the column iteration index, meant to be called when creating a new row
+ * The 'public' modifier has been added by Boris Poudérous for
+ * 'number-columns-spanned' processing
+ */
+ public void selectFirstColumn() {
+ m_colIndex = 0;
+ }
+
+ /**
+ * Increment the column iteration index
+ * The 'public' modifier has been added by Boris Poudérous for
+ * 'number-columns-spanned' processing
+ */
+ public void selectNextColumn() {
+ m_colIndex++;
+ }
+
+ /**
+ * Get current column width according to column iteration index
+ * @return INVALID_COLUMN_WIDTH if we cannot find the value
+ * The 'public' modifier has been added by Boris Poudérous for
+ * 'number-columns-spanned' processing
+ */
+ public float getColumnWidth() {
+ try {
+ return ((Float)m_colWidths.get(m_colIndex)).floatValue();
+ } catch (IndexOutOfBoundsException ex) {
+ // this code contributed by Trembicki-Guy, Ed <GuyE@DNB.com>
+ log.warn("fo:table-column width not defined, using " + INVALID_COLUM_WIDTH);
+ return INVALID_COLUM_WIDTH;
+ }
+ }
+
+ /** Added by Boris Poudérous on 07/22/2002 */
+ public int getColumnIndex() {
+ return m_colIndex;
+ }
+ /** - end - */
+
+ /** Added by Boris Poudérous on 07/22/2002 */
+ public int getNumberOfColumns() {
+ return m_colWidths.size();
+ }
+ /** - end - */
+}
+
diff --git a/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java
new file mode 100644
index 000000000..be4d79cf4
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java
@@ -0,0 +1,345 @@
+/*
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+package org.apache.fop.render.rtf;
+
+//XML
+import org.xml.sax.Attributes;
+
+//FOP
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.fo.EnumProperty;
+import org.apache.fop.fo.expr.NCnameProperty;
+import org.apache.fop.fo.properties.Constants;
+import org.apache.fop.fo.LengthProperty;
+import org.apache.fop.fo.ListProperty;
+import org.apache.fop.fo.PropertyList;
+import org.apache.fop.fo.Property;
+import org.apache.fop.fo.SpaceProperty;
+import org.apache.fop.fo.ColorTypeProperty;
+import org.apache.fop.fo.NumberProperty;
+import org.apache.fop.datatypes.ColorType;
+
+//RTF
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfColorTable;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfFontManager;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfText;
+
+
+/** Converts FO properties to RtfAttributes
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ * @author Andreas Putz a.putz@skynamics.com
+ * @author Boris Poudérous boris.pouderous@eads-telecom.com
+ * @author Peter Herweg, pherweg@web.de
+ * @author Normand Massé
+ * @author Chris Scott
+ * @author rmarra
+ */
+
+class TextAttributesConverter {
+ private static Logger log = new ConsoleLogger();
+
+ /**
+ * Converts all known text FO properties to RtfAttributes
+ * @param props list of FO properites, which are to be converted
+ * @param props list of default FO properites (usally null)
+ */
+ public static RtfAttributes convertAttributes(PropertyList props, PropertyList defProps)
+ throws FOPException {
+ RtfAttributes attrib = null;
+
+ if (defProps != null) {
+ attrib = convertAttributes(defProps, null);
+ } else {
+ attrib = new RtfAttributes();
+ }
+
+ attrBlockFontFamily(props, attrib);
+ attrBlockFontWeight(props, attrib);
+ attrBlockFontSize(props, attrib);
+ attrBlockFontColor(props, attrib);
+ attrBlockFontItalic(props, attrib);
+ attrBlockFontUnderline(props, attrib);
+ attrBlockBackgroundColor(props, attrib);
+ attrBlockSpaceBeforeAfter(props, attrib);
+ attrBlockMargins(props, attrib);
+ attrBlockTextAlign(props, attrib);
+
+ return attrib;
+ }
+
+ /**
+ * Converts all character related FO properties to RtfAttributes.
+ * @param props list of FO properites, which are to be converted
+ * @param props list of default FO properites (usally null)
+ */
+ public static RtfAttributes convertCharacterAttributes(PropertyList props, PropertyList defProps)
+ throws FOPException {
+
+ RtfAttributes attrib = null;
+
+ if (defProps != null) {
+ attrib = convertCharacterAttributes(defProps, null);
+ } else {
+ attrib = new RtfAttributes();
+ }
+
+ attrBlockFontFamily(props, attrib);
+ attrBlockFontWeight(props, attrib);
+ attrBlockFontSize(props, attrib);
+ attrBlockFontColor(props, attrib);
+ attrBlockFontItalic(props, attrib);
+ attrBlockFontUnderline(props, attrib);
+ attrBlockBackgroundColor(props, attrib);
+
+ return attrib;
+ }
+
+
+ private static void attrBlockFontFamily(PropertyList properties, RtfAttributes rtfAttr) {
+ String fopValue = properties.get("font-family").getString();
+
+ if (fopValue != null) {
+ rtfAttr.set(RtfText.ATTR_FONT_FAMILY, RtfFontManager.getInstance().getFontNumber(fopValue));
+ }
+ }
+
+ private static void attrBlockFontSize(PropertyList properties, RtfAttributes rtfAttr) {
+ int fopValue = properties.get("font-size").getLength().getValue() / 500;
+ rtfAttr.set("fs", fopValue);
+ }
+
+ private static void attrBlockFontColor(PropertyList properties, RtfAttributes rtfAttr) {
+ // Cell background color
+ ColorTypeProperty colorTypeProp=(ColorTypeProperty)properties.get("color");
+ if(colorTypeProp != null) {
+ ColorType colorType = colorTypeProp.getColorType();
+ if (colorType != null) {
+ if (colorType.getAlpha() != 0
+ || colorType.getRed() != 0
+ || colorType.getGreen() != 0
+ || colorType.getBlue() != 0) {
+ rtfAttr.set(
+ RtfText.ATTR_FONT_COLOR,
+ convertFOPColorToRTF(colorType));
+ }
+ } else {
+ log.warn("Named color '" + colorTypeProp.toString() + "' not found. ");
+ }
+ }
+ }
+
+
+
+ private static void attrBlockFontWeight(PropertyList properties, RtfAttributes rtfAttr) {
+ String fopValue = properties.get("font-weight").getString();
+ if (fopValue == "bold" || fopValue == "700") {
+ rtfAttr.set("b", 1);
+ } else {
+ rtfAttr.set("b", 0);
+ }
+ }
+
+ private static void attrBlockFontItalic(PropertyList properties, RtfAttributes rtfAttr) {
+ String fopValue = properties.get("font-style").getString();
+ if(fopValue.equals("italic")) {
+ rtfAttr.set(RtfText.ATTR_ITALIC, 1);
+ } else {
+ rtfAttr.set(RtfText.ATTR_ITALIC, 0);
+ }
+ }
+
+ private static void attrBlockFontUnderline(PropertyList properties, RtfAttributes rtfAttr) {
+ EnumProperty enumProp=(EnumProperty)properties.get("text-decoration");
+ if(enumProp.getEnum()==Constants.UNDERLINE) {
+ rtfAttr.set(RtfText.ATTR_UNDERLINE, 1);
+ } else {
+ rtfAttr.set(RtfText.ATTR_UNDERLINE, 0);
+ }
+ }
+
+ private static void attrBlockSpaceBeforeAfter(PropertyList properties, RtfAttributes rtfAttr) {
+ SpaceProperty spaceProp=null;
+
+ //space-before
+ spaceProp=(SpaceProperty)properties.get("space-before");
+ if(spaceProp!=null) {
+ Float f = new Float(spaceProp.getLengthRange().getOptimum().getLength().getValue() / 1000f);
+ String sValue = f.toString() + "pt";
+
+ try {
+ rtfAttr.set(
+ RtfText.SPACE_BEFORE,
+ (int)FoUnitsConverter.getInstance().convertToTwips(sValue));
+ } catch(FOPException fe) {
+ log.warn("attrBlockSpaceBeforeAfter: " + fe.getMessage());
+ }
+ }
+
+ //space-after
+ spaceProp=(SpaceProperty)properties.get("space-after");
+ if(spaceProp!=null) {
+ Float f = new Float(spaceProp.getLengthRange().getOptimum().getLength().getValue() / 1000f);
+ String sValue = f.toString() + "pt";
+
+ try {
+ rtfAttr.set(
+ RtfText.SPACE_AFTER,
+ (int)FoUnitsConverter.getInstance().convertToTwips(sValue));
+ } catch(FOPException fe) {
+ log.warn("attrBlockSpaceBeforeAfter: " + fe.getMessage());
+ }
+ }
+ }
+
+ private static void attrBlockMargins(PropertyList properties, RtfAttributes rtfAttr) {
+ try {
+ LengthProperty lengthProp=null;
+
+ // margin-left
+ lengthProp=(LengthProperty)properties.get("margin-left");
+ if (lengthProp != null) {
+ Float f = new Float(lengthProp.getLength().getValue() / 1000f);
+ String sValue = f.toString() + "pt";
+
+ rtfAttr.set(
+ RtfText.LEFT_INDENT_BODY,
+ (int)FoUnitsConverter.getInstance().convertToTwips(sValue));
+ } else {
+ rtfAttr.set(RtfText.LEFT_INDENT_BODY, 0);
+ }
+
+ // margin-right
+ lengthProp=(LengthProperty)properties.get("margin-right");
+ if (lengthProp != null) {
+ Float f = new Float(lengthProp.getLength().getValue() / 1000f);
+ String sValue = f.toString() + "pt";
+
+ rtfAttr.set(
+ RtfText.LEFT_INDENT_BODY,
+ (int)FoUnitsConverter.getInstance().convertToTwips(sValue));
+ } else {
+ rtfAttr.set(RtfText.RIGHT_INDENT_BODY, 0);
+ }
+ } catch(FOPException fe) {
+ log.warn("attrBlockSpaceBeforeAfter: " + fe.getMessage());
+ }
+ }
+
+
+
+ private static void attrBlockTextAlign(PropertyList properties, RtfAttributes rtfAttr) {
+ int fopValue = properties.get("text-align").getEnum();
+ String rtfValue = null;
+ switch (fopValue) {
+ case Constants.CENTER: {
+ rtfValue = RtfText.ALIGN_CENTER;
+ break;
+ }
+ case Constants.END: {
+ rtfValue = RtfText.ALIGN_RIGHT;
+ break;
+ }
+ case Constants.JUSTIFY: {
+ rtfValue = RtfText.ALIGN_JUSTIFIED;
+ break;
+ }
+ default: {
+ rtfValue = RtfText.ALIGN_LEFT;
+ break;
+ }
+ }
+
+ rtfAttr.set(rtfValue);
+ }
+
+ /**
+ * Reads background-color from bl and writes it to rtfAttr.
+ *
+ * @param bl the Block object the properties are read from
+ * @param rtfAttr the RtfAttributes object the attributes are written to
+ */
+ private static void attrBlockBackgroundColor(PropertyList properties, RtfAttributes rtfAttr) {
+ ColorType fopValue = properties.get("background-color").getColorType();
+ int rtfColor = 0;
+ /* FOP uses a default background color of "transparent", which is
+ actually a transparent black, which is generally not suitable as a
+ default here. Changing FOP's default to "white" causes problems in
+ PDF output, so we will look for the default here & change it to
+ "auto". */
+ if ((fopValue.getRed() == 0)
+ && (fopValue.getGreen() == 0)
+ && (fopValue.getBlue() == 0)
+ && (fopValue.getAlpha() == 0)) {
+ rtfColor = 0; //=auto
+ } else {
+ rtfColor = convertFOPColorToRTF(fopValue);
+ }
+
+ rtfAttr.set(RtfText.ATTR_BACKGROUND_COLOR, rtfColor);
+ }
+
+ /**
+ * Converts a FOP ColorType to the integer pointing into the RTF color table
+ * @param fopColor the ColorType object to be converted
+ * @return integer pointing into the RTF color table
+ */
+ public static int convertFOPColorToRTF(ColorType fopColor) {
+ int redComponent = ColorType.convertChannelToInteger (fopColor.getRed());
+ int greenComponent = ColorType.convertChannelToInteger (fopColor.getGreen());
+ int blueComponent = ColorType.convertChannelToInteger (fopColor.getBlue());
+ return RtfColorTable.getInstance().getColorNumber(redComponent,
+ greenComponent, blueComponent).intValue();
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/exceptions/RtfException.java b/src/java/org/apache/fop/render/rtf/rtflib/exceptions/RtfException.java
new file mode 100644
index 000000000..b4d21ab47
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/exceptions/RtfException.java
@@ -0,0 +1,71 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.exceptions;
+
+/** Base class for rtflib exceptions.
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+public class RtfException extends java.io.IOException {
+ /**
+ * @param reason Description of reason for Exception.
+ */
+ public RtfException(String reason) {
+ super(reason);
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/exceptions/RtfStructureException.java b/src/java/org/apache/fop/render/rtf/rtflib/exceptions/RtfStructureException.java
new file mode 100644
index 000000000..3fe9174d3
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/exceptions/RtfStructureException.java
@@ -0,0 +1,72 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.exceptions;
+
+/** Thrown when a method call would lead to an invalid RTF document structure.
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+public class RtfStructureException
+extends RtfException {
+ /**
+ * @param reason Description of reason for exception.
+ */
+ public RtfStructureException(String reason) {
+ super(reason);
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/exceptions/package.html b/src/java/org/apache/fop/render/rtf/rtflib/exceptions/package.html
new file mode 100644
index 000000000..da0564ad2
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/exceptions/package.html
@@ -0,0 +1,6 @@
+<HTML>
+<TITLE>org.apache.fop.render.rtf.rtflib.exceptions</TITLE>
+<BODY>
+<P>Classes handling specialized exceptions that arise during RTF creation.</P>
+</BODY>
+</HTML> \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/interfaces/ITableColumnsInfo.java b/src/java/org/apache/fop/render/rtf/rtflib/interfaces/ITableColumnsInfo.java
new file mode 100644
index 000000000..f1ab9d7a8
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/interfaces/ITableColumnsInfo.java
@@ -0,0 +1,85 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.interfaces;
+
+/** Used to get information about tables, for example when handling nested tables
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+public interface ITableColumnsInfo {
+ /** value for invalid column width */
+ float INVALID_COLUM_WIDTH = 200f;
+
+ /** reset the column iteration index, meant to be called when creating a new row */
+ void selectFirstColumn();
+
+ /** increment the column iteration index */
+ void selectNextColumn();
+
+ /** get current column width according to column iteration index
+ * @return INVALID_COLUMN_WIDTH if we cannot find the value
+ */
+ float getColumnWidth();
+
+ /** @return current column iteration index */
+ int getColumnIndex();
+
+ /** @return number of columns */
+ int getNumberOfColumns();
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/interfaces/package.html b/src/java/org/apache/fop/render/rtf/rtflib/interfaces/package.html
new file mode 100644
index 000000000..3403d00ad
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/interfaces/package.html
@@ -0,0 +1,6 @@
+<HTML>
+<TITLE>org.apache.fop.render.rtf.rtflib.interfaces</TITLE>
+<BODY>
+<P>Interfaces used to build RTF documents.</P>
+</BODY>
+</HTML> \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/BorderAttributesConverter.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/BorderAttributesConverter.java
new file mode 100644
index 000000000..d29d1b480
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/BorderAttributesConverter.java
@@ -0,0 +1,182 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+/** Constants for RTF border attribute names, and a static method for converting
+ * fo attribute strings. */
+
+public class BorderAttributesConverter {
+
+ /** Constant for a single-thick border */
+ public static final String BORDER_SINGLE_THICKNESS = "brdrs";
+ /** Constant for a double-thick border */
+ public static final String BORDER_DOUBLE_THICKNESS = "brdrth";
+ /** Constant for a shadowed border */
+ public static final String BORDER_SHADOWED = "brdrsh";
+ /** Constant for a double border */
+ public static final String BORDER_DOUBLE = "brdrdb";
+ /** Constant for a dotted border */
+ public static final String BORDER_DOTTED = "brdrdot";
+ /** Constant for a dashed border */
+ public static final String BORDER_DASH = "brdrdash";
+ /** Constant for a hairline border */
+ public static final String BORDER_HAIRLINE = "brdrhair";
+ /** Constant for a small-dashed border */
+ public static final String BORDER_DASH_SMALL = "brdrdashsm";
+ /** Constant for a dot-dashed border */
+ public static final String BORDER_DOT_DASH = "brdrdashd";
+ /** Constant for a dot-dot-dashed border */
+ public static final String BORDER_DOT_DOT_DASH = "brdrdashdd";
+ /** Constant for a triple border */
+ public static final String BORDER_TRIPLE = "brdrtriple";
+ /** Constant for a think-thin-small border */
+ public static final String BORDER_THINK_THIN_SMALL = "brdrtnthsg";
+ /** Constant for a thin-thick-small border */
+ public static final String BORDER_THIN_THICK_SMALL = "brdrthtnsg";
+ /** Constant for a thin-thick-thin-small border */
+ public static final String BORDER_THIN_THICK_THIN_SMALL = "brdrthtnthsg";
+ /** Constant for a think-thin-medium border */
+ public static final String BORDER_THINK_THIN_MEDIUM = "brdrtnthmg";
+ /** Constant for a thin-thick-medium border */
+ public static final String BORDER_THIN_THICK_MEDIUM = "brdrthtnmg";
+ /** Constant for a thin-thick-thin-medium border */
+ public static final String BORDER_THIN_THICK_THIN_MEDIUM = "brdrthtnthmg";
+ /** Constant for a think-thin-large border */
+ public static final String BORDER_THINK_THIN_LARGE = "brdrtnthlg";
+ /** Constant for a thin-thick-large border */
+ public static final String BORDER_THIN_THICK_LARGE = "brdrthtnlg";
+ /** Constant for a thin-thick-thin-large border */
+ public static final String BORDER_THIN_THICK_THIN_LARGE = "brdrthtnthlg";
+ /** Constant for a wavy border */
+ public static final String BORDER_WAVY = "brdrwavy";
+ /** Constant for a double wavy border */
+ public static final String BORDER_WAVY_DOUBLE = "brdrwavydb";
+ /** Constant for a striped border */
+ public static final String BORDER_STRIPED = "brdrdashdotstr";
+ /** Constant for an embossed border */
+ public static final String BORDER_EMBOSS = "brdremboss";
+ /** Constant for an engraved border */
+ public static final String BORDER_ENGRAVE = "brdrengrave";
+ /** Constant for border color */
+ public static final String BORDER_COLOR = "brdrcf";
+ /** Constant for border space */
+ public static final String BORDER_SPACE = "brsp";
+ /** Constant for border width */
+ public static final String BORDER_WIDTH = "brdrw";
+
+ /** String array of border attributes */
+ public static final String [] BORDERS = new String[] {
+ BORDER_SINGLE_THICKNESS, BORDER_DOUBLE_THICKNESS, BORDER_SHADOWED,
+ BORDER_DOUBLE, BORDER_DOTTED, BORDER_DASH,
+ BORDER_HAIRLINE, BORDER_DASH_SMALL, BORDER_DOT_DASH,
+ BORDER_DOT_DOT_DASH, BORDER_TRIPLE, BORDER_THINK_THIN_SMALL,
+ BORDER_THIN_THICK_SMALL, BORDER_THIN_THICK_THIN_SMALL, BORDER_THINK_THIN_MEDIUM,
+ BORDER_THIN_THICK_MEDIUM, BORDER_THIN_THICK_THIN_MEDIUM, BORDER_THINK_THIN_LARGE,
+ BORDER_THIN_THICK_LARGE, BORDER_THIN_THICK_THIN_LARGE, BORDER_WAVY,
+ BORDER_WAVY_DOUBLE, BORDER_STRIPED, BORDER_EMBOSS,
+ BORDER_ENGRAVE, BORDER_COLOR, BORDER_SPACE,
+ BORDER_WIDTH
+ };
+
+ /**
+ * BorderAttributesConverter: Static Method for converting FO strings
+ * to RTF control words
+ * @param value FO string
+ * @return RTF control word
+ */
+ public static String convertAttributetoRtf(String value) {
+ // Added by Normand Masse
+ // "solid" is interpreted like "thin"
+ if (value.equals("thin") || value.equals("solid")) {
+ return BORDER_SINGLE_THICKNESS;
+ } else if (value.equals("thick")) {
+ return BORDER_DOUBLE_THICKNESS;
+ } else if (value.equals("shadowed")) {
+ return BORDER_SHADOWED;
+ } else if (value.equals("double")) {
+ return BORDER_DOUBLE;
+ } else if (value.equals("dotted")) {
+ return BORDER_DOTTED;
+ } else if (value.equals("dash")) {
+ return BORDER_DASH;
+ } else if (value.equals("hairline")) {
+ return BORDER_HAIRLINE;
+ } else if (value.equals("dot-dash")) {
+ return BORDER_DOT_DASH;
+ } else if (value.equals("dot-dot-dash")) {
+ return BORDER_DOT_DOT_DASH;
+ } else if (value.equals("triple")) {
+ return BORDER_TRIPLE;
+ } else if (value.equals("wavy")) {
+ return BORDER_WAVY;
+ } else if (value.equals("wavy-double")) {
+ return BORDER_WAVY_DOUBLE;
+ } else if (value.equals("striped")) {
+ return BORDER_STRIPED;
+ } else if (value.equals("emboss")) {
+ return BORDER_EMBOSS;
+ } else if (value.equals("engrave")) {
+ return BORDER_ENGRAVE;
+ } else {
+ return null;
+ }
+ }
+
+
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfAfterContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfAfterContainer.java
new file mode 100644
index 000000000..326e65e60
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfAfterContainer.java
@@ -0,0 +1,72 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+
+/** interface for RTF objects that can contain footers */
+public interface IRtfAfterContainer {
+ /**
+ *
+ * @param attrs Attributes for new footer
+ * @return RtfAfter for footer
+ * @throws IOException for I/O problems
+ */
+ RtfAfter newAfter(RtfAttributes attrs) throws IOException;
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfBeforeContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfBeforeContainer.java
new file mode 100644
index 000000000..362a12209
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfBeforeContainer.java
@@ -0,0 +1,75 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+
+/**
+ * Interface for classes containing headers.
+ */
+public interface IRtfBeforeContainer {
+
+ /**
+ *
+ * @param attrs Attributes of new header
+ * @return RtfBefore for new header object
+ * @throws IOException for I/O problems
+ */
+ RtfBefore newBefore(RtfAttributes attrs) throws IOException;
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfBookmarkContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfBookmarkContainer.java
new file mode 100644
index 000000000..e7516a3ab
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfBookmarkContainer.java
@@ -0,0 +1,77 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+
+/**
+ * RTF Bookmark container interface.
+ * @author <a href="mailto:a.putz@skynamics.com">Andreas Putz</a>
+ */
+public interface IRtfBookmarkContainer {
+
+ /**
+ * Create a new RTF bookmark.
+ * @param bookmark Name of the bookmark
+ * @return RTF bookmark
+ * @throws IOException for I/O problems
+ */
+ RtfBookmark newBookmark (String bookmark) throws IOException;
+}
+
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfExternalGraphicContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfExternalGraphicContainer.java
new file mode 100644
index 000000000..8770c8a48
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfExternalGraphicContainer.java
@@ -0,0 +1,74 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+
+/**
+ * Interface for classes containing images.
+ */
+public interface IRtfExternalGraphicContainer {
+
+ /**
+ * Creates a new image on external graphic base.
+ * @return RtfExternalGraphic for the new image
+ * @exception IOException On error
+ */
+ RtfExternalGraphic newImage () throws IOException;
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfHyperLinkContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfHyperLinkContainer.java
new file mode 100644
index 000000000..8a5b8cbab
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfHyperLinkContainer.java
@@ -0,0 +1,75 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+
+/** interface for RtfElements that can contain RtfHyperLinks
+ * @author Andreas Putz a.putz@skynamics.com
+ */
+public interface IRtfHyperLinkContainer extends IRtfTextContainer {
+ /**
+ * Creates a new hyperlink.
+ * @param str Hyperlink string
+ * @param attr Hyperlink attributes
+ * @exception IOException on error
+ * @return new Hyperlink object
+ */
+ RtfHyperLink newHyperLink (String str, RtfAttributes attr) throws IOException;
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfJforCmdContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfJforCmdContainer.java
new file mode 100644
index 000000000..42940f02b
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfJforCmdContainer.java
@@ -0,0 +1,75 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+
+import java.io.IOException;
+
+/**
+ * Interface for objects containing Commands
+ */
+public interface IRtfJforCmdContainer {
+ /**
+ *
+ * @param attr Attributes for the command
+ * @return new Command object
+ * @throws IOException for I/O problems
+ */
+ RtfJforCmd newJforCmd(RtfAttributes attr) throws IOException;
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfListContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfListContainer.java
new file mode 100644
index 000000000..09b6ca34b
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfListContainer.java
@@ -0,0 +1,74 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+
+/** Interface for RtfElements that can contain RtfLists
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+public interface IRtfListContainer {
+ /** Close the current list, if any, and starts a new one
+ * @param attrs attributes of new List
+ * @return new List object
+ * @throws IOException for I/O problems
+ */
+ RtfList newList(RtfAttributes attrs) throws IOException;
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfOptions.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfOptions.java
new file mode 100644
index 000000000..11a0bef35
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfOptions.java
@@ -0,0 +1,76 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+/**
+ * Options for configuring the rtf elements.
+ */
+public interface IRtfOptions {
+ /**
+ * Sets the compression rate for the external graphic in percent.
+ * @param percent Compression rate
+ */
+ void setRtfExternalGraphicCompressionRate (int percent);
+
+ /**
+ * Gets the compression rate for the external graphic in percent.
+ * @return Compression rate
+ */
+ int getRtfExternalGraphicCompressionRate ();
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfPageBreakContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfPageBreakContainer.java
new file mode 100644
index 000000000..35464b1f4
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfPageBreakContainer.java
@@ -0,0 +1,72 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+
+/** Interface for RtfElements that can contain RtfPageBreaks
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+public interface IRtfPageBreakContainer {
+ /** add a page break
+ * @throws IOException for I/O problems
+ */
+ void newPageBreak() throws IOException;
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfPageContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfPageContainer.java
new file mode 100644
index 000000000..3fc50e320
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfPageContainer.java
@@ -0,0 +1,74 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+
+/** Interface for RtfElements that can contain RtfText elements
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+public interface IRtfPageContainer {
+ /** close current text run if any and start a new one with specified attributes
+ * @param attrs attributes for the new Page
+ * @return new Page object
+ * @throws IOException for I/O problems.
+ */
+ RtfPage newPage(RtfAttributes attrs) throws IOException;
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfPageNumberCitationContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfPageNumberCitationContainer.java
new file mode 100644
index 000000000..38d442ee1
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfPageNumberCitationContainer.java
@@ -0,0 +1,74 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+
+/**
+ * Interface for classes containing page number citations
+ */
+public interface IRtfPageNumberCitationContainer {
+ /**
+ *
+ * @param id String identifying new page number citation
+ * @return RtfPageNumberCitation new page number citation object
+ * @throws IOException for I/O problems
+ */
+ RtfPageNumberCitation newPageNumberCitation(String id) throws IOException;
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfPageNumberContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfPageNumberContainer.java
new file mode 100644
index 000000000..45a0bc61a
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfPageNumberContainer.java
@@ -0,0 +1,74 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+
+/**
+ * Interface for objects containing page numbers
+ */
+public interface IRtfPageNumberContainer {
+
+ /**
+ *
+ * @return new RtfPageNumber
+ * @throws IOException for I/O problems.
+ */
+ RtfPageNumber newPageNumber() throws IOException;
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfParagraphContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfParagraphContainer.java
new file mode 100644
index 000000000..1d67670fb
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfParagraphContainer.java
@@ -0,0 +1,85 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+
+/** Interface for RtfElements that can contain RtfParagraphs
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+public interface IRtfParagraphContainer {
+ /**
+ * Close current paragraph, if any, and start a new one with default
+ * attributes.
+ * @throws IOException for I/O problems.
+ * @return new paragraph object
+ */
+ RtfParagraph newParagraph() throws IOException;
+
+ /**
+ * Close current paragraph, if any, and start a new one with specified
+ * attributes
+ * @param attr attributes for new paragraph
+ * @return new paragraph object
+ * @throws IOException for I/O problems.
+ */
+ RtfParagraph newParagraph(RtfAttributes attr) throws IOException;
+
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfParagraphKeepTogetherContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfParagraphKeepTogetherContainer.java
new file mode 100644
index 000000000..5e716ecd2
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfParagraphKeepTogetherContainer.java
@@ -0,0 +1,74 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+
+/**
+ * Interface for classes containing Paragraphs with Keep Together
+ */
+public interface IRtfParagraphKeepTogetherContainer {
+
+ /**
+ * Close current paragraph, if any, and start a new one
+ * @return new paragraph object (with keep together)
+ * @throws IOException for I/O problems
+ */
+ RtfParagraphKeepTogether newParagraphKeepTogether() throws IOException;
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTableContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTableContainer.java
new file mode 100644
index 000000000..77beecc63
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTableContainer.java
@@ -0,0 +1,86 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+import org.apache.fop.render.rtf.rtflib.interfaces.ITableColumnsInfo;
+
+/**
+ * Interface for RtfElements that can contain RtfTables
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ * @author Boris Poudérous
+ */
+public interface IRtfTableContainer {
+ /**
+ * Close current table, if any, and start a new one
+ * @param tc Table Columns Info
+ * @return new table object
+ * @throws IOException for I/O problems
+ */
+ RtfTable newTable(ITableColumnsInfo tc) throws IOException;
+
+ /**
+ * Close current table, if any, and start a new one
+ * @param attrs for the Table attributes
+ * @param tc to process number-columns-spanned attribute
+ * @return new table object
+ * @throws IOException for I/O problems
+ */
+ RtfTable newTable(RtfAttributes attrs, ITableColumnsInfo tc) throws IOException;
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTextContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTextContainer.java
new file mode 100644
index 000000000..254fe7dc3
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTextContainer.java
@@ -0,0 +1,96 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+
+/** Interface for RtfElements that can contain RtfText elements
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+public interface IRtfTextContainer {
+ /**
+ * Close current text element, if any, and start a new one
+ * @param str if not null, added to the RtfText created
+ * @param attr attributes for text
+ * @return new text object
+ * @throws IOException for I/O problems
+ */
+ RtfText newText(String str, RtfAttributes attr) throws IOException;
+
+ /**
+ * Close current text run, if any, and start a new one with default attributes
+ * @param str if not null, added to the RtfText created
+ * @return a new text object
+ * @throws IOException for I/O problems
+ */
+ RtfText newText(String str) throws IOException;
+
+ /**
+ * Add a line break
+ * @throws IOException for I/O problems
+ */
+ void newLineBreak() throws IOException;
+
+ /**
+ * Text containers usually provide default attributes for all texts that they contain.
+ * @return a copy of the container's attributes.
+ */
+ RtfAttributes getTextContainerAttributes();
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTextrunContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTextrunContainer.java
new file mode 100644
index 000000000..93cae8e2c
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTextrunContainer.java
@@ -0,0 +1,74 @@
+/*
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+
+/*
+ * This file is part of the RTF library of the FOP project.
+ */
+
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Iterator;
+import java.io.IOException;
+import org.apache.fop.render.rtf.rtflib.exceptions.RtfStructureException;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTextrun;
+
+/** Interface which enables an implementing class to contain linear text runs.
+ * @author Peter Herweg, pherweg@web.de
+ */
+
+public interface IRtfTextrunContainer {
+ public RtfTextrun getTextrun() throws IOException;
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableAttributes.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableAttributes.java
new file mode 100644
index 000000000..e85afc511
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableAttributes.java
@@ -0,0 +1,212 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+/**
+ * Constants for RTF table attribute names
+ * @author unascribed
+ * @author Boris POUDEROUS
+ * @author Chris Scott, Westinghouse
+ */
+public interface ITableAttributes {
+ /** to process column spanning */
+ public static final String COLUMN_SPAN = "number-columns-spanned";
+ /** to process row spanning */
+ public static final String ROW_SPAN = "number-rows-spanned";
+
+// RTF 1.5 attributes (word 97)
+
+ /** half the space between the cells of a table row in twips */
+ public static final String ATTR_RTF_15_TRGAPH = "trgaph";
+
+// RTF 1.6 Row and table attributes
+ /** table row padding, top */
+ public static final String ATTR_ROW_PADDING_TOP = "trpaddt";
+ /** table row padding, bottom */
+ public static final String ATTR_ROW_PADDING_BOTTOM = "trpaddb";
+ /** table row padding, left */
+ public static final String ATTR_ROW_PADDING_LEFT = "trpaddl";
+ /** table row padding, right */
+ public static final String ATTR_ROW_PADDING_RIGHT = "trpaddr";
+
+ /** table row padding, top */
+ public static final String ATTR_ROW_U_PADDING_TOP = "trpaddft";
+ /** table row padding, bottom */
+ public static final String ATTR_ROW_U_PADDING_BOTTOM = "trpaddfb";
+ /** table row padding, left */
+ public static final String ATTR_ROW_U_PADDING_LEFT = "trpaddfl";
+ /** table row padding, right */
+ public static final String ATTR_ROW_U_PADDING_RIGHT = "trpaddfr";
+
+ /**
+ * List of ALL ROW PADDING attributes, used to select them when writing
+ * attributes
+ */
+ public static final String[] ATTRIB_ROW_PADDING = {
+ ATTR_ROW_PADDING_TOP, ATTR_ROW_U_PADDING_TOP,
+ ATTR_ROW_PADDING_BOTTOM, ATTR_ROW_U_PADDING_BOTTOM,
+ ATTR_ROW_PADDING_LEFT, ATTR_ROW_U_PADDING_LEFT,
+ ATTR_ROW_PADDING_RIGHT, ATTR_ROW_U_PADDING_RIGHT,
+ ATTR_RTF_15_TRGAPH
+ };
+
+// Cell attributes
+ /** cell padding, top */
+ public static final String ATTR_CELL_PADDING_TOP = "clpadt";
+ /** cell padding, bottom */
+ public static final String ATTR_CELL_PADDING_BOTTOM = "clpadb";
+ /** cell padding, left */
+ public static final String ATTR_CELL_PADDING_LEFT = "clpadl";
+ /** cell padding, right */
+ public static final String ATTR_CELL_PADDING_RIGHT = "clpadr";
+
+ /** cell padding, top */
+ public static final String ATTR_CELL_U_PADDING_TOP = "clpadft";
+ /** cell padding, bottom */
+ public static final String ATTR_CELL_U_PADDING_BOTTOM = "clpadfb";
+ /** cell padding, left */
+ public static final String ATTR_CELL_U_PADDING_LEFT = "clpadfl";
+ /** cell padding, right */
+ public static final String ATTR_CELL_U_PADDING_RIGHT = "clpadfr";
+
+// for border style file
+ /** cell border, top */
+ public static final String CELL_BORDER_TOP = "clbrdrt";
+ /** cell border, bottom */
+ public static final String CELL_BORDER_BOTTOM = "clbrdrb";
+ /** cell border, left */
+ public static final String CELL_BORDER_LEFT = "clbrdrl";
+ /** cell border, right */
+ public static final String CELL_BORDER_RIGHT = "clbrdrr";
+
+//Table row border attributes
+ /** row border, top */
+ public static final String ROW_BORDER_TOP = "trbrdrt";
+ /** row border, bottom */
+ public static final String ROW_BORDER_BOTTOM = "trbrdrb";
+ /** row border, left */
+ public static final String ROW_BORDER_LEFT = "trbrdrl";
+ /** row border, right */
+ public static final String ROW_BORDER_RIGHT = "trbrdrr";
+ /** row border, horizontal */
+ public static final String ROW_BORDER_HORIZONTAL = "trbrdrh";
+ /** row border, vertical */
+ public static final String ROW_BORDER_VERTICAL = "trbrdrv";
+
+//Table row attributes
+ /** row attribute, keep-together */
+ public static final String ROW_KEEP_TOGETHER = "trkeep";
+ public static final String ROW_HEIGHT = "trrh";
+
+ /**
+ * This control word is nonexistent in RTF, used to simulate the
+ * FO:keep-with-next attribute.
+ */
+ public static final String ROW_KEEP_WITH_NEXT = "knext";
+
+ /**
+ * This control word is nonexistent in RTF, used to simulate the
+ * FO:keep-with-previous attribute.
+ */
+ public static final String ROW_KEEP_WITH_PREVIOUS = "kprevious";
+
+ /** cell shading, a unit-based attribute */
+ public static final String CELL_SHADE = "clshdng";
+ /** cell background color, a unit-based attribute */
+ public static final String CELL_COLOR_BACKGROUND = "clcbpat";
+ /** cell foreground color, a unit-based attribute */
+ public static final String CELL_COLOR_FOREGROUND = "clcfpat";
+
+ /**
+ * List of ALL CELL PADDING attributes, used to select them when writing
+ * attributes
+ */
+ public static final String[] ATTRIB_CELL_PADDING = {
+ ATTR_CELL_PADDING_TOP, ATTR_CELL_U_PADDING_TOP,
+ ATTR_CELL_PADDING_BOTTOM, ATTR_CELL_U_PADDING_BOTTOM,
+ ATTR_CELL_PADDING_LEFT, ATTR_CELL_U_PADDING_LEFT,
+ ATTR_CELL_PADDING_RIGHT, ATTR_CELL_U_PADDING_RIGHT,
+ };
+
+ /**
+ * List of ALL CELL BORDER attributes, used to select them when writing
+ * attributes
+ */
+ public static final String[] CELL_BORDER = {
+ CELL_BORDER_TOP, CELL_BORDER_BOTTOM,
+ CELL_BORDER_LEFT, CELL_BORDER_RIGHT
+ };
+
+ /**
+ * List of ALL ROW BORDER attributes, used to select them when writing
+ * attributes
+ */
+ public static final String[] ROW_BORDER = {
+ ROW_BORDER_TOP, ROW_BORDER_BOTTOM, ROW_BORDER_LEFT,
+ ROW_BORDER_RIGHT, ROW_BORDER_HORIZONTAL, ROW_BORDER_VERTICAL
+ };
+
+ /**
+ * List of ALL CELL SHADING AND COLOR attributes, used to select them when
+ * writing attributes
+ */
+ public static final String[] CELL_COLOR = {
+ CELL_SHADE, CELL_COLOR_BACKGROUND, CELL_COLOR_FOREGROUND
+ };
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IrtfTemplateContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IrtfTemplateContainer.java
new file mode 100644
index 000000000..dc2f945b1
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IrtfTemplateContainer.java
@@ -0,0 +1,78 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+
+/**
+ * Interface for classes containing templates.
+ */
+public interface IrtfTemplateContainer {
+
+ /**
+ * Creates a new Template.
+ * @param str description of Template
+ * @param attr attributes of Template
+ * @return new Template object
+ * @exception IOException on error
+ */
+ RtfTemplate newTemplate (String str, RtfAttributes attr) throws IOException;
+
+
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ParagraphKeeptogetherContext.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ParagraphKeeptogetherContext.java
new file mode 100644
index 000000000..8b0e10c07
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ParagraphKeeptogetherContext.java
@@ -0,0 +1,126 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+/**
+ *
+ * This context is used to manage the "keepn" RTF attribute
+ * Used by ParagraphBuilder and JforCmd
+ *
+ */
+
+public class ParagraphKeeptogetherContext {
+
+ private static int paraKeepTogetherOpen = 0;
+ private static boolean paraResetProperties = false;
+ private static ParagraphKeeptogetherContext instance = null;
+
+ ParagraphKeeptogetherContext() {
+ }
+
+
+ /**
+ * Singelton.
+ *
+ * @return The instance of ParagraphKeeptogetherContext
+ */
+ public static ParagraphKeeptogetherContext getInstance() {
+ if (instance == null) {
+ instance = new ParagraphKeeptogetherContext();
+ }
+ return instance;
+ }
+
+ /**
+ * @return the level of current "keep whith next" paragraph
+ */
+ public static int getKeepTogetherOpenValue() {
+ return paraKeepTogetherOpen;
+ }
+
+ /** Open a new "keep with next" paragraph */
+ public static void keepTogetherOpen() {
+ paraKeepTogetherOpen++;
+ }
+
+ /** Close a "keep with next" paragraph */
+ public static void keepTogetherClose() {
+ if (paraKeepTogetherOpen > 0) {
+ 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.
+ paraResetProperties = (paraKeepTogetherOpen == 0);
+ }
+ }
+
+ /**
+ * @return true if the next paragraph must reset the properties
+ */
+ public static boolean paragraphResetProperties() {
+ return paraResetProperties;
+ }
+
+ /** Reset the flag if the paragraph properties have been resested */
+ public static void setParagraphResetPropertiesUsed() {
+ paraResetProperties = false;
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfAfter.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfAfter.java
new file mode 100644
index 000000000..1d2b90ca8
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfAfter.java
@@ -0,0 +1,84 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+
+/** RtfContainer that encloses footers */
+public class RtfAfter extends RtfAfterBeforeBase {
+ /**RtfBefore attributes*/
+ public static final String FOOTER = "footer";
+ /** String array of footer attributes */
+ public static final String[] FOOTER_ATTR = new String[]{
+ FOOTER
+ };
+
+ RtfAfter(RtfSection parent, Writer w, RtfAttributes attrs) throws IOException {
+ super(parent, w, attrs);
+ }
+
+ /**
+ *
+ * @throws IOException for I/O problems
+ */
+ protected void writeMyAttributes() throws IOException {
+ writeAttributes(attrib, FOOTER_ATTR);
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfAfterBeforeBase.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfAfterBeforeBase.java
new file mode 100644
index 000000000..dd0c153cf
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfAfterBeforeBase.java
@@ -0,0 +1,164 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+import org.apache.fop.render.rtf.rtflib.interfaces.ITableColumnsInfo;
+
+/** Common code for RtfAfter and RtfBefore
+* @author Andreas Lambert <andreas.lambert@cronidesoft.com>
+* @author Christopher Scott, scottc@westinghouse.com
+* @author Christoph Zahm <zahm@jnet.ch> (support for tables in headers/footers)
+*/
+
+abstract class RtfAfterBeforeBase
+extends RtfContainer
+implements IRtfParagraphContainer, IRtfExternalGraphicContainer, IRtfTableContainer,
+ IRtfTextrunContainer {
+ protected RtfAttributes attrib;
+ private RtfParagraph para;
+ private RtfExternalGraphic externalGraphic;
+ private RtfTable table;
+
+ RtfAfterBeforeBase(RtfSection parent, Writer w, RtfAttributes attrs) throws IOException {
+ super((RtfContainer)parent, w, attrs);
+ attrib = attrs;
+ }
+
+ public RtfParagraph newParagraph() throws IOException {
+ closeAll();
+ para = new RtfParagraph(this, writer);
+ return para;
+ }
+
+ public RtfParagraph newParagraph(RtfAttributes attrs) throws IOException {
+ closeAll();
+ para = new RtfParagraph(this, writer, attrs);
+ return para;
+ }
+
+ public RtfExternalGraphic newImage() throws IOException {
+ closeAll();
+ externalGraphic = new RtfExternalGraphic(this, writer);
+ return externalGraphic;
+ }
+
+ private void closeCurrentParagraph() throws IOException {
+ if (para != null) {
+ para.close();
+ }
+ }
+
+ private void closeCurrentExternalGraphic() throws IOException {
+ if (externalGraphic != null) {
+ externalGraphic.close();
+ }
+ }
+
+ private void closeCurrentTable() throws IOException {
+ if (table != null) {
+ table.close();
+ }
+ }
+
+ protected void writeRtfPrefix() throws IOException {
+ writeGroupMark(true);
+ writeMyAttributes();
+ }
+
+ /** must be implemented to write the header or footer attributes */
+ protected abstract void writeMyAttributes() throws IOException;
+
+ protected void writeRtfSuffix() throws IOException {
+ writeGroupMark(false);
+ }
+
+ public RtfAttributes getAttributes() {
+ return attrib;
+ }
+
+ public void closeAll() throws IOException {
+ closeCurrentParagraph();
+ closeCurrentExternalGraphic();
+ closeCurrentTable();
+ }
+
+ /** 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 {
+ closeAll();
+ table = new RtfTable(this, writer, attrs, tc);
+ return table;
+ }
+
+ /** close current table if any and start a new one */
+ public RtfTable newTable(ITableColumnsInfo tc) throws IOException {
+ closeAll();
+ table = new RtfTable(this, writer, tc);
+ return table;
+ }
+
+ public RtfTextrun getTextrun()
+ throws IOException {
+ return RtfTextrun.getTextrun(this, writer, null);
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfAttributes.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfAttributes.java
new file mode 100644
index 000000000..351da81e0
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfAttributes.java
@@ -0,0 +1,239 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import org.xml.sax.Attributes;
+import org.xml.sax.helpers.AttributesImpl;
+
+
+/** Attributes for RtfText
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+public class RtfAttributes
+implements java.lang.Cloneable {
+ private HashMap values = new HashMap();
+
+ /**
+ * Set attributes from another attributes object
+ * @param attrs RtfAttributes object whose elements will be copied into this
+ * instance
+ * @return this object, for chaining calls
+ */
+ public RtfAttributes set (RtfAttributes attrs) {
+ if (attrs != null) {
+ Iterator it = attrs.nameIterator ();
+ while (it.hasNext ()) {
+ String name = (String) it.next ();
+ if (attrs.getValue(name) instanceof Integer) {
+ Integer value = (Integer)attrs.getValue (name);
+ if (value == null) {
+ set (name);
+ } else {
+ set (name, value.intValue ());
+ }
+ } else if (attrs.getValue(name) instanceof String) {
+ String value = (String)attrs.getValue (name);
+ if (value == null) {
+ set (name);
+ } else {
+ set (name, value);
+ }
+ } else {
+ set (name);
+ }
+
+
+ }
+ // indicate the XSL attributes used to build the Rtf attributes
+ setXslAttributes(attrs.getXslAttributes());
+ }
+ return this;
+ }
+
+ /**
+ * set an attribute that has no value.
+ * @param name name of attribute to set
+ * @return this object, for chaining calls
+ */
+ public RtfAttributes set(String name) {
+ values.put(name, null);
+ return this;
+ }
+
+ /**
+ * unset an attribute that has no value
+ * @param name name of attribute to unset
+ * @return this object, for chaining calls
+ */
+ public RtfAttributes unset(String name) {
+ values.remove(name);
+ return this;
+ }
+
+ /**
+ * debugging log
+ * @return String representation of object
+ */
+ public String toString() {
+ return values.toString() + "(" + super.toString() + ")";
+ }
+
+ /**
+ * implement cloning
+ * @return cloned Object
+ */
+ public Object clone() {
+ final RtfAttributes result = new RtfAttributes();
+ result.values = (HashMap)values.clone();
+
+ // Added by Normand Masse
+ // indicate the XSL attributes used to build the Rtf attributes
+ if (xslAttributes != null) {
+ result.xslAttributes = new org.xml.sax.helpers.AttributesImpl(xslAttributes);
+ }
+
+ return result;
+ }
+
+ /**
+ * Set an attribute that has an integer value
+ * @param name name of attribute
+ * @param value value of attribute
+ * @return this (which now contains the new entry), for chaining calls
+ */
+ public RtfAttributes set(String name, int value) {
+ values.put(name, new Integer(value));
+ return this;
+ }
+
+ /**
+ * Set an attribute that has a String value
+ * @param name name of attribute
+ * @param type value of attribute
+ * @return this (which now contains the new entry)
+ */
+ public RtfAttributes set(String name, String type) {
+ values.put(name, type);
+ return this;
+ }
+
+ /**
+ * @param name String containing attribute name
+ * @return the value of an attribute, null if not found
+ */
+ public Object getValue(String name) {
+ return values.get(name);
+ }
+
+ /**
+ * @param name String containing attribute name
+ * @return true if given attribute is set
+ */
+ public boolean isSet(String name) {
+ return values.containsKey(name);
+ }
+
+ /** @return an Iterator on all names that are set */
+ public Iterator nameIterator() {
+ return values.keySet().iterator();
+ }
+
+ private Attributes xslAttributes = null;
+
+ /**
+ * Added by Normand Masse
+ * Used for attribute inheritance
+ * @return Attributes
+ */
+ public Attributes getXslAttributes() {
+ return xslAttributes;
+ }
+
+ /**
+ * Added by Normand Masse
+ * Used for attribute inheritance
+ * @param pAttribs attributes
+ */
+ public void setXslAttributes(Attributes pAttribs) {
+ if (pAttribs == null) {
+ return;
+ }
+ // copy/replace the xsl attributes into the current attributes
+ if (xslAttributes != null) {
+ for (int i = 0; i < pAttribs.getLength(); i++) {
+ String wKey = pAttribs.getQName(i);
+ int wPos = xslAttributes.getIndex(wKey);
+ if (wPos == -1) {
+ ((AttributesImpl)xslAttributes).addAttribute(pAttribs.getURI(i),
+ pAttribs.getLocalName(i), pAttribs.getQName(i),
+ pAttribs.getType(i), pAttribs.getValue(i));
+ } else {
+ ((AttributesImpl)xslAttributes).setAttribute(wPos, pAttribs.getURI(i),
+ pAttribs.getLocalName(i), pAttribs.getQName(i),
+ pAttribs.getType(i), pAttribs.getValue(i));
+ }
+ }
+ } else {
+ xslAttributes = new org.xml.sax.helpers.AttributesImpl(pAttribs);
+ }
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfBefore.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfBefore.java
new file mode 100644
index 000000000..97ba666d1
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfBefore.java
@@ -0,0 +1,85 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+
+/** The opposite of RtfAfter */
+public class RtfBefore extends RtfAfterBeforeBase {
+ /**RtfBefore attributes*/
+ public static final String HEADER = "header";
+
+ /** String array of attribute names */
+ public static final String[] HEADER_ATTR = new String[]{
+ HEADER
+ };
+
+ RtfBefore(RtfSection parent, Writer w, RtfAttributes attrs) throws IOException {
+ super(parent, w, attrs);
+ }
+
+ /**
+ * Write the attributes for this element
+ * @throws IOException for I/O problems
+ */
+ protected void writeMyAttributes() throws IOException {
+ writeAttributes(attrib, HEADER_ATTR);
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfBookmark.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfBookmark.java
new file mode 100644
index 000000000..effa5c888
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfBookmark.java
@@ -0,0 +1,193 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+
+/**
+ * RTF Bookmark.
+ * Create an RTF bookmark as a child of given container with default attributes.
+ * This class belongs to the "id" attribute processing.
+ * @author <a href="mailto:a.putz@skynamics.com">Andreas Putz</a>
+ */
+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 final int MAX_BOOKMARK_LENGTH = 40;
+ /** Word 2000 converts '.' in bookmarks to "_", thats why we control this replacement. */
+ public static final char REPLACE_CHARACTER = '_';
+
+
+ //////////////////////////////////////////////////
+ // @@ Construction
+ //////////////////////////////////////////////////
+
+ /**
+ * Constructor.
+ *
+ * @param parent a <code>RtfBookmarkContainer</code> value
+ * @param writer a <code>Writer</code> 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 < MAX_BOOKMARK_LENGTH ? now : MAX_BOOKMARK_LENGTH);
+ this.bookmark = this.bookmark.replace ('.', REPLACE_CHARACTER);
+ this.bookmark = this.bookmark.replace (' ', REPLACE_CHARACTER);
+ }
+
+
+ //////////////////////////////////////////////////
+ // @@ 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);
+
+ writer.write (bookmark);
+ this.writeGroupMark (false);
+ }
+
+ /**
+ * @return 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/render/rtf/rtflib/rtfdoc/RtfBookmarkContainerImpl.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfBookmarkContainerImpl.java
new file mode 100644
index 000000000..face2ce09
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfBookmarkContainerImpl.java
@@ -0,0 +1,134 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+
+/**
+ * RTF Bookmark container implementation.
+ * Nearly all containers or elements can have a bookmark, that is why the bookmark container is
+ * implemented as stand alone.
+ * @author <a href="mailto:a.putz@skynamics.com">Andreas Putz</a>
+ */
+public class RtfBookmarkContainerImpl extends RtfContainer implements IRtfBookmarkContainer {
+ //////////////////////////////////////////////////
+ // @@ Members
+ //////////////////////////////////////////////////
+
+ /** Rtf bookmark */
+ private RtfBookmark mBookmark = null;
+
+
+ //////////////////////////////////////////////////
+ // @@ 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
+ * @param attr Rtf attributes
+ *
+ * @exception IOException On error
+ */
+ RtfBookmarkContainerImpl (RtfContainer parent, Writer w, RtfAttributes attr) throws IOException
+ {
+ super (parent, w, attr);
+ }
+
+
+ //////////////////////////////////////////////////
+ // @@ 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 ();
+ }
+
+ mBookmark = new RtfBookmark (this, writer, bookmark);
+
+ return mBookmark;
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfColorTable.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfColorTable.java
new file mode 100644
index 000000000..1297ba11c
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfColorTable.java
@@ -0,0 +1,274 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.util.Vector;
+import java.util.Hashtable;
+import java.io.IOException;
+
+/**
+ * Singelton of the RTF color table.
+ * This class was created for <fo:basic-link> tag processing.
+ * @author <a href="mailto:a.putz@skynamics.com">Andreas Putz</a>
+ */
+
+public class RtfColorTable {
+ //////////////////////////////////////////////////
+ // @@ Symbolic constants
+ //////////////////////////////////////////////////
+
+ // Defines the bit moving for the colors
+ private static final int RED = 16;
+ private static final int GREEN = 8;
+ private static final int BLUE = 0;
+
+
+ //////////////////////////////////////////////////
+ // @@ Members
+ //////////////////////////////////////////////////
+
+ /** 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;
+ /** Map of color names to color numbers */
+ private Hashtable namedColors = null;
+
+
+ //////////////////////////////////////////////////
+ // @@ Construction
+ //////////////////////////////////////////////////
+
+ /**
+ * 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).intValue());
+ addNamedColor("white", getColorNumber (255, 255, 255).intValue());
+ addNamedColor("red", getColorNumber (255, 0, 0).intValue());
+ addNamedColor("green", getColorNumber (0, 255, 0).intValue());
+ addNamedColor("blue", getColorNumber (0, 0, 255).intValue());
+ addNamedColor("cyan", getColorNumber (0, 255, 255).intValue());
+ addNamedColor("magenta", getColorNumber (255, 0, 255).intValue());
+ addNamedColor("yellow", getColorNumber (255, 255, 0).intValue());
+
+ 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).intValue());
+
+ getColorNumber (192, 192, 192);
+ }
+
+ /** define a named color for getColorNumber(String) */
+ private void addNamedColor(String name, int colorNumber) {
+ namedColors.put(name.toLowerCase(), new Integer(colorNumber));
+ }
+
+ //////////////////////////////////////////////////
+ // @@ Public methods
+ //////////////////////////////////////////////////
+
+ /**
+ * @param name a named color
+ * @return the RTF number of a named color, or null if name not found
+ */
+ 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 Integer 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 new Integer(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/render/rtf/rtflib/rtfdoc/RtfContainer.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfContainer.java
new file mode 100644
index 000000000..317ba6769
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfContainer.java
@@ -0,0 +1,239 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Iterator;
+import java.io.IOException;
+import org.apache.fop.render.rtf.rtflib.exceptions.RtfStructureException;
+
+/** An RtfElement that can contain other elements.
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+public class RtfContainer extends RtfElement {
+ private LinkedList children; // 'final' removed by Boris Poudérous on 07/22/2002
+ private RtfOptions options = new RtfOptions();
+ private RtfElement lastChild;
+
+ /** Create an RTF container as a child of given container */
+ RtfContainer(RtfContainer parent, Writer w) throws IOException {
+ this(parent, w, null);
+ }
+
+ /** Create an RTF container as a child of given container with given attributes */
+ RtfContainer(RtfContainer parent, Writer w, RtfAttributes attr) throws IOException {
+ super(parent, w, attr);
+ children = new LinkedList();
+ }
+
+ /**
+ * set options
+ * @param opt options to set
+ */
+ public void setOptions(RtfOptions opt) {
+ options = opt;
+ }
+
+ /**
+ * add a child element to this
+ * @param e child element to add
+ * @throws RtfStructureException for trying to add an invalid child (??)
+ */
+ protected void addChild(RtfElement e)
+ throws RtfStructureException {
+ if (isClosed()) {
+ // No childs should be added to a container that has been closed
+ final StringBuffer sb = new StringBuffer();
+ sb.append("addChild: container already closed (parent=");
+ sb.append(this.getClass().getName());
+ sb.append(" child=");
+ sb.append(e.getClass().getName());
+ sb.append(")");
+ final String msg = sb.toString();
+
+ // warn of this problem
+ final RtfFile rf = getRtfFile();
+// if(rf.getLog() != null) {
+// rf.getLog().logWarning(msg);
+// }
+
+ // TODO this should be activated to help detect XSL-FO constructs
+ // that we do not handle properly.
+ /*
+ throw new RtfStructureException(msg);
+ */
+ }
+
+ children.add(e);
+ lastChild = e;
+ }
+
+ /**
+ * @return a copy of our children's list
+ */
+ public List getChildren() {
+ return (List)children.clone();
+ }
+
+ /**
+ * @return the number of children
+ */
+ public int getChildCount() {
+ return children.size();
+ }
+
+ /**
+ * Add by Boris Poudérous on 07/22/2002
+ * Set the children list
+ * @param children list of child objects
+ * @return true if process succeeded
+ */
+ public boolean setChildren (List children) {
+ if (children instanceof LinkedList) {
+ this.children = (LinkedList)children;
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * write RTF code of all our children
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfContent()
+ throws IOException {
+ for (Iterator it = children.iterator(); it.hasNext();) {
+ final RtfElement e = (RtfElement)it.next();
+ e.writeRtf();
+ }
+ }
+
+ /** return our options */
+ RtfOptions getOptions() {
+ return options;
+ }
+
+ /** true if this (recursively) contains at least one RtfText object */
+ boolean containsText() {
+ boolean result = false;
+ for (Iterator it = children.iterator(); it.hasNext();) {
+ final RtfElement e = (RtfElement)it.next();
+ if (e instanceof RtfText) {
+ result = !e.isEmpty();
+ } else if (e instanceof RtfContainer) {
+ if (((RtfContainer)e).containsText()) {
+ result = true;
+ }
+ }
+ if (result) {
+ break;
+ }
+ }
+ return result;
+ }
+
+ /** debugging to given Writer */
+ void dump(Writer w, int indent)
+ throws IOException {
+ super.dump(w, indent);
+ for (Iterator it = children.iterator(); it.hasNext();) {
+ final RtfElement e = (RtfElement)it.next();
+ e.dump(w, indent + 1);
+ }
+ }
+
+ /**
+ * minimal debugging display
+ * @return String representation of object contents
+ */
+ public String toString() {
+ return super.toString() + " (" + getChildCount() + " children)";
+ }
+
+ /**
+ * @return false if empty or if our options block writing
+ */
+ protected boolean okToWriteRtf() {
+ boolean result = super.okToWriteRtf() && !isEmpty();
+ if (result && !options.renderContainer(this)) {
+ result = false;
+ }
+ return result;
+ }
+
+ /**
+ * @return true if this element would generate no "useful" RTF content,
+ * i.e. (for RtfContainer) true if it has no children where isEmpty() is false
+ */
+ public boolean isEmpty() {
+ boolean result = true;
+ for (Iterator it = children.iterator(); it.hasNext();) {
+ final RtfElement e = (RtfElement)it.next();
+ if (!e.isEmpty()) {
+ result = false;
+ break;
+ }
+ }
+ return result;
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfDocumentArea.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfDocumentArea.java
new file mode 100644
index 000000000..9558b8cb6
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfDocumentArea.java
@@ -0,0 +1,89 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+
+/** The RTF document area, container for RtfSection objects.
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+public class RtfDocumentArea
+extends RtfContainer {
+ private RtfSection currentSection;
+
+ /** Create an RTF element as a child of given container */
+ RtfDocumentArea(RtfFile f, Writer w) throws IOException {
+ super(f, w);
+ }
+
+ /**
+ * Close current RtfSection if any and create a new one
+ * @throws IOException for I/O problems
+ * @return the new RtfSection
+ */
+ public RtfSection newSection() throws IOException {
+ if (currentSection != null) {
+ currentSection.close();
+ }
+ currentSection = new RtfSection(this, writer);
+ return currentSection;
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfElement.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfElement.java
new file mode 100644
index 000000000..7147648a8
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfElement.java
@@ -0,0 +1,365 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+import java.util.Iterator;
+//import org.apache.fop.render.rtf.rtflib.jfor.main.JForVersionInfo;
+
+/** Base class for all elements of an RTF file.
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ * @author Andreas Putz a.putz@skynamics.com
+ */
+public abstract class RtfElement {
+ /** Writer to be used */
+ protected final Writer writer;
+ /** parent element */
+ protected final RtfContainer parent;
+ /** attributes of the element */
+ protected final RtfAttributes attrib;
+ private boolean written;
+ private boolean closed;
+ private final int id;
+ private static int idCounter;
+
+ /** Create an RTF element as a child of given container */
+ RtfElement(RtfContainer parent, Writer w) throws IOException {
+ this(parent, w, null);
+ }
+
+ /** Create an RTF element as a child of given container with given attributes */
+ RtfElement(RtfContainer parent, Writer w, RtfAttributes attr) throws IOException {
+
+ id = idCounter++;
+ this.parent = parent;
+ attrib = (attr != null ? attr : new RtfAttributes());
+ if (this.parent != null) {
+ this.parent.addChild(this);
+ }
+ writer = w;
+ written = false;
+ }
+
+ /**
+ * Does nothing, meant to allow elements to write themselves without waiting
+ * for write(), but not implemented yet
+ * @throws IOException for I/O problems
+ */
+ public final void close() throws IOException {
+ closed = true;
+ }
+
+ /**
+ * Write the RTF code of this element to our Writer
+ * @throws IOException for I/O problems
+ */
+ public final void writeRtf() throws IOException {
+ if (!written) {
+ written = true;
+ if (okToWriteRtf()) {
+ writeRtfPrefix();
+ writeRtfContent();
+ writeRtfSuffix();
+ }
+ }
+ }
+
+ /**
+ * Write an RTF control word to our Writer
+ * @param word RTF control word to write
+ * @throws IOException for I/O problems
+ */
+ protected final void writeControlWord(String word)
+ throws IOException {
+ writer.write('\\');
+ writer.write(word);
+ writer.write(' ');
+ }
+
+ /**
+ * Write an RTF control word to our Writer, preceeded by a star '*'
+ * meaning "ignore this if you don't know what it means"
+ * @param word RTF control word to write
+ * @throws IOException for I/O problems
+ */
+ protected final void writeStarControlWord(String word)
+ throws IOException {
+ writer.write("\\*\\");
+ writer.write(word);
+ writer.write(' ');
+ }
+
+ /**
+ * Same as writeStarControlWord(String word), except with no space behind it
+ * @param word RTF control word to write
+ * @throws IOException for I/O problems
+ */
+ protected final void writeStarControlWordNS(String word)
+ throws IOException {
+ writer.write("\\*\\");
+ writer.write(word);
+ }
+
+ /**
+ * Write rtf control word without the space behind it
+ * @param word RTF control word to write
+ * @throws IOException for I/O problems
+ */
+ protected final void writeControlWordNS(String word)
+ throws IOException {
+ writer.write('\\');
+ writer.write(word);
+ }
+
+ /**
+ * Called before writeRtfContent()
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfPrefix() throws IOException {
+ }
+
+ /**
+ * Must be implemented to write RTF content to m_writer
+ * @throws IOException for I/O problems
+ */
+ protected abstract void writeRtfContent() throws IOException;
+
+ /**
+ * Called after writeRtfContent()
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfSuffix() throws IOException {
+ }
+
+ /**
+ * Write a start or end group mark
+ * @param isStart set to true if this is a start mark
+ * @throws IOException for I/O problems
+ */
+ protected final void writeGroupMark(boolean isStart)
+ throws IOException {
+ writer.write(isStart ? "{" : "}");
+ }
+
+ /**
+ * Write given attribute values to our Writer
+ * @param attr RtfAttributes to be written
+ * @param nameList if given, only attribute names from this list are considered
+ * @throws IOException for I/O problems
+ */
+ protected void writeAttributes(RtfAttributes attr, String [] nameList)
+ throws IOException {
+ if (attr == null) {
+ return;
+ }
+
+ if (nameList != null) {
+ // process only given attribute names
+ for (int i = 0; i < nameList.length; i++) {
+ final String name = nameList[i];
+ if (attr.isSet(name)) {
+ writeOneAttribute(name, attr.getValue(name));
+ }
+ }
+ } else {
+ // process all defined attributes
+ for (Iterator it = attr.nameIterator(); it.hasNext();) {
+ final String name = (String)it.next();
+ if (attr.isSet(name)) {
+ writeOneAttribute(name, attr.getValue(name));
+ }
+ }
+ }
+ }
+
+ /**
+ * Write one attribute to our Writer
+ * @param name name of attribute to write
+ * @param value value of attribute to be written
+ * @throws IOException for I/O problems
+ */
+ protected void writeOneAttribute(String name, Object value)
+ throws IOException {
+ String cw = name;
+ if (value instanceof Integer) {
+ // attribute has integer value, must write control word + value
+ cw += value;
+ } else if (value instanceof String) {
+ cw += value;
+ }
+ writeControlWord(cw);
+ }
+
+ /**
+ * Write one attribute to our Writer without a space
+ * @param name name of attribute to write
+ * @param value value of attribute to be written
+ * @throws IOException for I/O problems
+ */
+ protected void writeOneAttributeNS(String name, Object value)
+ throws IOException {
+ String cw = name;
+ if (value instanceof Integer) {
+ // attribute has integer value, must write control word + value
+ cw += value;
+ } else if (value instanceof String) {
+ cw += value;
+ }
+ writeControlWordNS(cw);
+ }
+
+ /**
+ * can be overridden to suppress all RTF output
+ * @return true if this object can be written into the RTF
+ */
+ protected boolean okToWriteRtf() {
+ return true;
+ }
+
+ /** debugging to given PrintWriter */
+ void dump(Writer w, int indent)
+ throws IOException {
+ for (int i = 0; i < indent; i++) {
+ w.write(' ');
+ }
+ w.write(this.toString());
+ w.write('\n');
+ w.flush();
+ }
+
+ /**
+ * minimal debugging display
+ * @return String representation of object
+ */
+ public String toString() {
+ return (this == null) ? "null" : (this.getClass().getName() + " #" + id);
+ }
+
+ /** true if close() has been called */
+ boolean isClosed() {
+ return closed;
+ }
+
+ /** access our RtfFile, which is always the topmost parent */
+ RtfFile getRtfFile() {
+ // go up the chain of parents until we find the topmost one
+ RtfElement result = this;
+ while (result.parent != null) {
+ result = result.parent;
+ }
+
+ // topmost parent must be an RtfFile
+ // a ClassCastException here would mean that the parent-child structure is not as expected
+ return (RtfFile)result;
+ }
+
+ /** find the first parent where c.isAssignableFrom(parent.getClass()) is true
+ * @return null if not found
+ */
+ RtfElement getParentOfClass(Class c) {
+ RtfElement result = null;
+ RtfElement current = this;
+ while (current.parent != null) {
+ current = current.parent;
+ if (c.isAssignableFrom(current.getClass())) {
+ result = current;
+ break;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * @return true if this element would generate no "useful" RTF content
+ */
+ public abstract boolean isEmpty();
+
+ /**
+ * Make a visible entry in the RTF for an exception
+ * @param ie Exception to flag
+ * @throws IOException for I/O problems
+ */
+ protected void writeExceptionInRtf(Exception ie)
+ throws IOException {
+ writeGroupMark(true);
+ writeControlWord("par");
+
+ // make the exception message stand out so that the problem is visible
+ writeControlWord("fs48");
+// RtfStringConverter.getInstance().writeRtfString(m_writer,
+// JForVersionInfo.getShortVersionInfo() + ": ");
+ RtfStringConverter.getInstance().writeRtfString(writer, ie.getClass().getName());
+
+ writeControlWord("fs20");
+ RtfStringConverter.getInstance().writeRtfString(writer, " " + ie.toString());
+
+ writeControlWord("par");
+ writeGroupMark(false);
+ }
+
+ /**
+ * Added by Normand Masse
+ * Used for attribute inheritance
+ * @return RtfAttributes
+ */
+ public RtfAttributes getRtfAttributes() {
+ return attrib;
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java
new file mode 100644
index 000000000..76a6bc663
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java
@@ -0,0 +1,633 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import org.apache.fop.render.rtf.rtflib.tools.ImageConstants;
+import org.apache.fop.render.rtf.rtflib.tools.ImageUtil;
+//import org.apache.fop.render.rtf.rtflib.tools.jpeg.Encoder;
+//import org.apache.fop.render.rtf.rtflib.tools.jpeg.JPEGException;
+
+import java.io.BufferedInputStream;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.Writer;
+
+import java.io.File;
+import java.net.URL;
+import java.net.MalformedURLException;
+
+/**
+ * Creates an RTF image from an external graphic file.
+ * This class belongs to the <fo:external-graphic> tag processing. <br>
+ *
+ * Supports relative path like "../test.gif", too (01-08-24) <br>
+ *
+ * Limitations:
+ * <li> Only the image types PNG, JPEG and EMF are supported
+ * <li> The GIF is supported, too, but will be converted to JPG
+ * <li> Only the attributes SRC (required), WIDTH, HEIGHT, SCALING are supported
+ * <li> The SCALING attribute supports (uniform | non-uniform)
+ *
+ * Known Bugs:
+ * <li> If the emf image has a desired size, the image will be clipped
+ * <li> The emf, jpg & png image will not be displayed in correct size
+ *
+ * @author <a href="mailto:a.putz@skynamics.com">Andreas Putz</a>
+ * @author Gianugo Rabellino gianugo@rabellino.it
+ */
+
+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;
+
+ /** The image data */
+ private byte[] data = null;
+
+ /** The image type */
+ private int type;
+
+ //////////////////////////////////////////////////
+ // @@ Construction
+ //////////////////////////////////////////////////
+
+
+ /**
+ * Default constructor.
+ * Create an RTF element as a child of given container.
+ *
+ * @param container a <code>RtfContainer</code> value
+ * @param writer a <code>Writer</code> value
+ * @throws IOException for I/O problems
+ */
+ public RtfExternalGraphic(RtfContainer container, Writer writer) throws IOException {
+ super (container, writer);
+ }
+
+ /**
+ * Default constructor.
+ *
+ * @param container a <code>RtfContainer</code> value
+ * @param writer a <code>Writer</code> value
+ * @param attributes a <code>RtfAttributes</code> value
+ * @throws IOException for I/O problems
+ */
+ 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
+ * @throws IOException for I/O problems
+ */
+ 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 (writer == null) {
+ return;
+ }
+
+
+ if (url == null) {
+ throw new ExternalGraphicException("The attribute 'url' of "
+ + "<fo:external-graphic> is null.");
+ }
+
+ String linkToRoot = System.getProperty("jfor_link_to_root");
+ if (linkToRoot != null) {
+ writer.write("{\\field {\\* \\fldinst { INCLUDEPICTURE \"");
+ writer.write(linkToRoot);
+ File urlFile = new File(url.getFile());
+ writer.write(urlFile.getName());
+ writer.write("\" \\\\* MERGEFORMAT \\\\d }}}");
+ return;
+ }
+
+// getRtfFile ().getLog ().logInfo ("Writing image '" + url + "'.");
+
+
+ data = null;
+ try {
+ // image reading patch provided by Michael Krause <michakurt@web.de>
+ 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 "
+ + "<fo:external-graphic> has a invalid value: '"
+ + url + "' (" + e + ")");
+ }
+
+ if (data == null) {
+ return;
+ }
+
+ // Determine image file format
+ String file = url.getFile ();
+ 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 <fo:external-graphic> 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 <fo:external-graphic> "
+ + "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);
+
+ computeImageSize();
+ writeSizeInfo();
+
+ 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);
+ writer.write(chars);
+
+ // Writes the end of RTF image
+
+ writeGroupMark(false);
+ writeGroupMark(false);
+ }
+
+ private void computeImageSize () {
+ 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);
+ }
+ }
+
+ private void writeSizeInfo () throws IOException {
+ // 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);
+ }
+ }
+ }
+
+ //////////////////////////////////////////////////
+ // @@ 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 "
+ + "<fo:external-graphic> 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 if the compression rate is valid (0..100), false if 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;
+ }
+
+ /**
+ * @return true if this element would generate no "useful" RTF content
+ */
+ public boolean isEmpty() {
+ return url == null;
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExtraRowSet.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExtraRowSet.java
new file mode 100644
index 000000000..ed48363ad
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExtraRowSet.java
@@ -0,0 +1,343 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+import java.util.List;
+import java.util.LinkedList;
+import java.util.Iterator;
+import java.util.Collections;
+import org.apache.fop.render.rtf.rtflib.interfaces.ITableColumnsInfo;
+
+
+/**
+ * Used to add extra table rows after a row that contains a nested table:
+ * <li> created by RtfTableRow before generating RTF code
+ * <li> an RtfTableCell that contains a nested table can ask this to put
+ * some of its children in extra rows that after the current row
+ * <li> once RtfTableRow is done rendering its children, it renders this,
+ * causing extra rows to be generated, with content that can come
+ * from several RtfTableCells
+ *
+ * See org.apache.fop.rtf.rtflib.testdocs.NestedTable for an example of
+ * usage.
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+public class RtfExtraRowSet extends RtfContainer {
+ // TODO what is idnum?
+ static final int DEFAULT_IDNUM = 0;
+
+ /** Parent table context
+ * (added by Boris Poudérous on july 2002 in order to process nested tables)
+ */
+ private ITableColumnsInfo parentITableColumnsInfo = null;
+
+ /** While a top-level RtfTableRow is being rendered, we build a list of
+ * RtfTableCells that must be rendered in extra rows.
+ * This holds a cell with positioning information
+ */
+ private final List cells = new LinkedList();
+ private static class PositionedCell
+ implements Comparable {
+ private final RtfTableCell cell;
+ private final int xOffset;
+ private final int rowIndex;
+
+ PositionedCell(RtfTableCell c, int index, int offset) {
+ cell = c;
+ xOffset = offset;
+ rowIndex = index;
+ }
+
+ /** debugging dump */
+ public String toString() {
+ return "PositionedCell: row " + rowIndex + ", offset " + xOffset;
+ }
+
+ /** cells need to be sorted by row index and then by x offset */
+ public int compareTo(Object o) {
+ int result = 0;
+ if (o == null) {
+ result = 1;
+ } else if (!(o instanceof PositionedCell)) {
+ result = 1;
+ } else {
+ final PositionedCell pc = (PositionedCell)o;
+ if (this.rowIndex < pc.rowIndex) {
+ result = -1;
+ } else if (this.rowIndex > pc.rowIndex) {
+ result = 1;
+ } else if (this.xOffset < pc.xOffset) {
+ result = -1;
+ } else if (this.xOffset > pc.xOffset) {
+ result = 1;
+ }
+ }
+
+ return result;
+ }
+
+ public boolean equals(Object o) {
+ return o != null && this.compareTo(o) == 0;
+ }
+ }
+
+ /** our maximum row index */
+ private int maxRowIndex;
+
+ /** an RtfExtraRowSet has no parent, it is only used temporary during
+ * generation of RTF for an RtfTableRow
+ */
+ RtfExtraRowSet(Writer w)
+ throws IOException {
+ super(null, w);
+ }
+
+ /** Add all cells of given Table to this set for later rendering in extra rows
+ * @return index of extra row to use for elements that follow this table in the same cell
+ * @param rowIndex index of first extra row to create to hold cells of tbl
+ * @param xOffset horizontal position of left edge of first column of tbl
+ */
+ int addTable(RtfTable tbl, int rowIndex, int xOffset) {
+ // process all rows of the table
+ for (Iterator it = tbl.getChildren().iterator(); it.hasNext();) {
+ final RtfElement e = (RtfElement)it.next();
+ if (e instanceof RtfTableRow) {
+ addRow((RtfTableRow)e, rowIndex, xOffset);
+ rowIndex++;
+ maxRowIndex = Math.max(rowIndex, maxRowIndex);
+ }
+ }
+ return rowIndex;
+ }
+
+ /** add all cells of given row to this set */
+ private void addRow(RtfTableRow row, int rowIndex, int xOffset) {
+ for (Iterator it = row.getChildren().iterator(); it.hasNext();) {
+ final RtfElement e = (RtfElement)it.next();
+ if (e instanceof RtfTableCell) {
+ final RtfTableCell c = (RtfTableCell)e;
+ cells.add(new PositionedCell(c, rowIndex, xOffset));
+ xOffset += c.getCellWidth();
+ }
+ }
+ }
+
+ /** create an extra cell to hold content that comes after a nested table in a cell
+ * Modified by Boris Poudérous in order to permit the extra cell to have
+ * the attributes of its parent cell
+ */
+ RtfTableCell createExtraCell(int rowIndex, int xOffset, int cellWidth,
+ RtfAttributes parentCellAttributes)
+ throws IOException {
+ final RtfTableCell c = new RtfTableCell(null, writer, cellWidth,
+ parentCellAttributes, DEFAULT_IDNUM);
+ cells.add(new PositionedCell(c, rowIndex, xOffset));
+ return c;
+ }
+
+ /**
+ * render extra RtfTableRows containing all the extra RtfTableCells that we
+ * contain
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfContent() throws IOException {
+ // sort cells by rowIndex and xOffset
+ Collections.sort(cells);
+
+ // process all extra cells by rendering them into extra rows
+ List rowCells = null;
+ int rowIndex = -1;
+ for (Iterator it = cells.iterator(); it.hasNext();) {
+ final PositionedCell pc = (PositionedCell)it.next();
+ if (pc.rowIndex != rowIndex) {
+ // starting a new row, render previous one
+ if (rowCells != null) {
+ writeRow(rowCells);
+ }
+ rowIndex = pc.rowIndex;
+ rowCells = new LinkedList();
+ }
+ rowCells.add(pc);
+ }
+
+ // render last row
+ if (rowCells != null) {
+ writeRow(rowCells);
+ }
+ }
+
+ /** write one RtfTableRow containing given PositionedCells */
+ private void writeRow(List cells)
+ throws IOException {
+ if (allCellsEmpty(cells)) {
+ return;
+ }
+
+ final RtfTableRow row = new RtfTableRow(null, writer, DEFAULT_IDNUM);
+ int cellIndex = 0;
+
+ // Get the context of the table that holds the nested table
+ ITableColumnsInfo parentITableColumnsInfo = getParentITableColumnsInfo();
+ parentITableColumnsInfo.selectFirstColumn();
+
+ // X offset of the current empty cell to add
+ float xOffset = 0;
+ float xOffsetOfLastPositionedCell = 0;
+
+ for (Iterator it = cells.iterator(); it.hasNext();) {
+ final PositionedCell pc = (PositionedCell)it.next();
+
+ // if first cell is not at offset 0, add placeholder cell
+ // TODO should be merged with the cell that is above it
+ if (cellIndex == 0 && pc.xOffset > 0) {
+ /**
+ * Added by Boris Poudérous
+ */
+ // Add empty cells merged vertically with the cells above and with the same widths
+ // (BEFORE the cell that contains the nested table)
+ for (int i = 0; (xOffset < pc.xOffset)
+ && (i < parentITableColumnsInfo.getNumberOfColumns()); i++) {
+ // Get the width of the cell above
+ xOffset += parentITableColumnsInfo.getColumnWidth();
+ // Create the empty cell merged vertically
+ row.newTableCellMergedVertically((int)parentITableColumnsInfo.getColumnWidth(),
+ pc.cell.attrib);
+ // Select next column in order to have its width
+ parentITableColumnsInfo.selectNextColumn();
+ }
+ }
+
+ row.addChild(pc.cell);
+ // Line added by Boris Poudérous
+ xOffsetOfLastPositionedCell = pc.xOffset + pc.cell.getCellWidth();
+ cellIndex++;
+ }
+
+ /**
+ * Added by Boris Poudérous
+ */
+ // Add empty cells merged vertically with the cells above AFTER the cell
+ // that contains the nested table
+ // The cells added have the same widths than the cells above.
+ if (parentITableColumnsInfo.getColumnIndex()
+ < (parentITableColumnsInfo.getNumberOfColumns() - 1)) {
+ parentITableColumnsInfo.selectNextColumn();
+
+ while (parentITableColumnsInfo.getColumnIndex()
+ < parentITableColumnsInfo.getNumberOfColumns()) {
+ // Create the empty cell merged vertically
+ // TODO : the new cells after the extra cell don't have its
+ // attributes as we did for the previous cells.
+ // => in fact the m_attrib below (last argument) is
+ // empty => should be the attributes of the above cells.
+ row.newTableCellMergedVertically((int)parentITableColumnsInfo.getColumnWidth(),
+ attrib);
+ // Select next column in order to have its width
+ parentITableColumnsInfo.selectNextColumn();
+ }
+ }
+
+ row.writeRtf();
+ }
+
+ /** true if all cells of given list are empty
+ * @param cells List of PositionedCell objects
+ */
+ private static boolean allCellsEmpty(List cells) {
+ boolean empty = true;
+ for (Iterator it = cells.iterator(); it.hasNext();) {
+ final PositionedCell pc = (PositionedCell)it.next();
+ if (pc.cell.containsText()) {
+ empty = false;
+ break;
+ }
+ }
+ return empty;
+ }
+
+ /**
+ * As this contains cells from several rows, we say that it's empty
+ * only if we have no cells.
+ * writeRow makes the decision about rendering specific rows
+ * @return false (always)
+ */
+ public boolean isEmpty() {
+ return false;
+ }
+
+ /**
+ * @return The table context of the parent table
+ * Added by Boris Poudérous on july 2002 in order to process nested tables
+ */
+ public ITableColumnsInfo getParentITableColumnsInfo() {
+ return this.parentITableColumnsInfo;
+ }
+
+ /**
+ *
+ * @param parentITableColumnsInfo table context to set
+ */
+ public void setParentITableColumnsInfo (ITableColumnsInfo parentITableColumnsInfo) {
+ this.parentITableColumnsInfo = parentITableColumnsInfo;
+ }
+ /** - end - */
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFile.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFile.java
new file mode 100644
index 000000000..f05f56b99
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFile.java
@@ -0,0 +1,273 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import org.apache.fop.render.rtf.rtflib.exceptions.RtfStructureException;
+import java.io.Writer;
+import java.io.IOException;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.OutputStreamWriter;
+
+/**
+ * Models the top-level structure of an RTF file.
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ * @author Andreas Putz a.putz@skynamics.com
+ * @author Christopher Scott scottc@westinghouse.com
+ */
+
+public class RtfFile
+extends RtfContainer {
+ private RtfHeader header;
+ private RtfPageArea pageArea;
+ private RtfListTable listTable;
+ private RtfDocumentArea docArea;
+// private ConverterLogChannel m_log;
+ private RtfContainer listTableContainer;
+ private int listNum = 0;
+
+ /**
+ * Create an RTF file that outputs to the given Writer
+ * @param w the Writer to write to
+ * @throws IOException for I/O problems
+ */
+ 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
+ * @return the new RtfHeader
+ * @throws IOException for I/O problems
+ */
+ public RtfHeader startHeader()
+ throws IOException {
+ if (header != null) {
+ throw new RtfStructureException("startHeader called more than once");
+ }
+ header = new RtfHeader(this, writer);
+ listTableContainer = new RtfContainer(this, writer);
+ return header;
+ }
+
+ /**
+ * Creates the list table.
+ * @param attr attributes for the RtfListTable
+ * @return the new RtfListTable
+ * @throws IOException for I/O problems
+ */
+ public RtfListTable startListTable(RtfAttributes attr)
+ throws IOException {
+ listNum++;
+ listTable = new RtfListTable(this, writer, new Integer(listNum), attr);
+ listTableContainer.addChild(listTable);
+ return 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
+ * @return the RtfPageArea
+ * @throws IOException for I/O problems
+ * @throws RtfStructureException for illegal RTF structure
+ */
+ public RtfPageArea startPageArea()
+ throws IOException, RtfStructureException {
+ if (pageArea != null) {
+ throw new RtfStructureException("startPageArea called more than once");
+ }
+ // create an empty header if there was none
+ if (header == null) {
+ startHeader();
+ }
+ header.close();
+ pageArea = new RtfPageArea(this, writer);
+ addChild(pageArea);
+ return pageArea;
+ }
+
+ /**
+ * Call startPageArea if needed and return the page area object.
+ * @return the RtfPageArea
+ * @throws IOException for I/O problems
+ * @throws RtfStructureException for illegal RTF structure
+ */
+ public RtfPageArea getPageArea()
+ throws IOException, RtfStructureException {
+ if (pageArea == null) {
+ return startPageArea();
+ }
+ return pageArea;
+ }
+
+ /**
+ * Closes the RtfHeader if not done yet, and starts the document area.
+ * Must be called once only.
+ * @return the RtfDocumentArea
+ * @throws IOException for I/O problems
+ * @throws RtfStructureException for illegal RTF structure
+ */
+ public RtfDocumentArea startDocumentArea()
+ throws IOException, RtfStructureException {
+ if (docArea != null) {
+ throw new RtfStructureException("startDocumentArea called more than once");
+ }
+ // create an empty header if there was none
+ if (header == null) {
+ startHeader();
+ }
+ header.close();
+ docArea = new RtfDocumentArea(this, writer);
+ addChild(docArea);
+ return docArea;
+ }
+
+
+
+ /**
+ * Call startDocumentArea if needed and return the document area object.
+ * @return the RtfDocumentArea
+ * @throws IOException for I/O problems
+ * @throws RtfStructureException for illegal RTF structure
+ */
+ public RtfDocumentArea getDocumentArea()
+ throws IOException, RtfStructureException {
+ if (docArea == null) {
+ return startDocumentArea();
+ }
+ return docArea;
+ }
+
+ /**
+ * overridden to write RTF prefix code, what comes before our children
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfPrefix() throws IOException {
+ writeGroupMark(true);
+ writeControlWord("rtf1");
+ }
+
+ /**
+ * overridden to write RTF suffix code, what comes after our children
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfSuffix() throws IOException {
+ writeGroupMark(false);
+ }
+
+ /**
+ * must be called when done creating the document
+ * @throws IOException for I/O problems
+ */
+ public synchronized void flush() throws IOException {
+ writeRtf();
+ writer.flush();
+ }
+
+ /**
+ * minimal test and usage example
+ * @param args command-line arguments
+ * @throws Exception for problems
+ */
+ 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/render/rtf/rtflib/rtfdoc/RtfFontManager.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFontManager.java
new file mode 100644
index 000000000..6b4e13cde
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFontManager.java
@@ -0,0 +1,208 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+import java.util.Hashtable;
+import java.util.Vector;
+
+/**
+ * RTF font table
+ * @author Andreas Putz a.putz@skynamics.com
+ */
+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");
+
+/*
+ {\\f0\\fswiss Helv;}
+
+ // f1 is used by RtfList and RtfListItem for bullets
+
+ {\\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);
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFontTable.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFontTable.java
new file mode 100644
index 000000000..2674aa9e8
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFontTable.java
@@ -0,0 +1,84 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+
+/** RTF font table
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ * @author Andreas Putz a.putz@skynamics.com
+ */
+
+class RtfFontTable extends RtfElement {
+ /** 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)parent);
+ }
+
+ /** true if this element would generate no "useful" RTF content */
+ public boolean isEmpty() {
+ return false;
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfHeader.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfHeader.java
new file mode 100644
index 000000000..7051b195a
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfHeader.java
@@ -0,0 +1,130 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.io.Writer;
+import java.io.IOException;
+//import org.apache.fop.render.rtf.rtflib.jfor.main.JForVersionInfo;
+
+/** RTF file header, contains style, font and other document-level information.
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ * @author Andreas Putz a.putz@skynamics.com
+ */
+
+class RtfHeader extends RtfContainer {
+ private final String charset = "ansi";
+ private final Map userProperties = new HashMap();
+
+ /** Create an RTF header */
+ RtfHeader(RtfFile f, Writer w) throws IOException {
+ super(f, w);
+ new RtfFontTable(this, w);
+// m_userProperties.put("jforVersion",JForVersionInfo.getLongVersionInfo());
+ }
+
+ /** Overridden to write our own data before our children's data */
+ protected void writeRtfContent() throws IOException {
+ writeControlWord(charset);
+ writeUserProperties();
+ RtfColorTable.getInstance().writeColors(this);
+ super.writeRtfContent();
+ RtfTemplate.getInstance().writeTemplate(this);
+ RtfStyleSheetTable.getInstance().writeStyleSheet(this);
+
+ }
+
+ /** write user properties if any */
+ private void writeUserProperties() throws IOException {
+ if (userProperties.size() > 0) {
+ writeGroupMark(true);
+ writeStarControlWord("userprops");
+ for (Iterator it = userProperties.entrySet().iterator(); it.hasNext();) {
+ final Map.Entry entry = (Map.Entry)it.next();
+ writeGroupMark(true);
+ writeControlWord("propname");
+ RtfStringConverter.getInstance().writeRtfString(writer,
+ entry.getKey().toString());
+ writeGroupMark(false);
+ writeControlWord("proptype30");
+ writeGroupMark(true);
+ writeControlWord("staticval");
+ RtfStringConverter.getInstance().writeRtfString(writer,
+ entry.getValue().toString());
+ writeGroupMark(false);
+ }
+ writeGroupMark(false);
+ }
+ }
+
+ /** write directly to our Writer
+ * TODO should check that this done at the right point, or even better, store
+ * what is written here to render it in writeRtfContent. <-- it is for the color table
+ */
+ void write(String toWrite) throws IOException {
+ writer.write(toWrite);
+ }
+
+ /** write to our Writer using an RtfStringConverter */
+ void writeRtfString(String toWrite) throws IOException {
+ RtfStringConverter.getInstance().writeRtfString(writer, toWrite);
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfHyperLink.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfHyperLink.java
new file mode 100644
index 000000000..f1862ed3f
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfHyperLink.java
@@ -0,0 +1,243 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+
+/**
+ * Creates an hyperlink.
+ * This class belongs to the <fo:basic-link> tag processing.
+ * @author <a href="mailto:a.putz@skynamics.com">Andreas Putz</a>
+ *
+ * {\field {\*\fldinst HYPERLINK "http://www.test.de" }{\fldrslt Joe Smith}}
+ */
+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 parent a <code>RtfContainer</code> value
+ * @param writer a <code>Writer</code> value
+ * @param str text of the link
+ * @param attr a <code>RtfAttributes</code> value
+ * @throws IOException for I/O problems
+ */
+ 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");
+
+ 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 (attrib != null && attrib.isSet ("cs")) {
+ writeGroupMark (true);
+ writeAttributes(attrib, new String [] {"cs"});
+ }
+ }
+
+ /**
+ * Writes the RTF content to m_writer.
+ *
+ * @exception IOException On error
+ */
+ public void writeRtfSuffix () throws IOException {
+ if (attrib != null && 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
+ * @throws IOException for I/O problems
+ * @return new RtfText object
+ */
+ 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
+ * @param attr attributes of text to add
+ * @throws IOException for I/O problems
+ * @return the new RtfText object
+ */
+ public RtfText newText (String str, RtfAttributes attr) throws IOException {
+ closeAll ();
+ mText = new RtfText (this, writer, str, attr);
+ return mText;
+ }
+
+ /**
+ * IRtfTextContainer requirement:
+ * @return a copy of our attributes
+ */
+ public RtfAttributes getTextContainerAttributes() {
+ if (attrib == null) {
+ return null;
+ }
+ return (RtfAttributes) this.attrib.clone ();
+ }
+
+
+ /**
+ * add a line break
+ * @throws IOException for I/O problems
+ */
+ public void newLineBreak () throws IOException {
+ new RtfLineBreak (this, 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.MAX_BOOKMARK_LENGTH;
+ this.url = "#" + jumpTo.substring (0, now > max ? max : now);
+ this.url = this.url.replace ('.', RtfBookmark.REPLACE_CHARACTER);
+ this.url = this.url.replace (' ', RtfBookmark.REPLACE_CHARACTER);
+ }
+
+ /**
+ *
+ * @return false (always)
+ */
+ public boolean isEmpty () {
+ return false;
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfJforCmd.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfJforCmd.java
new file mode 100644
index 000000000..09d4a9360
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfJforCmd.java
@@ -0,0 +1,116 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+
+import java.io.Writer;
+import java.util.Iterator;
+import java.io.IOException;
+
+/**
+ * Process "jfor-cmd"
+ */
+public class RtfJforCmd extends RtfContainer {
+
+ private static final String PARA_KEEP_ON = "para-keep:on";
+ private static final String PARA_KEEP_OFF = "para-keep:off";
+
+ private final RtfAttributes attrib;
+ private ParagraphKeeptogetherContext paragraphKeeptogetherContext;
+
+
+
+ RtfJforCmd(RtfContainer parent, Writer w, RtfAttributes attrs) throws IOException {
+ super((RtfContainer)parent, w);
+ attrib = attrs;
+ paragraphKeeptogetherContext = ParagraphKeeptogetherContext.getInstance();
+ }
+
+
+ /**
+ *
+ * @return true (alway)
+ */
+ public boolean isEmpty() {
+ return true;
+ }
+
+ /**
+ * Execute all jfor-cmd commands
+ * TODO: Consider creating one class for each jfor command.
+ */
+ public void process() {
+ for (Iterator it = attrib.nameIterator(); it.hasNext();) {
+ final String cmd = (String)it.next();
+
+ if (cmd.equals(PARA_KEEP_ON)) {
+ paragraphKeeptogetherContext.keepTogetherOpen();
+ } else if (cmd.equals(PARA_KEEP_OFF)) {
+ paragraphKeeptogetherContext.keepTogetherClose();
+ } else {
+// this.getRtfFile ().getLog ().logInfo
+// ("JFOR-CMD ignored, command not recognised:"+cmd);
+ }
+
+ }
+
+
+ }
+
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfLineBreak.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfLineBreak.java
new file mode 100644
index 000000000..b98400ca5
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfLineBreak.java
@@ -0,0 +1,86 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+
+/** "Model" of an RTF line break
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+public class RtfLineBreak extends RtfElement {
+ /** Create an RTF paragraph as a child of given container with default attributes */
+ RtfLineBreak(IRtfTextContainer parent, Writer w) throws IOException {
+ super((RtfContainer)parent, w);
+ }
+
+ /**
+ * Overridden to write our attributes before our content
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfContent() throws IOException {
+ writeControlWord("line");
+ }
+
+ /** @return true if this element would generate no "useful" RTF content */
+ public boolean isEmpty() {
+ return false;
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfList.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfList.java
new file mode 100644
index 000000000..879e8ec70
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfList.java
@@ -0,0 +1,215 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+
+/**
+ * Model of an RTF list, which can contain RTF list items
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ * @author Christopher Scott, scottc@westinghouse.com
+ */
+public class RtfList extends RtfContainer {
+ private RtfListItem item;
+ private RtfListTable listTable;
+ private final boolean hasTableParent;
+
+ /** list numbering style.
+ * Could add more variables, for now we simply differentiate between bullets and numbering
+ */
+ private NumberingStyle numberingStyle;
+
+ /**
+ * Inner static class to handle numbering styles.
+ */
+ public static class NumberingStyle {
+ private boolean isBulletedList = true;
+
+ /**
+ * accessor for isBulletedList
+ * @return isBulletedList
+ */
+ public boolean getIsBulletedList() {
+ return isBulletedList;
+ }
+
+ /**
+ * set isBulletedList
+ * @param isBL boolean value to set
+ */
+ public void setIsBulletedList(boolean isBL) {
+ isBulletedList = isBL;
+ }
+ }
+
+ /** Create an RTF list as a child of given container with given attributes */
+ RtfList(RtfContainer parent, Writer w, RtfAttributes attr) throws IOException {
+ super((RtfContainer)parent, w, attr);
+ numberingStyle = new NumberingStyle();
+ //create a new list table entry for the list
+ listTable = (getRtfFile()).startListTable(attr);
+ listTable.setParentList(this);
+
+ // find out if we are nested in a table
+ hasTableParent = this.getParentOfClass(RtfTable.class) != null;
+ }
+
+ /**
+ * Change numbering style
+ * @param ns NumberingSytle to set
+ */
+ public void setNumberingStyle(NumberingStyle ns) {
+ numberingStyle = ns;
+ }
+
+ /**
+ * Overridden to setup the list: start a group with appropriate attributes
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfPrefix() throws IOException {
+ // pard causes word97 (and sometimes 2000 too) to crash if the list is nested in a table
+ if (!hasTableParent) {
+ writeControlWord("pard");
+ }
+
+ writeOneAttribute(RtfText.LEFT_INDENT_FIRST, attrib.getValue(RtfListTable.LIST_INDENT));
+ writeOneAttribute(RtfText.LEFT_INDENT_BODY, attrib.getValue(RtfText.LEFT_INDENT_BODY));
+
+ // put the whole list in a group
+ writeGroupMark(true);
+
+ // group for list setup info
+ writeGroupMark(true);
+
+ writeStarControlWord("pn");
+ //Modified by Chris Scott
+ //fixes second line indentation
+
+ if (numberingStyle.isBulletedList) {
+ // bulleted list
+ writeControlWord("pnlvlblt");
+ writeControlWord("ilvl0");
+ writeOneAttribute(RtfListTable.LIST_NUMBER,
+ (listTable.getListNumber()).toString());
+ writeOneAttribute("pnindent",
+ attrib.getValue(RtfListTable.LIST_INDENT));
+ writeControlWord("pnf1");
+ writeGroupMark(true);
+ writeControlWord("pndec");
+ writeOneAttribute(RtfListTable.LIST_FONT_TYPE, "2");
+ writeControlWord("pntxtb");
+ writeControlWord("'b7");
+ writeGroupMark(false);
+ } else {
+ // numbered list
+ writeControlWord("pnlvlbody");
+ writeControlWord("ilvl0");
+ writeOneAttribute(RtfListTable.LIST_NUMBER,
+ (numberingStyle.isBulletedList) ? "2" : "0");
+ writeControlWord("pndec");
+ writeOneAttribute("pnstart",
+ attrib.getValue(RtfListTable.LIST_START_AT));
+ writeOneAttribute("pnindent",
+ attrib.getValue(RtfListTable.LIST_INDENT));
+ writeControlWord("pntxta.");
+ }
+
+ writeGroupMark(false);
+ writeOneAttribute(RtfListTable.LIST_NUMBER,
+ (listTable.getListNumber()).toString());
+ }
+
+ /**
+ * End the list group
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfSuffix() throws IOException {
+ // close group that encloses the whole list
+ writeGroupMark(false);
+
+ /* reset paragraph defaults to make sure list ends
+ * but pard causes word97 (and sometimes 2000 too) to crash if the list
+ * is nested in a table
+ */
+ if (!hasTableParent) {
+ writeControlWord("pard");
+ }
+ }
+
+ /**
+ * Close current list item and start a new one
+ * @return new RtfListItem
+ * @throws IOException for I/O problems
+ */
+ public RtfListItem newListItem() throws IOException {
+ if (item != null) {
+ item.close();
+ }
+ item = new RtfListItem(this, writer);
+ return item;
+ }
+
+ /**
+ * @return true if this is a bulleted list (as opposed to numbered list)
+ */
+ public boolean isBulletedList() {
+ return numberingStyle.isBulletedList;
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListItem.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListItem.java
new file mode 100644
index 000000000..3ddad1922
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListItem.java
@@ -0,0 +1,136 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+
+/** Model of an RTF list item, which can contain RTF paragraphs
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ * @author Andreas Putz a.putz@skynamics.com
+ */
+public class RtfListItem
+extends RtfContainer
+implements IRtfParagraphContainer {
+ private RtfList parentList;
+ private RtfParagraph paragraph;
+
+ /** special RtfParagraph that writes list item setup code before its content */
+ private class RtfListItemParagraph extends RtfParagraph {
+
+ RtfListItemParagraph(RtfListItem rli, RtfAttributes attrs)
+ throws IOException {
+ super(rli, rli.writer, attrs);
+ }
+
+ protected void writeRtfPrefix() throws IOException {
+ super.writeRtfPrefix();
+ // for bulleted list, add list item setup group before paragraph contents
+ if (parentList.isBulletedList()) {
+ writeGroupMark(true);
+ writeControlWord("pntext");
+ writeControlWord("f" + RtfFontManager.getInstance().getFontNumber("Symbol"));
+ writeControlWord("'b7");
+ writeControlWord("tab");
+ writeGroupMark(false);
+ } else {
+ writeGroupMark(true);
+ writeControlWord("pntext");
+ writeGroupMark(false);
+ }
+ }
+
+ }
+
+ /** Create an RTF list item as a child of given container with default attributes */
+ RtfListItem(RtfList parent, Writer w) throws IOException {
+ super((RtfContainer)parent, w);
+ parentList = parent;
+ }
+
+ /** Create an RTF list item as a child of given container with given attributes */
+ RtfListItem(RtfList parent, Writer w, RtfAttributes attr) throws IOException {
+ super((RtfContainer)parent, w, attr);
+ parentList = parent;
+ }
+
+ /**
+ * Close current paragraph if any and start a new one
+ * @param attrs attributes of new paragraph
+ * @return new RtfParagraph
+ * @throws IOException for I/O problems
+ */
+ public RtfParagraph newParagraph(RtfAttributes attrs) throws IOException {
+ if (paragraph != null) {
+ paragraph.close();
+ }
+ paragraph = new RtfListItemParagraph(this, attrs);
+ return paragraph;
+ }
+
+ /**
+ * Close current paragraph if any and start a new one with default attributes
+ * @return new RtfParagraph
+ * @throws IOException for I/O problems
+ */
+ public RtfParagraph newParagraph() throws IOException {
+ return newParagraph(null);
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListTable.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListTable.java
new file mode 100644
index 000000000..d8152610d
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListTable.java
@@ -0,0 +1,244 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.util.Date;
+import java.util.Random;
+import java.io.Writer;
+import java.io.IOException;
+//import org.apache.fop.render.rtf.rtflib.jfor.main.JForVersionInfo;
+
+/**
+ * RtfListTable: used to make the list table in the header section of the RtfFile.
+ * This is the method that Word uses to make lists in RTF and the way most RTF readers,
+ * esp. Adobe FrameMaker read lists from RTF.
+ * @author Christopher Scott, scottc@westinghouse.com
+ */
+public class RtfListTable extends RtfContainer {
+
+ /** number of list in document */
+ private Integer listNum;
+ /** id of list */
+ private Integer listId;
+ private Integer listTemplateId;
+ private RtfList parentList;
+//static data members
+ /** constant for a list table */
+ public static final String LIST_TABLE = "listtable";
+ /** constant for a list */
+ public static final String LIST = "list";
+ /** constant for a list template id */
+ public static final String LIST_TEMPLATE_ID = "listtemplateid";
+ /** constant for a list level */
+ public static final String LIST_LEVEL = "listlevel";
+ /** constant for a list number type */
+ public static final String LIST_NUMBER_TYPE = "levelnfc";
+ /** constant for a list justification */
+ public static final String LIST_JUSTIFICATION = "leveljc";
+ /** constant for list following character */
+ public static final String LIST_FOLLOWING_CHAR = "levelfollow";
+ /** constant for list start at */
+ public static final String LIST_START_AT = "levelstartat";
+ /** constant for list space */
+ public static final String LIST_SPACE = "levelspace";
+ /** constant for list indentation */
+ public static final String LIST_INDENT = "levelindent";
+ /** constant for list text format */
+ public static final String LIST_TEXT_FORM = "leveltext";
+ /** constant for list number positioning */
+ public static final String LIST_NUM_POSITION = "levelnumbers";
+ /** constant for list name */
+ public static final String LIST_NAME = "listname ;";
+ /** constant for list ID */
+ public static final String LIST_ID = "listid";
+ /** constant for list font type */
+ public static final String LIST_FONT_TYPE = "f";
+ /** constant for list override table */
+ public static final String LIST_OVR_TABLE = "listoverridetable";
+ /** constant for list override */
+ public static final String LIST_OVR = "listoverride";
+ /** constant for list override count */
+ public static final String LIST_OVR_COUNT = "listoverridecount";
+ /** constant for list number */
+ public static final String LIST_NUMBER = "ls";
+
+ /** String array of list table attributes */
+ 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
+ };
+
+ /**
+ * RtfListTable Constructor: sets the number of the list, and allocates
+ * for the RtfAttributes
+ * @param parent RtfContainer holding this RtfListTable
+ * @param w Writer
+ * @param num number of the list in the document
+ * @param attrs attributes of new RtfListTable
+ * @throws IOException for I/O problems
+ */
+ public RtfListTable(RtfContainer parent, Writer w, Integer num, RtfAttributes attrs)
+ throws IOException {
+ super(parent, w, attrs);
+ listNum = new Integer(num.intValue());
+ //random number generator for ids
+ Date runTime = new Date();
+ Random listIdGenerator = new Random(runTime.getTime());
+ listId = new Integer(listIdGenerator.nextInt());
+ attrib.set(LIST_ID, listId.toString());
+ listTemplateId = new Integer(listIdGenerator.nextInt());
+ attrib.set(LIST_NUMBER_TYPE, 0);
+ }
+
+ /**
+ * Set parentList
+ * @param parent parentList to set
+ */
+ public void setParentList(RtfList parent) {
+ parentList = parent;
+ }
+
+ /**
+ * Accessor for listNum
+ * @return listNum
+ */
+ public Integer getListNumber() {
+ return listNum;
+ }
+
+ /** Set whether the list is a bulleted list not, and set attributes
+ * accordingly */
+ private void setListType() {
+ if (parentList.isBulletedList()) {
+ // bullet definition for bulleted lists
+ // Chris Scott's version was "\\\'01\\u-3913 ?;"
+ // 'b7 is what was used in jfor V0.5.2
+ attrib.set(LIST_TEXT_FORM, "\\\'01\\'b7 ?;");
+ attrib.set(LIST_NUM_POSITION);
+ attrib.set(LIST_NUMBER_TYPE, 23);
+ attrib.set(LIST_FONT_TYPE, 2);
+ } else {
+ attrib.set(LIST_TEXT_FORM, "\\\'03\\\'00. ;");
+ attrib.set(LIST_NUM_POSITION, "\\\'01;");
+ attrib.set(LIST_NUMBER_TYPE, 0);
+ attrib.set(LIST_FONT_TYPE, 0);
+ }
+ }
+
+ /**
+ * Write the content
+ * @throws IOException for I/O problems
+ */
+ public void writeRtfContent() throws IOException {
+ setListType();
+ writeGroupMark(true);
+ writeStarControlWordNS(LIST_TABLE);
+ writeGroupMark(true);
+
+ writeControlWordNS(LIST);
+ writeOneAttributeNS(LIST_TEMPLATE_ID, listTemplateId.toString());
+ writeOneAttributeNS(LIST, attrib.getValue(LIST));
+ writeGroupMark(true);
+ writeControlWordNS(LIST_LEVEL);
+ writeOneAttributeNS(LIST_NUMBER_TYPE, attrib.getValue(LIST_NUMBER_TYPE));
+ writeOneAttributeNS(LIST_JUSTIFICATION, attrib.getValue(LIST_JUSTIFICATION));
+ writeOneAttributeNS(LIST_FOLLOWING_CHAR, attrib.getValue(LIST_FOLLOWING_CHAR));
+ writeOneAttributeNS(LIST_START_AT, attrib.getValue(LIST_START_AT));
+ writeOneAttributeNS(LIST_SPACE, new Integer(0));
+ writeOneAttributeNS(LIST_INDENT, attrib.getValue(LIST_INDENT));
+ writeGroupMark(true);
+ writeOneAttributeNS(LIST_TEXT_FORM, attrib.getValue(LIST_TEXT_FORM));
+ writeGroupMark(false);
+ writeGroupMark(true);
+ writeOneAttributeNS(LIST_NUM_POSITION, attrib.getValue(LIST_NUM_POSITION));
+ writeGroupMark(false);
+ writeOneAttributeNS(LIST_FONT_TYPE, attrib.getValue(LIST_FONT_TYPE));
+ writeGroupMark(false);
+ writeGroupMark(true);
+ writeControlWordNS(LIST_NAME);
+ writeGroupMark(false);
+ writeOneAttributeNS(LIST_ID, listId.toString());
+ writeGroupMark(false);
+ writeGroupMark(false);
+ writeGroupMark(true);
+ writeStarControlWordNS(LIST_OVR_TABLE);
+ writeGroupMark(true);
+ writeControlWordNS(LIST_OVR);
+ writeOneAttributeNS(LIST_ID, listId.toString());
+ writeOneAttributeNS(LIST_OVR_COUNT, new Integer(0));
+ writeOneAttributeNS(LIST_NUMBER, listNum.toString());
+ writeGroupMark(false);
+ writeGroupMark(false);
+ }
+
+ /**
+ * Since this has no text content we have to overwrite isEmpty to print
+ * the table
+ * @return false (always)
+ */
+ public boolean isEmpty() {
+ return false;
+ }
+
+
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfNull.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfNull.java
new file mode 100644
index 000000000..1a88bcec7
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfNull.java
@@ -0,0 +1,73 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+
+/**
+ * @author Christopher Scott, scottc@westinghouse.com
+ */
+public class RtfNull
+extends RtfContainer {
+
+ 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/render/rtf/rtflib/rtfdoc/RtfOptions.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfOptions.java
new file mode 100644
index 000000000..98fe93cf7
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfOptions.java
@@ -0,0 +1,83 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+/**
+ * Simplistic options definitions for RTF generation
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+public class RtfOptions {
+ /**
+ * If this returns true, RtfParagraphs that have no children will not
+ * generate any RTF code
+ * @return true
+ */
+ public boolean ignoreEmptyParagraphs() {
+ return true;
+ }
+
+ /**
+ * If this returns false, RtfContainer will not generate any RTF
+ * @param c RtfContainer to be tested
+ * @return true
+ */
+ public boolean renderContainer(RtfContainer c) {
+ return true;
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPage.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPage.java
new file mode 100644
index 000000000..1d2a3a325
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPage.java
@@ -0,0 +1,138 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/** Specifies rtf control words. Is the container for page attributes.
+ * Overrides okToWriteRtf.
+ * @author Christopher Scott, scottc@westinghouse.com
+ */
+
+public class RtfPage
+extends RtfContainer {
+ private final RtfAttributes attrib;
+
+ /**RtfPage attributes*/
+ /** constant for page width */
+ public static final String PAGE_WIDTH = "paperw";
+ /** constant for page height */
+ public static final String PAGE_HEIGHT = "paperh";
+
+ /** constant for top margin */
+ public static final String MARGIN_TOP = "margt";
+ /** constant for bottom margin */
+ public static final String MARGIN_BOTTOM = "margb";
+ /** constant for left margin */
+ public static final String MARGIN_LEFT = "margl";
+ /** constant for right margin */
+ public static final String MARGIN_RIGHT = "margr";
+
+ /** String array of RtfPage attributes */
+ public static final 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);
+ attrib = attrs;
+ }
+
+ /**
+ * RtfPage writes the attributes the attributes contained in the string
+ * PAGE_ATTR, if not null
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfContent() throws IOException {
+ writeAttributes(attrib, PAGE_ATTR);
+
+ if (attrib != null) {
+ Object widthRaw = attrib.getValue(PAGE_WIDTH);
+ Object heightRaw = attrib.getValue(PAGE_HEIGHT);
+
+ if ((widthRaw instanceof Integer) && (heightRaw instanceof Integer)
+ && ((Integer) widthRaw).intValue() > ((Integer) heightRaw).intValue()) {
+ writeControlWord("landscape");
+ }
+ }
+ }
+
+ /**
+ * RtfPage - attributes accessor
+ * @return attributes
+ */
+ public RtfAttributes getAttributes() {
+ return 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.
+ * @return true
+ */
+ protected boolean okToWriteRtf() {
+ return true;
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageArea.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageArea.java
new file mode 100644
index 000000000..da4523423
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageArea.java
@@ -0,0 +1,99 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+
+/**
+ * @author Christopher Scott, scottc@westinghouse.com
+ */
+public class RtfPageArea
+extends RtfContainer {
+ private RtfPage currentPage;
+ private RtfNull nullChild;
+ private RtfAttributes childAttributes;
+
+ /** Create an RTF element as a child of given container */
+ RtfPageArea(RtfFile f, Writer w) throws IOException {
+ super(f, w);
+ }
+
+ /**
+ * Close current Rtfpage if any and create a new one
+ * @param attr attributes for new RtfPage
+ * @return new RtfPage
+ * @throws IOException for I/O problems
+ */
+ public RtfPage newPage(RtfAttributes attr) throws IOException {
+ if (currentPage != null) {
+ currentPage.close();
+ }
+ currentPage = new RtfPage(this, writer, attr);
+
+ return currentPage;
+ }
+
+ /**
+ * @return true
+ */
+ protected boolean okToWriteRtf() {
+ return true;
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageBreak.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageBreak.java
new file mode 100644
index 000000000..9586a2db8
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageBreak.java
@@ -0,0 +1,88 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+
+/** "Model" of an RTF page break
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+public class RtfPageBreak extends RtfElement {
+ /** Create an RTF paragraph as a child of given container with default attributes */
+ RtfPageBreak(IRtfPageBreakContainer parent, Writer w) throws IOException {
+ super((RtfContainer)parent, w);
+ }
+
+ /**
+ * Overridden to write our attributes before our content
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfContent() throws IOException {
+ writeControlWord("page");
+ }
+
+ /**
+ * @return true if this element would generate no "useful" RTF content
+ */
+ public boolean isEmpty() {
+ return false;
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumber.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumber.java
new file mode 100644
index 000000000..e2cdeb82b
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumber.java
@@ -0,0 +1,128 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+
+/**
+ * @author Christopher Scott, scottc@westinghouse.com
+ */
+public class RtfPageNumber extends RtfContainer {
+ /* RtfText attributes: fields
+ must be carefull of group markings and star control
+ ie page field:
+ "{\field {\*\fldinst {PAGE}} {\fldrslt}}"
+ */
+
+ /** constant for field */
+ public static final String RTF_FIELD = "field";
+ /** constant for field on page */
+ public static final String RTF_FIELD_PAGE = "fldinst { PAGE }";
+ /** constant for field result */
+ public static final 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 {
+ super((RtfContainer)parent, w);
+ }
+
+ /** Create an RTF page number as a child of given container with given attributes */
+ RtfPageNumber(RtfContainer parent, Writer w, RtfAttributes attrs) throws IOException {
+ // Adds the attributes of the parent paragraph
+ super(parent, w, attrs);
+ }
+
+ /** Create an RTF page number as a child of given paragraph,
+ * copying the paragraph attributes
+ */
+ RtfPageNumber(RtfParagraph parent, Writer w) throws IOException {
+ // Adds the attributes of the parent paragraph
+ super((RtfContainer)parent, w, parent.attrib);
+
+ // copy parent's text attributes
+ if (parent.getTextAttributes() != null) {
+ attrib.set(parent.getTextAttributes());
+ }
+ }
+
+ /**
+ * Write our attributes and content
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfContent() throws IOException {
+ writeGroupMark(true);
+ writeControlWord(RTF_FIELD);
+ writeGroupMark(true);
+ writeAttributes(attrib, RtfText.ATTR_NAMES); // Added by Boris Poudérous
+ writeStarControlWord(RTF_FIELD_PAGE);
+ writeGroupMark(false);
+ writeGroupMark(true);
+ writeControlWord(RTF_FIELD_RESULT);
+ writeGroupMark(false);
+ writeGroupMark(false);
+ }
+
+ /**
+ * @return true if this element would generate no "useful" RTF content
+ */
+ public boolean isEmpty() {
+ return false;
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java
new file mode 100644
index 000000000..66a8a07c2
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java
@@ -0,0 +1,148 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+
+/**
+ * @author Christopher Scott, scottc@westinghouse.com
+ * @author Boris Pouderous, boris.pouderous@free.fr
+ */
+public class RtfPageNumberCitation extends RtfContainer {
+ /* Page field :
+ "{\field {\*\fldinst {PAGEREF xx}} {\fldrslt}}" where xx represents the
+ 'id' of the referenced page
+ */
+
+ /** constant for field */
+ public static final String RTF_FIELD = "field";
+ /** constant for field pageref model */
+ public static final String RTF_FIELD_PAGEREF_MODEL = "fldinst { PAGEREF }";
+ /** constant for field result */
+ public static final String RTF_FIELD_RESULT = "fldrslt";
+
+ // 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 {
+ super((RtfContainer)parent, w);
+ this.id = id;
+ }
+
+ /** Create an RTF page number citation as a child of given
+ * paragraph, copying its attributes */
+ RtfPageNumberCitation (RtfParagraph parent, Writer w, String id)
+ throws IOException {
+ // add the attributes ant text attributes of the parent paragraph
+ super((RtfContainer)parent, w, parent.attrib);
+ if (parent.getTextAttributes() != null) {
+ attrib.set(parent.getTextAttributes());
+ }
+ this.id = id;
+ }
+
+ /**
+ * Write the content
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfContent() throws IOException {
+ // If we have a valid ID
+ if (isValid()) {
+ // Build page reference field
+ String pageRef = RTF_FIELD_PAGEREF_MODEL;
+ final int insertionIndex = pageRef.indexOf("}");
+ pageRef =
+ pageRef.substring(0, insertionIndex) + "\"" + id + "\"" + " "
+ + pageRef.substring(insertionIndex, pageRef.length())
+ ;
+ id = null;
+
+ // Write RTF content
+ writeGroupMark(true);
+ writeControlWord(RTF_FIELD);
+ writeGroupMark(true);
+ writeAttributes(attrib, RtfText.ATTR_NAMES); // Added by Boris Poudérous
+ writeStarControlWord(pageRef);
+ writeGroupMark(false);
+ writeGroupMark(true);
+ writeControlWord(RTF_FIELD_RESULT);
+ writeGroupMark(false);
+ writeGroupMark(false);
+ }
+ }
+
+ /** checks that the 'ref-id' attribute exists */
+ private boolean isValid() {
+ if (id != null) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * @return true if this element would generate no "useful" RTF content
+ */
+ public boolean isEmpty() {
+ return false;
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfParagraph.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfParagraph.java
new file mode 100644
index 000000000..789199150
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfParagraph.java
@@ -0,0 +1,377 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+import java.util.List;
+
+/** Model of an RTF paragraph, which can contain RTF text elements.
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ * @author Andreas Putz a.putz@skynamics.com
+ * @author Boris Poudérous, boris.pouderous@free.fr
+ */
+
+public class RtfParagraph extends RtfBookmarkContainerImpl
+implements IRtfTextContainer, IRtfPageBreakContainer, IRtfHyperLinkContainer,
+ IRtfExternalGraphicContainer, IRtfPageNumberContainer,
+ IRtfPageNumberCitationContainer {
+ private RtfText text;
+ private RtfHyperLink hyperlink;
+ private RtfExternalGraphic externalGraphic;
+ private RtfPageNumber pageNumber;
+ private RtfPageNumberCitation pageNumberCitation;
+ // Above line added by Boris POUDEROUS on 2002/07/09
+ private boolean keepn = false;
+ private boolean resetProperties = false;
+
+ /* needed for importing Rtf into FrameMaker
+ FrameMaker is not as forgiving as word in rtf
+ thus /pard/par must be written in a page break directly
+ after a table. /pard is probably needed in other places
+ also, this is just a hack to make FrameMaker import Jfor rtf
+ correctly */
+ private boolean writeForBreak = false;
+
+ /** Set of attributes that must be copied at the start of a paragraph */
+ private static final String [] PARA_ATTRIBUTES = { "intbl" };
+
+ /** Create an RTF paragraph as a child of given container with default attributes */
+ RtfParagraph(IRtfParagraphContainer parent, Writer w) throws IOException {
+ super((RtfContainer)parent, w);
+ }
+
+ /** Create an RTF paragraph as a child of given container with given attributes */
+ RtfParagraph(IRtfParagraphContainer parent, Writer w, RtfAttributes attr) throws IOException {
+ super((RtfContainer)parent, w, attr);
+ }
+
+ /**
+ * Accessor for the paragraph text
+ * @return the paragraph text
+ */
+ public String getText() {
+ return (text.getText());
+ }
+
+ /** Set the keepn attribute for this paragraph */
+ public void setKeepn() {
+ this.keepn = true;
+ }
+
+ /** Force reset properties */
+ public void setResetProperties() {
+ this.resetProperties = true;
+ }
+
+ /**
+ * IRtfTextContainer requirement: return a copy of our attributes
+ * @return a copy of this paragraphs attributes
+ */
+ public RtfAttributes getTextContainerAttributes() {
+ if (attrib == null) {
+ return null;
+ }
+ return (RtfAttributes)this.attrib.clone();
+ }
+
+ /**
+ * Overridden to write our attributes before our content
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfPrefix() throws IOException {
+ // collapse whitespace before writing out
+ // TODO could be made configurable
+ if (attrib != null && attrib.isSet("WhiteSpaceFalse")) {
+ attrib.unset("WhiteSpaceFalse");
+ } else {
+ new WhitespaceCollapser(this);
+ }
+
+ //Reset paragraph properties if needed
+ if (resetProperties) {
+ writeControlWord("pard");
+ }
+
+ /*
+ * Original comment said "do not write text attributes here, they are
+ * handled by RtfText." However, the text attributes appear to be
+ * relevant to paragraphs as well.
+ */
+ writeAttributes(attrib, RtfText.ATTR_NAMES);
+ writeAttributes(attrib, PARA_ATTRIBUTES);
+ // Added by Normand Masse
+ // Write alignment attributes after \intbl for cells
+ if (attrib.isSet("intbl") && mustWriteAttributes()) {
+ writeAttributes(attrib, RtfText.ALIGNMENT);
+ }
+
+ //Set keepn if needed (Keep paragraph with the next paragraph)
+ if (keepn) {
+ writeControlWord("keepn");
+ }
+
+ // start a group for this paragraph and write our own attributes if needed
+ if (mustWriteGroupMark()) {
+ writeGroupMark(true);
+ }
+
+
+ if (mustWriteAttributes()) {
+ // writeAttributes(m_attrib, new String [] {"cs"});
+ // Added by Normand Masse
+ // If \intbl then attributes have already been written (see higher in method)
+ if (!attrib.isSet("intbl")) {
+ writeAttributes(attrib, RtfText.ALIGNMENT);
+ }
+ //this line added by Chris Scott, Westinghouse
+ writeAttributes(attrib, RtfText.BORDER);
+ writeAttributes(attrib, RtfText.INDENT);
+ writeAttributes(attrib, RtfText.TABS);
+ if (writeForBreak) {
+ writeControlWord("pard\\par");
+ }
+ }
+
+ }
+
+ /**
+ * Overridden to close paragraph
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfSuffix() throws IOException {
+ // sometimes the end of paragraph mark must be suppressed in table cells
+ boolean writeMark = true;
+ if (parent instanceof RtfTableCell) {
+ writeMark = ((RtfTableCell)parent).paragraphNeedsPar(this);
+ }
+ if (writeMark) {
+ writeControlWord("par");
+ }
+
+ if (mustWriteGroupMark()) {
+ writeGroupMark(false);
+ }
+
+
+ }
+
+ /**
+ * Close current text run if any and start a new one with default attributes
+ * @param str if not null, added to the RtfText created
+ * @return the new RtfText object
+ * @throws IOException for I/O problems
+ */
+ 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
+ * @param attr attributes of the text
+ * @return the new RtfText object
+ * @throws IOException for I/O problems
+ */
+ public RtfText newText(String str, RtfAttributes attr) throws IOException {
+ closeAll();
+ text = new RtfText(this, writer, str, attr);
+ return text;
+ }
+
+ /**
+ * add a page break
+ * @throws IOException for I/O problems
+ */
+ public void newPageBreak() throws IOException {
+ writeForBreak = true;
+ new RtfPageBreak(this, writer);
+ }
+
+ /**
+ * add a line break
+ * @throws IOException for I/O problems
+ */
+ public void newLineBreak() throws IOException {
+ new RtfLineBreak(this, writer);
+ }
+
+ /**
+ * Add a page number
+ * @return new RtfPageNumber object
+ * @throws IOException for I/O problems
+ */
+ public RtfPageNumber newPageNumber()throws IOException {
+ pageNumber = new RtfPageNumber(this, writer);
+ return pageNumber;
+ }
+
+ /**
+ * Added by Boris POUDEROUS on 2002/07/09
+ * @param id string containing the citation text
+ * @return the new RtfPageNumberCitation object
+ * @throws IOException for I/O problems
+ */
+ public RtfPageNumberCitation newPageNumberCitation(String id) throws IOException {
+ pageNumberCitation = new RtfPageNumberCitation(this, writer, id);
+ return pageNumberCitation;
+ }
+
+ /**
+ * Creates a new hyperlink.
+ * @param str string containing the hyperlink text
+ * @param attr attributes of new hyperlink
+ * @return the new RtfHyperLink object
+ * @throws IOException for I/O problems
+ */
+ public RtfHyperLink newHyperLink(String str, RtfAttributes attr) throws IOException {
+ hyperlink = new RtfHyperLink(this, writer, str, attr);
+ return hyperlink;
+ }
+
+ /**
+ * Start a new external graphic after closing all other elements
+ * @return the new RtfExternalGraphic
+ * @throws IOException for I/O problems
+ */
+ public RtfExternalGraphic newImage() throws IOException {
+ closeAll();
+ externalGraphic = new RtfExternalGraphic(this, writer);
+ return externalGraphic;
+ }
+
+ private void closeCurrentText() throws IOException {
+ if (text != null) {
+ text.close();
+ }
+ }
+
+ private void closeCurrentHyperLink() throws IOException {
+ if (hyperlink != null) {
+ hyperlink.close();
+ }
+ }
+
+ private void closeAll() throws IOException {
+ closeCurrentText();
+ closeCurrentHyperLink();
+ }
+
+ /**
+ * Depending on RtfOptions, do not emit any RTF for empty paragraphs
+ * @return true if RTF should be written
+ */
+ protected boolean okToWriteRtf() {
+ boolean result = super.okToWriteRtf();
+
+ if (parent.getOptions().ignoreEmptyParagraphs() && getChildCount() == 0) {
+ // TODO should test that this is the last RtfParagraph in the cell instead
+ // of simply testing for last child??
+ result = false;
+ }
+
+ return result;
+ }
+
+ /** true if we must write our own (non-text) attributes in the RTF */
+ private boolean mustWriteAttributes() {
+ boolean writeAttributes = false;
+ final int children = getChildCount();
+ if (children > 0) {
+ final List childList = getChildren();
+ for (int i = 0; i < children; i++) {
+ final RtfElement el = (RtfElement) childList.get(i);
+ if (!el.isEmpty()) {
+ if (el.getClass() == RtfText.class) {
+ boolean tmp = ((RtfText) el).isNbsp();
+ if (!tmp) {
+ writeAttributes = true;
+ break;
+ }
+ } else {
+ writeAttributes = true;
+ break;
+ }
+ }
+ }
+ }
+ return writeAttributes;
+ }
+
+ /** true if we must write a group mark around this paragraph
+ * TODO is this correct, study interaction with mustWriteAttributes()
+ * <-- On implementation i have noticed if the groupmark set, the
+ * format attributes are only for this content, i think this
+ * implementation is ok
+ */
+ private boolean mustWriteGroupMark() {
+ return getChildCount() > 0;
+ }
+
+ /**
+ * accessor for text attributes
+ * @return attributes of the text
+ */
+ public RtfAttributes getTextAttributes() {
+ if (text == null) {
+ return null;
+ }
+ return text.getTextAttributes();
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfParagraphKeepTogether.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfParagraphKeepTogether.java
new file mode 100644
index 000000000..da7c67697
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfParagraphKeepTogether.java
@@ -0,0 +1,125 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+
+import java.io.Writer;
+import java.io.IOException;
+
+/**
+ * Models the keep together attributes of paragraphs
+ */
+public class RtfParagraphKeepTogether extends RtfContainer {
+
+ /** constant for unset status */
+ public static final int STATUS_NULL = 0;
+ /** constant for open paragraph */
+ public static final int STATUS_OPEN_PARAGRAPH = 1;
+ /** constant for close paragraph */
+ public static final int STATUS_CLOSE_PARAGRAPH = 2;
+
+ private int status = STATUS_NULL;
+
+
+ /** RtfParagraphKeepTogether*/
+ RtfParagraphKeepTogether(IRtfParagraphContainer parent, Writer w) throws IOException {
+ super((RtfContainer)parent, w);
+ }
+
+ /**
+ * Write the content
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfContent() throws IOException {
+
+ //First reet paragraph properties
+ // create a new one with keepn
+ if (status == STATUS_OPEN_PARAGRAPH) {
+ writeControlWord("pard");
+ writeControlWord("par");
+ writeControlWord("keepn");
+ writeGroupMark(true);
+ status = STATUS_NULL;
+ }
+
+
+ if (status == STATUS_CLOSE_PARAGRAPH) {
+ writeGroupMark(false);
+ status = STATUS_NULL;
+ }
+
+ }
+
+
+ /**
+ * set the status
+ * @param status the status to be set
+ */
+ public void setStatus(int status) {
+ this.status = status;
+ }
+
+ /**
+ * @return true if this element would generate no "useful" RTF content
+ */
+ public boolean isEmpty() {
+ return false;
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfSection.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfSection.java
new file mode 100644
index 000000000..d00aa38b4
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfSection.java
@@ -0,0 +1,271 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+import org.apache.fop.render.rtf.rtflib.interfaces.ITableColumnsInfo;
+
+/** Models a section in an RTF document
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+public class RtfSection
+extends RtfContainer
+implements
+ IRtfParagraphContainer,
+ IRtfTableContainer,
+ IRtfListContainer,
+ IRtfExternalGraphicContainer,
+ IRtfBeforeContainer,
+ IRtfParagraphKeepTogetherContainer,
+ IRtfAfterContainer,
+ IRtfJforCmdContainer,
+ IRtfTextrunContainer {
+ private RtfParagraph paragraph;
+ private RtfTable table;
+ private RtfList list;
+ private RtfExternalGraphic externalGraphic;
+ private RtfBefore before;
+ private RtfAfter after;
+ private RtfJforCmd 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
+ * @return new RtfExternalGraphic object
+ * @throws IOException for I/O problems
+ */
+ public RtfExternalGraphic newImage() throws IOException {
+ closeAll();
+ externalGraphic = new RtfExternalGraphic(this, writer);
+ return externalGraphic;
+ }
+
+ /**
+ * Start a new paragraph after closing current paragraph, list and table
+ * @param attrs attributes for new RtfParagraph
+ * @return new RtfParagraph object
+ * @throws IOException for I/O problems
+ */
+ public RtfParagraph newParagraph(RtfAttributes attrs) throws IOException {
+ closeAll();
+ paragraph = new RtfParagraph(this, writer, attrs);
+ return paragraph;
+ }
+
+ /**
+ * Close current paragraph if any and start a new one with default attributes
+ * @return new RtfParagraph
+ * @throws IOException for I/O problems
+ */
+ public RtfParagraph newParagraph() throws IOException {
+ return newParagraph(null);
+ }
+
+ /**
+ * Close current paragraph if any and start a new one
+ * @return new RtfParagraphKeepTogether
+ * @throws IOException for I/O problems
+ */
+ public RtfParagraphKeepTogether newParagraphKeepTogether() throws IOException {
+ return new RtfParagraphKeepTogether(this, 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)
+ * @return new RtfTable object
+ * @throws IOException for I/O problems
+ */
+ public RtfTable newTable(ITableColumnsInfo tc) throws IOException {
+ closeAll();
+ table = new RtfTable(this, writer, tc);
+ return table;
+ }
+
+ /**
+ * Start a new table after closing current paragraph, list and table
+ * @param attrs attributes of new RtfTable
+ * @param tc Table context used for number-columns-spanned attribute (added by
+ * Boris Poudérous on july 2002)
+ * @return new RtfTable object
+ * @throws IOException for I/O problems
+ */
+ public RtfTable newTable(RtfAttributes attrs, ITableColumnsInfo tc) throws IOException {
+ closeAll();
+ table = new RtfTable(this, writer, attrs, tc);
+ return table;
+ }
+
+ /**
+ * Start a new list after closing current paragraph, list and table
+ * @param attrs attributes of new RftList object
+ * @return new RtfList
+ * @throws IOException for I/O problems
+ */
+ public RtfList newList(RtfAttributes attrs) throws IOException {
+ closeAll();
+ list = new RtfList(this, writer, attrs);
+ return list;
+ }
+
+ /**
+ * IRtfBeforeContainer
+ * @param attrs attributes of new RtfBefore object
+ * @return new RtfBefore object
+ * @throws IOException for I/O problems
+ */
+ public RtfBefore newBefore(RtfAttributes attrs) throws IOException {
+ closeAll();
+ before = new RtfBefore(this, writer, attrs);
+ return before;
+ }
+
+ /**
+ * IRtfAfterContainer
+ * @param attrs attributes of new RtfAfter object
+ * @return new RtfAfter object
+ * @throws IOException for I/O problems
+ */
+ public RtfAfter newAfter(RtfAttributes attrs) throws IOException {
+ closeAll();
+ after = new RtfAfter(this, writer, attrs);
+ return after;
+ }
+
+ /**
+ *
+ * @param attrs attributes of new RtfJforCmd
+ * @return the new RtfJforCmd
+ * @throws IOException for I/O problems
+ */
+ public RtfJforCmd newJforCmd(RtfAttributes attrs) throws IOException {
+ jforCmd = new RtfJforCmd(this, writer, attrs);
+ return jforCmd;
+ }
+
+
+
+ /**
+ * Can be overridden to write RTF prefix code, what comes before our children
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfPrefix() throws IOException {
+ writeControlWord("sectd");
+ writeAttributes(attrib, RtfPage.PAGE_ATTR);
+ }
+
+ /**
+ * Can be overridden to write RTF suffix code, what comes after our children
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfSuffix() throws IOException {
+ writeControlWord("sect");
+ }
+
+ private void closeCurrentTable() throws IOException {
+ if (table != null) {
+ table.close();
+ }
+ }
+
+ private void closeCurrentParagraph() throws IOException {
+ if (paragraph != null) {
+ paragraph.close();
+ }
+ }
+
+ private void closeCurrentList() throws IOException {
+ if (list != null) {
+ list.close();
+ }
+ }
+
+ private void closeCurrentExternalGraphic() throws IOException {
+ if (externalGraphic != null) {
+ externalGraphic.close();
+ }
+ }
+
+ private void closeCurrentBefore() throws IOException {
+ if (before != null) {
+ before.close();
+ }
+ }
+
+ private void closeAll()
+ throws IOException {
+ closeCurrentTable();
+ closeCurrentParagraph();
+ closeCurrentList();
+ closeCurrentExternalGraphic();
+ closeCurrentBefore();
+ }
+
+ public RtfTextrun getTextrun()
+ throws IOException {
+ return RtfTextrun.getTextrun(this, writer, null);
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfString.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfString.java
new file mode 100644
index 000000000..8ef95fe0c
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfString.java
@@ -0,0 +1,100 @@
+/*
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/** Plain text in a RTF file, without any formatings.
+ * @author Peter Herweg, pherweg@web.de
+ */
+
+public class RtfString extends RtfElement
+{
+ String text="";
+
+ RtfString(RtfContainer parent, Writer w, String s)
+ throws IOException {
+ super(parent, w);
+
+ text=s;
+ }
+
+ /**
+ * @return true if this element would generate no "useful" RTF content
+ */
+ public boolean isEmpty() {
+ return text.trim().equals("");
+ }
+
+ /**
+ * write RTF code of all our children
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfContent() throws IOException {
+ RtfStringConverter.getInstance().writeRtfString(writer, text);
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String s) {
+ text=s;
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfStringConverter.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfStringConverter.java
new file mode 100644
index 000000000..678d97402
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfStringConverter.java
@@ -0,0 +1,153 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.io.IOException;
+import java.io.Writer;
+
+/** Converts java Strings according to RTF conventions
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+public class RtfStringConverter {
+ private static final RtfStringConverter INSTANCE = new RtfStringConverter();
+
+ private static final Map SPECIAL_CHARS;
+ private static final Character DBLQUOTE = new Character('\"');
+ private static final Character QUOTE = new Character('\'');
+ private static final Character SPACE = new Character(' ');
+
+ /** List of characters to escape with corresponding replacement strings */
+ static {
+ SPECIAL_CHARS = new HashMap();
+ SPECIAL_CHARS.put(new Character('\t'), "tab");
+ SPECIAL_CHARS.put(new Character('\n'), "line");
+ SPECIAL_CHARS.put(new Character('\''), "rquote");
+ SPECIAL_CHARS.put(new Character('\"'), "rdblquote");
+ SPECIAL_CHARS.put(new Character('\\'), "\\");
+ SPECIAL_CHARS.put(new Character('{'), "{");
+ SPECIAL_CHARS.put(new Character('}'), "}");
+ }
+
+ /** singleton pattern */
+ private RtfStringConverter() {
+ }
+
+ /**
+ * use this to get an object of this class
+ * @return the singleton instance
+ */
+ public static RtfStringConverter getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Write given String to given Writer, converting characters as required by
+ * RTF spec
+ * @param w Writer
+ * @param str String to be written
+ * @throws IOException for I/O problems
+ */
+ public void writeRtfString(Writer w, String str) throws IOException {
+ if (str == null) {
+ return;
+ }
+
+ // TODO: could be made more efficient (binary lookup, etc.)
+ for (int i = 0; i < str.length(); i++) {
+ final Character c = new Character(str.charAt(i));
+ Character d;
+ String replacement;
+ if (i != 0) {
+ d = new Character(str.charAt(i - 1));
+ } else {
+ d = new Character(str.charAt(i));
+ }
+
+ //This section modified by Chris Scott
+ //add "smart" quote recognition
+ if (c.equals((Object)DBLQUOTE) && d.equals((Object)SPACE)) {
+ replacement = "ldblquote";
+ } else if (c.equals((Object)QUOTE) && d.equals((Object)SPACE)) {
+ replacement = "lquote";
+ } else {
+ replacement = (String)SPECIAL_CHARS.get(c);
+ }
+
+ if (replacement != null) {
+ // RTF-escaped char
+ w.write('\\');
+ w.write(replacement);
+ w.write(' ');
+ } else if (c.charValue() > 255) {
+ // write unicode representation - contributed by Michel Jacobson
+ // <jacobson@idf.ext.jussieu.fr>
+ w.write("\\u");
+ w.write(Integer.toString((int)c.charValue()));
+ w.write("\\\'3f");
+ } else {
+ // plain char that is understood by RTF natively
+ w.write(c.charValue());
+ }
+ }
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfStyleSheetTable.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfStyleSheetTable.java
new file mode 100644
index 000000000..344c0d80d
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfStyleSheetTable.java
@@ -0,0 +1,275 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.util.Vector;
+import java.util.Hashtable;
+import java.io.IOException;
+import java.util.Iterator;
+
+/**
+ * Singelton of the RTF style sheet table.
+ * This class belongs to the <jfor:stylesheet> tag processing.
+ * @author <a href="mailto:a.putz@skynamics.com">Andreas Putz</a>
+ */
+public class RtfStyleSheetTable {
+ //////////////////////////////////////////////////
+ // @@ Symbolic constants
+ //////////////////////////////////////////////////
+
+ /** Start index number for the stylesheet reference table */
+ private static int startIndex = 15;
+
+ /** OK status value for attribute handling */
+ public static final int STATUS_OK = 0;
+ /** Status value for attribute handling, if the stylesheet not found and
+ * the stylesheet set to the default stylesheet */
+ public static final int STATUS_DEFAULT = 1;
+
+ /** Standard style name */
+ private static final 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 attr 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/render/rtf/rtflib/rtfdoc/RtfTable.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTable.java
new file mode 100644
index 000000000..5d6bda9ee
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTable.java
@@ -0,0 +1,196 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+import org.apache.fop.render.rtf.rtflib.interfaces.ITableColumnsInfo;
+
+/** Container for RtfRow elements
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+public class RtfTable extends RtfContainer {
+ private RtfTableRow row;
+ private int highestRow = 0;
+
+ /** Added by Boris Poudérous on 07/22/2002 in order to process
+ * number-columns-spanned attribute */
+ private ITableColumnsInfo tableContext;
+
+ /** Create an RTF element as a child of given container */
+ RtfTable(IRtfTableContainer parent, Writer w, ITableColumnsInfo tc)
+ throws IOException {
+ super((RtfContainer)parent, w);
+ // Line added by Boris Poudérous on 07/22/2002
+ tableContext = tc;
+ }
+
+ /** 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);
+ // Line added by Boris Poudérous on 07/22/2002
+ tableContext = tc;
+ }
+
+ /**
+ * Close current row if any and start a new one
+ * @return new RtfTableRow
+ * @throws IOException for I/O problems
+ */
+ public RtfTableRow newTableRow() throws IOException {
+ if (row != null) {
+ row.close();
+ }
+
+ highestRow++;
+ row = new RtfTableRow(this, writer, attrib, highestRow);
+ return row;
+ }
+
+ /**
+ * Close current row if any and start a new one
+ * @param attrs attributs of new RtfTableRow
+ * @return new RtfTableRow
+ * @throws IOException for I/O problems
+ */
+ public RtfTableRow newTableRow(RtfAttributes attrs) throws IOException {
+ RtfAttributes attr = null;
+ if (attrib != null) {
+ attr = (RtfAttributes) attrib.clone ();
+ attr.set (attrs);
+ } else {
+ attr = attrs;
+ }
+ if (row != null) {
+ row.close();
+ }
+ highestRow++;
+
+ row = new RtfTableRow(this, writer, attr, highestRow);
+ return row;
+ }
+
+
+
+ /**
+ * Overridden to write RTF prefix code, what comes before our children
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfPrefix() throws IOException {
+ writeGroupMark(true);
+ }
+
+ /**
+ * Overridden to write RTF suffix code, what comes after our children
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfSuffix() throws IOException {
+ writeGroupMark(false);
+ }
+
+ /**
+ *
+ * @param id row to check (??)
+ * @return true if id is the highestRow
+ */
+ public boolean isHighestRow(int id) {
+ return (highestRow == id) ? true : false;
+ }
+
+ /**
+ * Added by Boris Poudérous on 07/22/2002
+ * @return ITableColumnsInfo for this table
+ */
+ public ITableColumnsInfo getITableColumnsInfo() {
+ return this.tableContext;
+ }
+
+ private RtfAttributes headerAttribs = null;
+
+ /**
+ * Added by Normand Masse
+ * Support for table-header attributes (used instead of table attributes)
+ * @param attrs attributes to be set
+ */
+ public void setHeaderAttribs(RtfAttributes attrs) {
+ headerAttribs = attrs;
+ }
+
+ public RtfAttributes getHeaderAttribs() {
+ return headerAttribs;
+ }
+
+ /**
+ * Added by Normand Masse
+ * @return the table-header attributes if they are present, otherwise the
+ * parent's attributes are returned normally.
+ */
+ public RtfAttributes getRtfAttributes() {
+ if (headerAttribs != null) {
+ return headerAttribs;
+ }
+
+ return super.getRtfAttributes();
+ }
+ /** - end - */
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java
new file mode 100644
index 000000000..f84b5c970
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java
@@ -0,0 +1,486 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.Writer;
+import java.io.IOException;
+import java.util.Iterator;
+import org.apache.fop.render.rtf.rtflib.interfaces.ITableColumnsInfo;
+
+/** A cell in an RTF table, container for paragraphs, lists, etc.
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+public class RtfTableCell
+extends RtfContainer
+implements IRtfParagraphContainer, IRtfListContainer, IRtfTableContainer,
+ IRtfExternalGraphicContainer, IRtfTextrunContainer {
+ private RtfParagraph paragraph;
+ private RtfList list;
+ private RtfTable table;
+ private RtfExternalGraphic externalGraphic;
+ private final RtfTableRow parentRow;
+ private boolean setCenter;
+ private boolean setRight;
+ private int id;
+
+ /** default cell width (in twips ??) */
+ public static final int DEFAULT_CELL_WIDTH = 2000;
+
+ /** cell width in twips */
+ private int cellWidth;
+ private int widthOffset;
+
+ /** cell merging has three states */
+ private int vMerge = NO_MERGE;
+ private int hMerge = NO_MERGE;
+
+ /** cell merging: this cell is not merged */
+ public static final int NO_MERGE = 0;
+
+ /** cell merging: this cell is the start of a range of merged cells */
+ public static final int MERGE_START = 1;
+
+ /** cell merging: this cell is part of (but not the start of) a range of merged cells */
+ public static final int MERGE_WITH_PREVIOUS = 2;
+
+ /** Create an RTF element as a child of given container */
+ RtfTableCell(RtfTableRow parent, Writer w, int cellWidth, int idNum) throws IOException {
+ super(parent, w);
+ id = idNum;
+ parentRow = parent;
+ this.cellWidth = cellWidth;
+ setCenter = setRight = false;
+
+ }
+
+ /** Create an RTF element as a child of given container */
+ RtfTableCell(RtfTableRow parent, Writer w, int cellWidth, RtfAttributes attrs,
+ int idNum) throws IOException {
+ super(parent, w, attrs);
+ id = idNum;
+ parentRow = parent;
+ this.cellWidth = cellWidth;
+
+ /** Added by Boris Poudérous on 07/22/2002 in order to process
+ * number-columns-spanned attribute */
+ // If the cell is spanned horizontally
+ if (attrs.getValue("number-columns-spanned") != null) {
+ // Start horizontal merge
+ this.setHMerge(MERGE_START);
+
+ // Get the number of columns spanned
+ int nbMergedCells = ((Integer)attrs.getValue("number-columns-spanned")).intValue();
+
+ if (parent.parent instanceof RtfTable) {
+ // Get the context of the current table in order to get the width of each column
+ ITableColumnsInfo tableColumnsInfo =
+ ((RtfTable)parent.parent).getITableColumnsInfo();
+ tableColumnsInfo.selectFirstColumn();
+
+ // Reach the column index in table context corresponding to the current column cell
+ // id is the index of the current cell (it begins at 1)
+ // getColumnIndex() is the index of the current column in table context (it begins at 0)
+ // => so we must widthdraw 1 when comparing these two variables.
+ while ((this.id - 1) != tableColumnsInfo.getColumnIndex()) {
+ tableColumnsInfo.selectNextColumn();
+ }
+
+ // We widthdraw one cell because the first cell is already created
+ // (it's the current cell) !
+ int i = nbMergedCells - 1;
+ while (i > 0) {
+ tableColumnsInfo.selectNextColumn();
+ // Added by Normand Masse
+ // Pass in the current cell's attributes so the 'merged' cell has the
+ // same display attributes.
+ parent.newTableCellMergedHorizontally((int)tableColumnsInfo.getColumnWidth(),
+ attrs);
+
+ i--;
+ }
+ }
+ }
+ /** - end - */
+ }
+
+ /**
+ * Start a new paragraph after closing current current paragraph, list and table
+ * @param attrs attributes of new RtfParagraph
+ * @return new RtfParagraph object
+ * @throws IOException for I/O problems
+ */
+ public RtfParagraph newParagraph(RtfAttributes attrs) throws IOException {
+ closeAll();
+
+ // in tables, RtfParagraph must have the intbl attribute
+ if (attrs == null) {
+ attrs = new RtfAttributes();
+ }
+ attrs.set("intbl");
+
+ paragraph = new RtfParagraph(this, writer, attrs);
+
+ if (paragraph.attrib.isSet("qc")) {
+ setCenter = true;
+ attrs.set("qc");
+ } else if (paragraph.attrib.isSet("qr")) {
+ setRight = true;
+ attrs.set("qr");
+ } else {
+ attrs.set("ql");
+ }
+ attrs.set("intbl");
+
+
+ //lines modified by Chris Scott, Westinghouse
+ return paragraph;
+ }
+
+ /**
+ * Start a new external graphic after closing current paragraph, list and table
+ * @throws IOException for I/O problems
+ * @return new RtfExternalGraphic object
+ */
+ public RtfExternalGraphic newImage() throws IOException {
+ closeAll();
+ externalGraphic = new RtfExternalGraphic(this, writer);
+ return externalGraphic;
+ }
+
+ /**
+ * Start a new paragraph with default attributes after closing current
+ * paragraph, list and table
+ * @return new RtfParagraph object
+ * @throws IOException for I/O problems
+ */
+ public RtfParagraph newParagraph() throws IOException {
+ return newParagraph(null);
+ }
+
+ /**
+ * Start a new list after closing current paragraph, list and table
+ * @param attrib attributes for new RtfList
+ * @return new RtfList object
+ * @throws IOException for I/O problems
+ */
+ public RtfList newList(RtfAttributes attrib) throws IOException {
+ closeAll();
+ list = new RtfList(this, writer, attrib);
+ return list;
+ }
+
+ /**
+ * Start a new nested table after closing current paragraph, list and table
+ * @param tc table column info for new RtfTable
+ * @return new RtfTable object
+ * @throws IOException for I/O problems
+ */
+ public RtfTable newTable(ITableColumnsInfo tc) throws IOException {
+ closeAll();
+ table = new RtfTable(this, writer, tc);
+ return table;
+ }
+
+ /**
+ * Start a new nested table after closing current paragraph, list and table
+ * @param attrs attributes of new RtfTable
+ * @param tc table column info for new RtfTable
+ * @return new RtfTable object
+ * @throws IOException for I/O problems
+ */
+ // Modified by Boris Poudérous on 07/22/2002
+ public RtfTable newTable(RtfAttributes attrs, ITableColumnsInfo tc) throws IOException {
+ closeAll();
+ table = new RtfTable(this, writer, attrs, tc); // Added tc Boris Poudérous 07/22/2002
+ return table;
+ }
+
+ /** used by RtfTableRow to write the <celldef> cell definition control words
+ * @param widthOffset sum of the widths of preceeding cells in same row
+ * @return widthOffset + width of this cell
+ */
+ int writeCellDef(int widthOffset) throws IOException {
+ this.widthOffset = widthOffset;
+
+ // vertical cell merge codes
+ if (vMerge == MERGE_START) {
+ writeControlWord("clvmgf");
+ } else if (vMerge == MERGE_WITH_PREVIOUS) {
+ writeControlWord("clvmrg");
+ }
+
+ // horizontal cell merge codes
+ if (hMerge == MERGE_START) {
+ writeControlWord("clmgf");
+ } else if (hMerge == MERGE_WITH_PREVIOUS) {
+ writeControlWord("clmrg");
+ }
+
+ /**
+ * Added by Boris POUDEROUS on 2002/06/26
+ */
+ // Cell background color processing :
+ writeAttributes (attrib, ITableAttributes.CELL_COLOR);
+ /** - end - */
+
+ writeAttributes (attrib, ITableAttributes.ATTRIB_CELL_PADDING);
+ writeAttributes (attrib, ITableAttributes.CELL_BORDER);
+ writeAttributes (attrib, BorderAttributesConverter.BORDERS);
+
+ // cell width
+ final int xPos = widthOffset + this.cellWidth;
+
+ //these lines added by Chris Scott, Westinghouse
+ //some attributes need to be writting before opening block
+ if (setCenter) {
+ writeControlWord("qc");
+ } else if (setRight) {
+ writeControlWord("qr");
+ } else {
+ writeControlWord("ql");
+ }
+
+ writeControlWord("cellx" + xPos);
+
+ writeControlWord("ql");
+
+ return xPos;
+
+ }
+
+ /**
+ * The "cell" control word marks the end of a cell
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfSuffix() throws IOException {
+ // word97 hangs if cell does not contain at least one "par" control word
+ // TODO this is what causes the extra spaces in nested table of test
+ // 004-spacing-in-tables.fo,
+ // but if is not here we generate invalid RTF for word97
+
+ if (setCenter) {
+ writeControlWord("qc");
+ } else if (setRight) {
+ writeControlWord("qr");
+ } else {
+ writeControlWord("ql");
+ }
+
+
+
+ if (!containsText()) {
+ writeControlWord("intbl");
+
+ //R.Marra this create useless paragraph
+ //Seem working into Word97 with the "intbl" only
+// writeControlWord("par");
+ }
+
+ writeControlWord("cell");
+ }
+
+
+ //modified by Chris Scott, Westinghouse
+ private void closeCurrentParagraph() throws IOException {
+ if (paragraph != null) {
+ paragraph.close();
+ }
+ }
+
+ private void closeCurrentList() throws IOException {
+ if (list != null) {
+ list.close();
+ }
+ }
+
+ private void closeCurrentTable() throws IOException {
+ if (table != null) {
+ table.close();
+ }
+ }
+
+ private void closeCurrentExternalGraphic() throws IOException {
+ if (externalGraphic != null) {
+ externalGraphic.close();
+ }
+ }
+
+ private void closeAll()
+ throws IOException {
+ closeCurrentTable();
+ closeCurrentParagraph();
+ closeCurrentList();
+ closeCurrentExternalGraphic();
+ }
+
+ /**
+ * @param mergeStatus vertical cell merging status to set
+ */
+ public void setVMerge(int mergeStatus) { this.vMerge = mergeStatus; }
+
+ /**
+ * @return vertical cell merging status
+ */
+ public int getVMerge() { return this.vMerge; }
+
+ /**
+ * Set horizontal cell merging status
+ * @param mergeStatus mergeStatus to set
+ */
+ public void setHMerge(int mergeStatus) {
+ this.hMerge = mergeStatus;
+ }
+
+ /**
+ * @return horizontal cell merging status
+ */
+ public int getHMerge() {
+ return this.hMerge;
+ }
+
+ /** get cell width */
+ int getCellWidth() { return this.cellWidth; }
+
+ /**
+ * Overridden so that nested tables cause extra rows to be added after the row
+ * that contains this cell
+ * disabled for V0.3 - nested table support is not done yet
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfContent()
+ throws IOException {
+ int extraRowIndex = 0;
+ RtfTableCell extraCell = null;
+
+ for (Iterator it = getChildren().iterator(); it.hasNext();) {
+ final RtfElement e = (RtfElement)it.next();
+ if (e instanceof RtfTable) {
+ // nested table - render its cells in supplementary rows after current row,
+ // and put the remaining content of this cell in a new cell after nested table
+ // Line added by Boris Poudérous
+ parentRow.getExtraRowSet().setParentITableColumnsInfo(
+ ((RtfTable)this.getParentOfClass(e.getClass())).getITableColumnsInfo());
+ extraRowIndex = parentRow.getExtraRowSet().addTable((RtfTable)e,
+ extraRowIndex, widthOffset);
+ // Boris Poudérous added the passing of the current cell
+ // attributes to the new cells (in order not to have cell without
+ // border for example)
+ extraCell = parentRow.getExtraRowSet().createExtraCell(extraRowIndex,
+ widthOffset, this.getCellWidth(), attrib);
+ extraRowIndex++;
+
+ } else if (extraCell != null) {
+ // we are after a nested table, add elements to the extra cell created for them
+ extraCell.addChild(e);
+
+ } else {
+ // before a nested table, normal rendering
+ e.writeRtf();
+ }
+ }
+ }
+
+ /**
+ * A table cell always contains "useful" content, as it is here to take some
+ * space in a row.
+ * Use containsText() to find out if there is really some useful content in the cell.
+ * TODO: containsText could use the original isEmpty implementation?
+ * @return false (always)
+ */
+ public boolean isEmpty() {
+ return false;
+ }
+
+ /** true if the "par" control word must be written for given RtfParagraph
+ * (which is not the case for the last non-empty paragraph of the cell)
+ */
+ boolean paragraphNeedsPar(RtfParagraph p) {
+ // true if there is at least one non-empty paragraph after p in our children
+ boolean pFound = false;
+ boolean result = false;
+ for (Iterator it = getChildren().iterator(); it.hasNext();) {
+ final Object o = it.next();
+ if (!pFound) {
+ // set pFound when p is found in the list
+ pFound = (o == p);
+ } else {
+ if (o instanceof RtfParagraph) {
+ final RtfParagraph p2 = (RtfParagraph)o;
+ if (!p2.isEmpty()) {
+ // found a non-empty paragraph after p
+ result = true;
+ break;
+ }
+ } else if (o instanceof RtfTable) {
+ break;
+ }
+ }
+ }
+ return result;
+ }
+
+ public RtfTextrun getTextrun()
+ throws IOException {
+ RtfAttributes attrs = new RtfAttributes();
+ attrs.set("intbl");
+
+ return RtfTextrun.getTextrun(this, writer, attrs);
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java
new file mode 100644
index 000000000..5be8d50f0
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java
@@ -0,0 +1,388 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Iterator;
+
+/** Container for RtfTableCell elements
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ * @author Andreas Putz a.putz@skynamics.com
+ * @author Roberto Marra roberto@link-u.com
+ */
+
+public class RtfTableRow extends RtfContainer implements ITableAttributes {
+ private RtfTableCell cell;
+ private RtfExtraRowSet extraRowSet;
+ private int id;
+ private int highestCell = 0;
+
+
+ /** Create an RTF element as a child of given container */
+ RtfTableRow(RtfTable parent, Writer w, int idNum) throws IOException {
+ super(parent, w);
+ id = idNum;
+ }
+
+ /** Create an RTF element as a child of given container */
+ RtfTableRow(RtfTable parent, Writer w, RtfAttributes attrs, int idNum) throws IOException {
+ super(parent, w, attrs);
+ id = idNum;
+ }
+
+ /**
+ * Close current cell if any and start a new one
+ * @param cellWidth width of new cell
+ * @return new RtfTableCell
+ * @throws IOException for I/O problems
+ */
+ public RtfTableCell newTableCell(int cellWidth) throws IOException {
+ highestCell++;
+ cell = new RtfTableCell(this, writer, cellWidth, highestCell);
+ return cell;
+ }
+
+ /**
+ * Close current cell if any and start a new one
+ * @param attrs attributes of new cell
+ * @param cellWidth width of new cell
+ * @return new RtfTableCell
+ * @throws IOException for I/O problems
+ */
+ public RtfTableCell newTableCell(int cellWidth, RtfAttributes attrs) throws IOException {
+ highestCell++;
+ cell = new RtfTableCell(this, writer, cellWidth, attrs, highestCell);
+ return cell;
+ }
+
+ /**
+ * Added by Boris POUDEROUS on 07/02/2002
+ * in order to add an empty cell that is merged with the cell above.
+ * This cell is placed before or after the nested table.
+ * @param attrs attributes of new cell
+ * @param cellWidth width of new cell
+ * @return new RtfTableCell
+ * @throws IOException for I/O problems
+ */
+ public RtfTableCell newTableCellMergedVertically(int cellWidth,
+ RtfAttributes attrs) throws IOException {
+ highestCell++;
+ cell = new RtfTableCell (this, writer, cellWidth, attrs, highestCell);
+ cell.setVMerge(RtfTableCell.MERGE_WITH_PREVIOUS);
+ return cell;
+ }
+
+ /**
+ * Added by Boris POUDEROUS on 07/02/2002
+ * in order to add an empty cell that is merged with the previous cell.
+ * @param attrs attributes of new cell
+ * @param cellWidth width of new cell
+ * @return new RtfTableCell
+ * @throws IOException for I/O problems
+ */
+ public RtfTableCell newTableCellMergedHorizontally (int cellWidth,
+ RtfAttributes attrs) throws IOException {
+ highestCell++;
+ // Added by Normand Masse
+ // Inherit attributes from base cell for merge
+ RtfAttributes wAttributes = (RtfAttributes)attrs.clone();
+ wAttributes.unset("number-columns-spanned");
+
+ cell = new RtfTableCell(this, writer, cellWidth, wAttributes, highestCell);
+ cell.setHMerge(RtfTableCell.MERGE_WITH_PREVIOUS);
+ return cell;
+ }
+
+ /**
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfPrefix() throws IOException {
+ writeGroupMark(true);
+ }
+
+ /**
+ * Overridden to write trowd and cell definitions before writing our cells
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfContent() throws IOException {
+
+ // create new extra row set to allow our cells to put nested tables
+ // in rows that will be rendered after this one
+ extraRowSet = new RtfExtraRowSet(writer);
+
+ // render the row and cells definitions
+ writeControlWord("trowd");
+
+ //check for keep-together
+ if (attrib != null && attrib.isSet(ITableAttributes.ROW_KEEP_TOGETHER)) {
+ writeControlWord(ROW_KEEP_TOGETHER);
+ }
+
+ writePaddingAttributes();
+
+ final RtfTable parentTable = (RtfTable) parent;
+ adjustBorderProperties(parentTable);
+
+ writeAttributes(attrib, ITableAttributes.ROW_BORDER);
+ writeAttributes(attrib, ITableAttributes.CELL_BORDER);
+ writeAttributes(attrib, BorderAttributesConverter.BORDERS);
+
+ /**
+ * Added by Boris POUDEROUS on 07/02/2002
+ * in order to get the indexes of the cells preceding a cell that
+ * contains a nested table.
+ * Thus, the cells of the extra row will be merged with the cells above.
+ */
+ boolean nestedTableFound = false;
+ int index = 0; // Used to store the index of the cell that contains a nested table
+ int numberOfCellsBeforeNestedTable = 0;
+
+ java.util.Vector indexesFound = new java.util.Vector();
+ for (Iterator it = getChildren().iterator(); it.hasNext();) {
+ final RtfElement e = (RtfElement)it.next();
+
+ if (e instanceof RtfTableCell) {
+ if (!nestedTableFound) {
+ ++numberOfCellsBeforeNestedTable;
+ }
+ for (Iterator it2 = ((RtfTableCell)e).getChildren().iterator(); it2.hasNext();) {
+ final RtfElement subElement = (RtfElement)it2.next();
+ if (subElement instanceof RtfTable) {
+ nestedTableFound = true;
+ indexesFound.addElement(new Integer(index));
+ } else if (subElement instanceof RtfParagraph) {
+ for (Iterator it3 =
+ ((RtfParagraph)subElement).getChildren().iterator(); it3.hasNext();)
+ {
+ final RtfElement subSubElement = (RtfElement)it3.next();
+ if (subSubElement instanceof RtfTable) {
+ nestedTableFound = true;
+ indexesFound.addElement(new Integer(index));
+ }
+ }
+ }
+ }
+ }
+
+ index++;
+ }
+ /** - end - */
+
+ // write X positions of our cells
+ int xPos = 0;
+ index = 0; // Line added by Boris POUDEROUS on 07/02/2002
+ for (Iterator it = getChildren().iterator(); it.hasNext();) {
+ final RtfElement e = (RtfElement)it.next();
+ if (e instanceof RtfTableCell) {
+ /**
+ * Added by Boris POUDEROUS on 2002/07/02
+ */
+ // If one of the row's child cells contains a nested table :
+ if (!indexesFound.isEmpty()) {
+ for (int i = 0; i < indexesFound.size(); i++) {
+ // If the current cell index is equals to the index of the cell that
+ // contains a nested table => NO MERGE
+ if (index == ((Integer)indexesFound.get(i)).intValue()) {
+ break;
+
+ // If the current cell index is lower than the index of the cell that
+ // contains a nested table => START VERTICAL MERGE
+ } else if (index < ((Integer)indexesFound.get(i)).intValue()) {
+ ((RtfTableCell)e).setVMerge(RtfTableCell.MERGE_START);
+ break;
+
+ // If the current cell index is greater than the index of the cell that
+ // contains a nested table => START VERTICAL MERGE
+ } else if (index > ((Integer)indexesFound.get(i)).intValue()) {
+ ((RtfTableCell)e).setVMerge(RtfTableCell.MERGE_START);
+ break;
+ }
+ }
+ }
+ /** - end - */
+
+ // Added by Normand Masse
+ // Adjust the cell's display attributes so the table's/row's borders
+ // are drawn properly.
+ RtfTableCell cell = (RtfTableCell)e;
+ if (index == 0) {
+ if (!cell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_LEFT)) {
+ cell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_LEFT,
+ (String)attrib.getValue(ITableAttributes.ROW_BORDER_LEFT));
+ }
+ }
+
+ if (index == this.getChildCount() - 1) {
+ if (!cell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_RIGHT)) {
+ cell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_RIGHT,
+ (String)attrib.getValue(ITableAttributes.ROW_BORDER_RIGHT));
+ }
+ }
+
+ if (isFirstRow()) {
+ if (!cell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_TOP)) {
+ cell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_TOP,
+ (String)attrib.getValue(ITableAttributes.ROW_BORDER_TOP));
+ }
+ }
+
+ if (parentTable.isHighestRow(id)) {
+ if (!cell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_BOTTOM)) {
+ cell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_BOTTOM,
+ (String)attrib.getValue(ITableAttributes.ROW_BORDER_BOTTOM));
+ }
+ }
+
+ xPos = cell.writeCellDef(xPos);
+ }
+ index++; // Added by Boris POUDEROUS on 2002/07/02
+ }
+
+ // now children can write themselves, we have the correct RTF prefix code
+ super.writeRtfContent();
+ }
+
+ private void adjustBorderProperties(RtfTable parentTable) {
+ // if we have attributes, manipulate border properties
+ if (attrib != null && parentTable != null) {
+
+ //if table is only one row long
+ if (isFirstRow() && parentTable.isHighestRow(id)) {
+ attrib.unset(ITableAttributes.ROW_BORDER_HORIZONTAL);
+ //or if row is the first row
+ } else if (isFirstRow()) {
+ attrib.unset(ITableAttributes.ROW_BORDER_BOTTOM);
+ //or if row is the last row
+ } else if (parentTable.isHighestRow(id)) {
+ attrib.unset(ITableAttributes.ROW_BORDER_TOP);
+ //else the row is an inside row
+ } else {
+ attrib.unset(ITableAttributes.ROW_BORDER_BOTTOM);
+ attrib.unset(ITableAttributes.ROW_BORDER_TOP);
+ }
+ }
+ }
+
+ /**
+ * Overridden to write RTF suffix code, what comes after our children
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfSuffix() throws IOException {
+ writeControlWord("row");
+
+ // write extra rows if any
+ extraRowSet.writeRtf();
+ writeGroupMark(false);
+ }
+
+ RtfExtraRowSet getExtraRowSet() {
+ return extraRowSet;
+ }
+
+ private void writePaddingAttributes()
+ throws IOException {
+ // Row padding attributes generated in the converter package
+ // use RTF 1.6 definitions - try to compute a reasonable RTF 1.5 value
+ // out of them if present
+ // how to do vertical padding with RTF 1.5?
+ if (attrib != null && !attrib.isSet(ATTR_RTF_15_TRGAPH)) {
+ int gaph = -1;
+ try {
+ // set (RTF 1.5) gaph to the average of the (RTF 1.6) left and right padding values
+ final Integer leftPadStr = (Integer)attrib.getValue(ATTR_ROW_PADDING_LEFT);
+ if (leftPadStr != null) {
+ gaph = leftPadStr.intValue();
+ }
+ final Integer rightPadStr = (Integer)attrib.getValue(ATTR_ROW_PADDING_RIGHT);
+ if (rightPadStr != null) {
+ gaph = (gaph + rightPadStr.intValue()) / 2;
+ }
+ } catch (Exception e) {
+ final String msg = "RtfTableRow.writePaddingAttributes: " + e.toString();
+// getRtfFile().getLog().logWarning(msg);
+ }
+ if (gaph >= 0) {
+ attrib.set(ATTR_RTF_15_TRGAPH, gaph);
+ }
+ }
+
+ // write all padding attributes
+ writeAttributes(attrib, ATTRIB_ROW_PADDING);
+ }
+
+ /**
+ * @return true if the row is the first in the table
+ */
+ public boolean isFirstRow() {
+ if (id == 1) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * @param id cell id to check
+ * @return true if the cell is the highest cell
+ */
+ public boolean isHighestCell(int id) {
+ return (highestCell == id) ? true : false;
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTemplate.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTemplate.java
new file mode 100644
index 000000000..811cbe12c
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTemplate.java
@@ -0,0 +1,132 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+
+/**
+ * Singelton of the RTF style template
+ * This class belongs to the <jfor:style-template> tag processing.
+ */
+
+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
+ * @throws IOException for I/O problems
+ **/
+ 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/render/rtf/rtflib/rtfdoc/RtfText.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfText.java
new file mode 100644
index 000000000..484024374
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfText.java
@@ -0,0 +1,350 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/** Model of a text run (a piece of text with attributes) in an RTF document
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+public class RtfText extends RtfElement {
+ // char code for non-breakable space
+ private static final int CHAR_NBSP = 160;
+ private static final int CHAR_TAB = 137;
+ private static final int CHAR_NEW_LINE = 141;
+ /* these next two variables are used to encode bold formating in the
+ * raw xml text. Usefull when specific words or phrases are to be bolded
+ * but their placement and length change. Thus the bold formatting becomes
+ * part of the data. The same method can be used for implementing other types
+ * of raw text formatting.
+ */
+ private static final int CHAR_BOLD_START = 130;
+ private static final int CHAR_BOLD_END = 131;
+
+ /** members */
+ private String text;
+ private final RtfAttributes attr;
+
+
+ /** RtfText attributes: attribute names are RTF control word names to avoid
+ * additional mapping */
+ /** constant for bold */
+ public static final String ATTR_BOLD = "b";
+ /** constant for italic */
+ public static final String ATTR_ITALIC = "i";
+ /** constant for underline */
+ public static final String ATTR_UNDERLINE = "ul";
+ /** constant for font size */
+ public static final String ATTR_FONT_SIZE = "fs";
+ /** constant for font family */
+ public static final String ATTR_FONT_FAMILY = "f";
+ /** constant for font color */
+ public static final String ATTR_FONT_COLOR = "cf";
+ /** constant for background color */
+ public static final String ATTR_BACKGROUND_COLOR = "chcbpat"; // Added by Boris on 06/25//02
+
+ /** RtfText attributes: alignment attributes */
+ /** constant for align center */
+ public static final String ALIGN_CENTER = "qc";
+ /** constant for align left */
+ public static final String ALIGN_LEFT = "ql";
+ /** constant for align right */
+ public static final String ALIGN_RIGHT = "qr";
+ /** constant for align justified */
+ public static final String ALIGN_JUSTIFIED = "qj";
+ /** constant for align distributed */
+ public static final String ALIGN_DISTRIBUTED = "qd";
+
+ /** RtfText attributes: border attributes */
+ //added by Chris Scott
+ /** constant for bottom single border */
+ public static final String BDR_BOTTOM_SINGLE = "brdrb\\brsp40\\brdrs";
+ /** constant for bottom double border */
+ public static final String BDR_BOTTOM_DOUBLE = "brdrb\\brsp40\\brdrdb";
+ /** constant for bottom embossed border */
+ public static final String BDR_BOTTOM_EMBOSS = "brdrb\\brsp40\\brdremboss";
+ /** constant for bottom dotted border */
+ public static final String BDR_BOTTOM_DOTTED = "brdrb\\brsp40\\brdrdot";
+ /** constant for bottom dashed border */
+ public static final 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}}"
+ /** constant for field */
+ public static final String RTF_FIELD = "field";
+ /** constant for field page */
+ public static final String RTF_FIELD_PAGE = "fldinst { PAGE }";
+ /** constant for field result */
+ public static final String RTF_FIELD_RESULT = "fldrslt";
+
+ /**RtfText attributes: indentation attributes */
+ //added by Chris Scott
+ /** constant for left indent body */
+ public static final String LEFT_INDENT_BODY = "li";
+ /** constant for left indent first */
+ public static final String LEFT_INDENT_FIRST = "fi-";
+ /** constant for right indent body */
+ public static final String RIGHT_INDENT_BODY = "ri";
+
+ /** constant for center tab */
+ public static final String TAB_CENTER = "tqc\\tx";
+ /** constant for right tab */
+ public static final String TAB_RIGHT = "tqr\\tx";
+ /** constant for tab leader dots */
+ public static final String TAB_LEADER_DOTS = "tldot";
+ /** constant for tab leader hyphens */
+ public static final String TAB_LEADER_HYPHEN = "tlhyph";
+ /** constant for tab leader underscores */
+ public static final String TAB_LEADER_UNDER = "tlul";
+ /** constant for tab leader thick */
+ public static final String TAB_LEADER_THICK = "tlth";
+ /** constant for tab leader equals */
+ public static final String TAB_LEADER_EQUALS = "tleq";
+
+ /** Space before/after a paragraph */
+ //these lines were added by Boris Pouderous
+ public static final String SPACE_BEFORE = "sb";
+ /** Space after a paragraph */
+ public static final String SPACE_AFTER = "sa";
+
+ /** RtfText attributes: this must contain all allignment attributes names */
+ public static final 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 final String[] BORDER = new String []
+ {
+ BDR_BOTTOM_SINGLE, BDR_BOTTOM_DOUBLE, BDR_BOTTOM_EMBOSS, BDR_BOTTOM_DOTTED,
+ BDR_BOTTOM_DASH
+ };
+
+ /** String array of indent constants */
+ public static final String[] INDENT = new String []
+ {
+ LEFT_INDENT_BODY, LEFT_INDENT_FIRST
+ };
+
+ /** String array of tab constants */
+ public static final 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);
+ text = str;
+ this.attr = attr;
+ }
+
+ /**
+ * Write our text to the RTF stream
+ * @throws IOException for I/O problems
+ */
+ public void writeRtfContent() throws IOException {
+ writeChars: {
+
+ //these lines were added by Boris Pouderous
+ if (attr != null) {
+ writeAttributes(attr, new String[] {RtfText.SPACE_BEFORE});
+ writeAttributes(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 (attr != null && mustWriteAttributes()) {
+ writeAttributes(attr, RtfText.ATTR_NAMES);
+ }
+ RtfStringConverter.getInstance().writeRtfString(writer, text);
+ writeGroupMark(false);
+ }
+
+ }
+ }
+
+ /** true if our text attributes must be written */
+ private boolean mustWriteAttributes() {
+ return !isEmpty() && !isNbsp();
+ }
+
+ /** IRtfTextContainer requirement:
+ * @return a copy of our attributes */
+ public RtfAttributes getTextContainerAttributes() {
+ if (attrib == null) {
+ return null;
+ }
+ return (RtfAttributes)this.attrib.clone();
+ }
+
+ /** direct access to our text */
+ String getText() {
+ return text;
+ }
+
+ /** direct access to our text */
+ void setText(String str) {
+ 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 text == null || 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 (text.trim ().length () == 1 && text.charAt (0) == CHAR_NBSP) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @return true if the text is a tab character
+ */
+ public boolean isTab() {
+ if (text.trim().length() == 1 && text.charAt(0) == CHAR_TAB) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * @return true if text is a newline character
+ */
+ public boolean isNewLine() {
+ if (text.trim().length() == 1 && text.charAt(0) == CHAR_NEW_LINE) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * @param isStart set to true if processing the start of the text (??)
+ * @return true if text is bold
+ */
+ public boolean isBold(boolean isStart) {
+ if (isStart) {
+ if (text.trim().length() == 1 && text.charAt(0) == CHAR_BOLD_START) {
+ return true;
+ }
+ } else {
+ if (text.trim().length() == 1 && text.charAt(0) == CHAR_BOLD_END) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ return false;
+ }
+
+ /** @return the attributes of our text */
+ public RtfAttributes getTextAttributes() {
+ return attr;
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java
new file mode 100644
index 000000000..32910ca1a
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java
@@ -0,0 +1,286 @@
+/*
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+
+/*
+ * This file is part of the RTF library of the FOP project.
+ */
+
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Iterator;
+import java.io.IOException;
+import org.apache.fop.render.rtf.rtflib.exceptions.RtfStructureException;
+
+/** Class which contains a linear text run. It has methods to add attributes, text, paragraph breaks....
+ * @author Peter Herweg, pherweg@web.de
+ */
+
+public class RtfTextrun extends RtfContainer {
+
+ /** Class which represents the opening of a RTF group mark.*/
+ private class RtfOpenGroupMark extends RtfElement
+ {
+ RtfOpenGroupMark(RtfContainer parent, Writer w, RtfAttributes attr)
+ throws IOException {
+ super(parent, w, attr);
+ }
+
+ /**
+ * @return true if this element would generate no "useful" RTF content
+ */
+ public boolean isEmpty() {
+ return false;
+ }
+
+ /**
+ * write RTF code of all our children
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfContent() throws IOException {
+ writeGroupMark(true);
+ writeAttributes(getRtfAttributes(), null);
+ }
+ }
+
+ /** Class which represents the closing of a RTF group mark.*/
+ private class RtfCloseGroupMark extends RtfElement
+ {
+ RtfCloseGroupMark(RtfContainer parent, Writer w)
+ throws IOException {
+ super(parent, w);
+ }
+
+ /**
+ * @return true if this element would generate no "useful" RTF content
+ */
+ public boolean isEmpty() {
+ return false;
+ }
+
+ /**
+ * write RTF code of all our children
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfContent() throws IOException {
+ writeGroupMark(false);
+ }
+ }
+
+ /** Class which represents a paragraph break.*/
+ private class RtfParagraphBreak extends RtfElement
+ {
+ RtfParagraphBreak(RtfContainer parent, Writer w)
+ throws IOException {
+ super(parent, w);
+ }
+
+ /**
+ * @return true if this element would generate no "useful" RTF content
+ */
+ public boolean isEmpty() {
+ return false;
+ }
+
+ /**
+ * write RTF code of all our children
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfContent() throws IOException {
+ writeControlWord("par");
+ }
+ }
+
+ /** Create an RTF container as a child of given container */
+ RtfTextrun(RtfContainer parent, Writer w, RtfAttributes attrs) throws IOException {
+ super(parent, w, attrs);
+ }
+
+ public void pushAttributes(RtfAttributes attrs) throws IOException {
+ RtfOpenGroupMark r=new RtfOpenGroupMark(this, writer, attrs);
+ }
+
+ public void popAttributes() throws IOException {
+ RtfCloseGroupMark r=new RtfCloseGroupMark(this, writer);
+ }
+
+ public void addString(String s) throws IOException {
+ RtfString r=new RtfString(this, writer, s);
+ }
+
+ public void addParagraphBreak() throws IOException {
+ RtfParagraphBreak r=new RtfParagraphBreak(this, writer);
+ }
+
+ public void addPageNumber(RtfAttributes attr) throws IOException {
+ RtfPageNumber r=new RtfPageNumber(this, writer, attr);
+ }
+
+ /**
+ * Adds a new RtfTextrun to the given container if necessary, and returns it.
+ * @param container RtfContainer, which is the parent of the returned RtfTextrun
+ * @param writer Writer of the given RtfContainer
+ * @param attrs RtfAttributes which are to write at the beginning of the RtfTextrun
+ * @throws IOException for I/O problems
+ */
+ public static RtfTextrun getTextrun(RtfContainer container, Writer writer, RtfAttributes attrs)
+ throws IOException {
+ Object obj;
+ List list=container.getChildren();
+
+ if(list.size()==0) {
+ //add a new RtfTextrun
+ RtfTextrun textrun=new RtfTextrun(container, writer, attrs);
+ list.add(textrun);
+
+ return textrun;
+ } else if ((obj=list.get(list.size()-1)) instanceof RtfTextrun ) {
+ //if the last child is a RtfTextrun, return it
+ return (RtfTextrun)obj;
+ }
+
+ //add a new RtfTextrun as the last child
+ RtfTextrun textrun=new RtfTextrun(container, writer, attrs);
+ list.add(textrun);
+
+ return textrun;
+ }
+
+ /**
+ * write RTF code of all our children
+ * @throws IOException for I/O problems
+ */
+ protected void writeRtfContent() throws IOException {
+ /**
+ *TODO: The textrun's children are iterated threetimes:
+ * 1. In WhitespaceCollapser
+ * 2. To determine the last RtfParagraphBreak
+ * 3. To write the children
+ * Maybe this can be done more efficient.
+ */
+
+ if (attrib != null && attrib.isSet("WhiteSpaceFalse")) {
+ attrib.unset("WhiteSpaceFalse");
+ } else {
+ new WhitespaceCollapser(this);
+ }
+
+ //determine, if this RtfTextrun is the last child of its parent
+ boolean bLast=false;
+ for (Iterator it = parent.getChildren().iterator(); it.hasNext();) {
+ if(it.next() == this) {
+ bLast=!it.hasNext();
+ break;
+ }
+ }
+
+ //get last RtfParagraphBreak, which is not followed by any visible child
+ RtfParagraphBreak lastParagraphBreak=null;
+ if(bLast) {
+ for (Iterator it = getChildren().iterator(); it.hasNext();) {
+ final RtfElement e = (RtfElement)it.next();
+ if(e instanceof RtfParagraphBreak) {
+ lastParagraphBreak=(RtfParagraphBreak)e;
+ } else {
+ if(!(e instanceof RtfOpenGroupMark)
+ && !(e instanceof RtfCloseGroupMark)
+ && e.isEmpty()) {
+ lastParagraphBreak=null;
+ }
+ }
+ }
+ }
+
+ //may contain for example \intbl
+ writeAttributes(attrib, null);
+
+ //write all children
+ boolean bPrevPar = false;
+ boolean bFirst = true;
+ for (Iterator it = getChildren().iterator(); it.hasNext();) {
+ final RtfElement e = (RtfElement)it.next();
+ final boolean bRtfParagraphBreak = (e instanceof RtfParagraphBreak);
+
+ /**
+ * -Write RtfParagraphBreak only, if the previous visible child
+ * was't also a RtfParagraphBreak.
+ * -Write RtfParagraphBreak only, if it is not the first visible
+ * child.
+ * -If the RtfTextrun is the last child of its parent, write a
+ * RtfParagraphBreak only, if it is not the last child.
+ */
+ boolean bHide=false;
+ bHide=bRtfParagraphBreak;
+ bHide=bHide &&
+ (bPrevPar || bFirst || (bLast && lastParagraphBreak!=null && e==lastParagraphBreak) );
+
+ if( !bHide) {
+ e.writeRtf();
+ }
+
+ if(e instanceof RtfParagraphBreak) {
+ bPrevPar=true;
+ } else if(e instanceof RtfCloseGroupMark) {
+ //do nothing
+ } else if(e instanceof RtfOpenGroupMark) {
+ //do nothing
+ } else {
+ bPrevPar=bPrevPar && e.isEmpty();
+ bFirst=bFirst && e.isEmpty();
+ }
+ }
+ }
+}
+
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/WhitespaceCollapser.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/WhitespaceCollapser.java
new file mode 100644
index 000000000..98f1bed80
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/WhitespaceCollapser.java
@@ -0,0 +1,150 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+import java.util.Iterator;
+import java.util.StringTokenizer;
+
+/** Collapses whitespace of an RtfContainer that contains RtfText elements
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+class WhitespaceCollapser {
+ private static final String SPACE = " ";
+ private boolean lastEndSpace = true;
+
+ /** remove extra whitespace in RtfText elements that are inside c */
+ WhitespaceCollapser(RtfContainer c) {
+ // process all texts
+ for (Iterator it = c.getChildren().iterator(); it.hasNext();) {
+ final Object kid = it.next();
+ if (kid instanceof RtfText) {
+ RtfText current = (RtfText)kid;
+ processText(current);
+ } else if (kid instanceof RtfString) {
+ RtfString current = (RtfString)kid;
+ processString(current);
+ } else {
+ // if there is something between two texts, it counts for a space
+ lastEndSpace = true;
+ }
+ }
+ }
+
+ /** process one RtfText from our container */
+ private void processText(RtfText txt) {
+ final String newString=processString(txt.getText());
+ if(newString!=null) {
+ txt.setText(newString);
+ }
+ }
+
+ /** process one RtfString from our container */
+ private void processString(RtfString txt) {
+ final String newString=processString(txt.getText());
+ if(newString!=null) {
+ txt.setText(newString);
+ }
+ }
+
+ /** process one String */
+ private String processString(String txt) {
+ final String orig = txt;
+
+ // tokenize the text based on whitespace and regenerate it so as
+ // to collapse multiple spaces into one
+ if(orig==null) {
+ return null;
+ } else if (orig.length() > 0) {
+ final boolean allSpaces = orig.trim().length() == 0;
+ final boolean endSpace = allSpaces
+ || Character.isWhitespace(orig.charAt(orig.length() - 1));
+ final boolean beginSpace = Character.isWhitespace(orig.charAt(0));
+ final StringBuffer sb = new StringBuffer(orig.length());
+
+ // if text contains spaces only, keep at most one
+ if (allSpaces) {
+ if (!lastEndSpace) {
+ sb.append(SPACE);
+ }
+ } else {
+ // TODO to be compatible with different Locales, should use Character.isWhitespace
+ // instead of this limited list
+ boolean first = true;
+ final StringTokenizer stk = new StringTokenizer(txt, " \t\n\r");
+ while (stk.hasMoreTokens()) {
+ if (first && beginSpace && !lastEndSpace) {
+ sb.append(SPACE);
+ }
+ first = false;
+
+ sb.append(stk.nextToken());
+ if (stk.hasMoreTokens() || endSpace) {
+ sb.append(SPACE);
+ }
+ }
+ }
+
+ lastEndSpace = endSpace;
+ return sb.toString();
+ } else {
+ return "";
+ }
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/package.html b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/package.html
new file mode 100644
index 000000000..1d8c8db97
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/package.html
@@ -0,0 +1,7 @@
+<HTML>
+<TITLE>org.apache.fop.render.rtf.rtflib.rtfdoc</TITLE>
+<BODY>
+<P>Independent subsystem (not specific to FOP) classes that are used to build
+RTF documents.</P>
+</BODY>
+</HTML> \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/testdocs/BasicLink.java b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/BasicLink.java
new file mode 100644
index 000000000..cada79a40
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/BasicLink.java
@@ -0,0 +1,117 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.testdocs;
+
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfParagraph;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfHyperLink;
+
+import java.io.IOException;
+
+/**
+ * Class <code>BasicLink</code> here.
+ *
+ * @author <a href="mailto:mks@ANDREAS">Andreas Putz</a>
+ */
+
+public class BasicLink extends TestDocument {
+ //////////////////////////////////////////////////
+ // @@ Construction
+ //////////////////////////////////////////////////
+
+ /**
+ * Default constructor.
+ */
+ public BasicLink() {
+ }
+
+ /** generate the body of the test document
+ * @param rda RtfDocumentArea
+ * @param sect RtfSection
+ * @throws IOException for I/O Errors
+ */
+ 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.newLineBreak();
+ p.newLineBreak();
+ p.newPageBreak();
+ p.newBookmark("testBookmark");
+ p.newText("testBookmark");
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/testdocs/CreateTestDocuments.java b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/CreateTestDocuments.java
new file mode 100644
index 000000000..c98ce3f51
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/CreateTestDocuments.java
@@ -0,0 +1,136 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.testdocs;
+
+import java.io.File;
+import java.io.IOException;
+//import org.apache.fop.render.rtf.rtflib.jfor.main.JForVersionInfo;
+
+/** Create test RTF documents from classes found in this package.
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ * @author Andreas Putz a.putz@skynamics.com
+ */
+
+public class CreateTestDocuments {
+
+ /**
+ * package name for the testdocs
+ */
+ public static final String TESTDOCS_PACKAGE = "org.apache.fop.rtf.rtflib.testdocs";
+
+ /** List of all TestDocument subclasses from this package */
+ private static final String [] CLASS_NAMES = {
+ "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");
+ }
+
+ for (int i = 0; i < CLASS_NAMES.length; i++) {
+ createOneTestDocument(CLASS_NAMES[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();
+ }
+
+ /** execute this to create test documents from all classes listed in classNames array
+ * @param args String array of arguments
+ * @throws Exception for errors
+ */
+ public static void main(String args[])
+ throws Exception {
+ if (args.length < 1) {
+ System.err.println("usage: CreateTestDocuments <output directory>");
+ 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);
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/testdocs/DummyTableColumnsInfo.java b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/DummyTableColumnsInfo.java
new file mode 100644
index 000000000..a48df9d46
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/DummyTableColumnsInfo.java
@@ -0,0 +1,90 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.testdocs;
+
+import org.apache.fop.render.rtf.rtflib.interfaces.ITableColumnsInfo;
+
+/** ITableColumnsInfo that does nothing, used in testodcs package
+ * to create documents without worrying about nested tables handling.
+ * Might need to be replaced by more complete version in some sample
+ * documents created by this package.
+ *
+ * @author bdelacretaz@codeconsult.ch
+ */
+
+class DummyTableColumnsInfo implements ITableColumnsInfo {
+
+ public float getColumnWidth() {
+ return INVALID_COLUM_WIDTH;
+ }
+
+ public void selectFirstColumn() {
+ }
+
+ public int getNumberOfColumns() {
+ return 0;
+ }
+
+ public int getColumnIndex() {
+ return 0;
+ }
+
+ public void selectNextColumn() {
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/testdocs/ExternalGraphic.java b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/ExternalGraphic.java
new file mode 100644
index 000000000..66bbc9bad
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/ExternalGraphic.java
@@ -0,0 +1,148 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.testdocs;
+
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfExternalGraphic;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfParagraph;
+
+import java.io.IOException;
+/**
+ * Generate a test document containing external graphics.
+ *
+ * @author <a href="mailto:a.putz@skynamics.com">Andreas Putz</a>
+ */
+class ExternalGraphic extends TestDocument {
+ private String file = "file:///tmp/jfor-images/logo.";
+
+ //////////////////////////////////////////////////
+ // @@ Construction
+ //////////////////////////////////////////////////
+
+ /**
+ * 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();
+
+ 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 ("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();
+
+ }
+
+
+
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/testdocs/ListInTable.java b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/ListInTable.java
new file mode 100644
index 000000000..6f7ea1848
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/ListInTable.java
@@ -0,0 +1,110 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.testdocs;
+
+import java.io.IOException;
+
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfList;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTable;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableRow;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableCell;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfListItem;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfParagraph;
+
+/** Generates a simple RTF test document for the jfor rtflib package.
+ */
+
+class ListInTable extends TestDocument {
+ /** generate the body of the test document */
+ protected void generateDocument(RtfDocumentArea rda, RtfSection sect)
+ throws IOException {
+ sect.newParagraph().newText("There must be a table below where the "
+ + "second cell contains a bulleted list mixed with normal paragraphs");
+
+ final RtfTable tbl = sect.newTable(new DummyTableColumnsInfo());
+ final RtfTableRow row = tbl.newTableRow();
+ row.newTableCell(RtfTableCell.DEFAULT_CELL_WIDTH).newParagraph().newText("cell A, simple");
+
+ final RtfTableCell c = row.newTableCell(RtfTableCell.DEFAULT_CELL_WIDTH);
+ c.newParagraph().newText("cell B, contains this paragraph followed by "
+ + "a list and another paragraph");
+ fillList(c.newList(null), 1, 3);
+ c.newParagraph().newText("Normal paragraph, follows the list.");
+
+ row.newTableCell(RtfTableCell.DEFAULT_CELL_WIDTH).newParagraph().newText("cell C, simple");
+ }
+
+ private void fillList(RtfList list, int listIndex, int nItems)
+ throws IOException {
+ for (int i = 0; i < nItems; i++) {
+ final RtfListItem item = list.newListItem();
+ for (int j = 0; j <= i; j++) {
+ final RtfParagraph para = item.newParagraph();
+ para.newText("List " + listIndex + ", item " + i + ", paragraph " + j);
+ if (i == 0 && j == 0) {
+ final String txt = "This item takes more than one line to check word-wrapping.";
+ para.newText(". " + "This list must have " + nItems
+ + " items. " + txt + " " + txt + " " + txt);
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/testdocs/MergedTableCells.java b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/MergedTableCells.java
new file mode 100644
index 000000000..8590acc23
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/MergedTableCells.java
@@ -0,0 +1,149 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.testdocs;
+
+import java.io.IOException;
+
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTable;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableRow;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableCell;
+
+/** Generates an RTF test document containing merged table cells
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+class MergedTableCells extends TestDocument {
+ static final int MM_TO_TWIPS = (int)(1440f / 25.4f);
+
+ /** generate the body of the test document */
+ protected void generateDocument(RtfDocumentArea rda, RtfSection sect)
+ throws IOException {
+ sect.newParagraph().newText("This document contains a table with some merged cells.");
+
+ final RtfTable tbl = sect.newTable(new DummyTableColumnsInfo());
+
+ // first row, test horizontal merging
+ {
+ RtfTableRow r = tbl.newTableRow();
+ RtfTableCell c = r.newTableCell(80 * MM_TO_TWIPS);
+ c.setHMerge(c.MERGE_START);
+ c.newParagraph().newText("cell 0,0, width 80mm, merge start, "
+ + "followed by two merged cells totalling 80mm width.");
+
+ c = r.newTableCell(40 * MM_TO_TWIPS);
+ c.setHMerge(c.MERGE_WITH_PREVIOUS);
+ c.newParagraph().newText("THIS IS IN AN HMERGED CELL, MUST NOT APPEAR IN RTF DOCUMENT");
+
+ c = r.newTableCell(40 * MM_TO_TWIPS);
+ c.setHMerge(c.MERGE_WITH_PREVIOUS);
+ c.newParagraph().newText("THIS IS IN AN HMERGED CELL, MUST NOT APPEAR IN RTF DOCUMENT");
+ }
+
+ // second row, start vertical merging in column 1
+ {
+ RtfTableRow r = tbl.newTableRow();
+ RtfTableCell c = r.newTableCell(40 * MM_TO_TWIPS);
+ c.setVMerge(c.MERGE_START);
+ c.newParagraph().newText("cell 1,0, vertical merge start, 40mm, spans three rows.");
+
+ r.newTableCell(80 * MM_TO_TWIPS).newParagraph().newText("cell 1,1, no merge, 80mm");
+
+ c = r.newTableCell(40 * MM_TO_TWIPS);
+ c.setVMerge(c.MERGE_START);
+ c.newParagraph().newText("cell 1,2, vertical merge start, 40mm, spans two rows.");
+ }
+
+ // third row, column 1 merged with previous row
+ {
+ RtfTableRow r = tbl.newTableRow();
+ RtfTableCell c = r.newTableCell(40 * MM_TO_TWIPS);
+ c.setVMerge(c.MERGE_WITH_PREVIOUS);
+ c.newParagraph().newText("cell 2,0, VMERGED CELL, MUST NOT APPEAR IN RTF DOCUMENT");
+
+ r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText("cell 2,1, no merge, 40mm");
+ r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText("cell 2,2, no merge, 40mm");
+
+ c = r.newTableCell(40 * MM_TO_TWIPS);
+ c.setVMerge(c.MERGE_WITH_PREVIOUS);
+ c.newParagraph().newText("cell 2,3, VMERGED CELL, MUST NOT APPEAR IN RTF DOCUMENT");
+ }
+
+ // fourth row, column 1 merged with previous row
+ {
+ RtfTableRow r = tbl.newTableRow();
+ RtfTableCell c = r.newTableCell(40 * MM_TO_TWIPS);
+ c.setVMerge(c.MERGE_WITH_PREVIOUS);
+ c.newParagraph().newText("cell 3,0, VMERGED CELL, MUST NOT APPEAR IN RTF DOCUMENT");
+
+ r.newTableCell(10 * MM_TO_TWIPS).newParagraph().newText("cell 3,1, no merge, 10mm");
+ r.newTableCell(30 * MM_TO_TWIPS).newParagraph().newText("cell 3,2, no merge, 30mm");
+ r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText("cell 3,3, no merge, 40mm");
+ r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText("cell 3,4, no merge, 40mm");
+ }
+
+ // fifth row, just one cell
+ {
+ RtfTableRow r = tbl.newTableRow();
+ r.newTableCell(160 * MM_TO_TWIPS).newParagraph().newText
+ ("cell 4,0, width 160mm, only cell in this row");
+ }
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/testdocs/NestedTable.java b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/NestedTable.java
new file mode 100644
index 000000000..cbe284149
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/NestedTable.java
@@ -0,0 +1,246 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.testdocs;
+
+import java.io.IOException;
+
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTable;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfParagraph;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableRow;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableCell;
+
+/** Generates an RTF document to test nested tables with the jfor rtflib package.
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+class NestedTable extends TestDocument {
+ private static final int MM_TO_TWIPS = (int)(1440f / 25.4f);
+
+ /** generate the body of the test document */
+ protected void generateDocument(RtfDocumentArea rda, RtfSection sect)
+ throws IOException {
+ sect.newParagraph().newText("This document demonstrates pseudo-nested "
+ + "tables created using merged table cells");
+
+ firstTestTable(sect);
+ RtfParagraph p = sect.newParagraph();
+ p.newText("Test continues on next page.");
+ p.newPageBreak();
+ secondTestTable(sect);
+
+ p = sect.newParagraph();
+ p.newText("Test continues on next page.");
+ p.newPageBreak();
+ thirdTestTable(sect);
+
+ sect.newParagraph().newText("End of nested tables test document");
+ }
+
+ private void firstTestTable(RtfSection sect)
+ throws IOException {
+
+ sect.newParagraph().newText("First test: table with one nested table in cell 1,1");
+ final RtfTable tbl = sect.newTable(new DummyTableColumnsInfo());
+ // first row, normal
+ {
+ RtfTableRow r = tbl.newTableRow();
+ RtfTableCell c = r.newTableCell(160 * MM_TO_TWIPS);
+ c.newParagraph().newText("cell 0,0, width 160mm, only cell in this row.");
+ }
+
+ // second row contains nested table
+ {
+ RtfTableRow r = tbl.newTableRow();
+ r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText
+ ("cell 1,0, width 40mm, to the left of nested table.");
+
+ final RtfTableCell c = r.newTableCell(80 * MM_TO_TWIPS);
+ c.newParagraph().newText("cell 1,1, width 80mm, this text is "
+ + "followed by a nested table in the same cell, followed "
+ + "by text that says 'AFTER NESTED TABLE'.");
+ fillNestedTable(c.newTable(new DummyTableColumnsInfo()), 1);
+ c.newParagraph().newText("AFTER NESTED TABLE");
+
+ r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText
+ ("cell 1,2, width 40mm, to the right of nested table.");
+ }
+
+ // third row, normal
+ {
+ RtfTableRow r = tbl.newTableRow();
+ r.newTableCell(80 * MM_TO_TWIPS).newParagraph().newText
+ ("cell 2,0, width 80mm, this row has two cells.");
+ r.newTableCell(80 * MM_TO_TWIPS).newParagraph().newText
+ ("cell 2,1, width 80mm, last cell.");
+ }
+
+ }
+
+ private void secondTestTable(RtfSection sect)
+ throws IOException {
+ sect.newParagraph().newText("Second test: table with two nested tables in cell 1,1");
+ final RtfTable tbl = sect.newTable(new DummyTableColumnsInfo());
+ // first row, normal
+ {
+ RtfTableRow r = tbl.newTableRow();
+ RtfTableCell c = r.newTableCell(160 * MM_TO_TWIPS);
+ c.newParagraph().newText("second test table: cell 0,0, width 160mm, "
+ + "only cell in this row.");
+ }
+
+ // second row contains nested table
+ {
+ RtfTableRow r = tbl.newTableRow();
+ r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText
+ ("cell 1,0, width 40mm, to the left of nested tables.");
+
+ final RtfTableCell c = r.newTableCell(80 * MM_TO_TWIPS);
+ c.newParagraph().newText("cell 1,1, width 80mm, this text is "
+ + "followed by a nested table in the same cell, followed "
+ + "by text that says 'BETWEEN', then another table, then 'AFTER'.");
+ fillNestedTable(c.newTable(new DummyTableColumnsInfo()), 2);
+ c.newParagraph().newText("BETWEEN");
+ fillNestedTable(c.newTable(new DummyTableColumnsInfo()), 3);
+ c.newParagraph().newText("AFTER");
+
+ r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText
+ ("cell 1,2, width 40mm, to the right of nested table.");
+ }
+
+ // third row, normal
+ {
+ RtfTableRow r = tbl.newTableRow();
+ r.newTableCell(80 * MM_TO_TWIPS).newParagraph().newText
+ ("cell 2,0, width 80mm, this row has two cells.");
+ r.newTableCell(80 * MM_TO_TWIPS).newParagraph().newText
+ ("cell 2,1, width 80mm, last cell.");
+ }
+ }
+
+ private void thirdTestTable(RtfSection sect)
+ throws IOException {
+ sect.newParagraph().newText("Third test: table with two nested tables "
+ + "in cell 1,1 and one nested table in cell 0,1");
+ final RtfTable tbl = sect.newTable(new DummyTableColumnsInfo());
+ // first row, normal
+ {
+ RtfTableRow r = tbl.newTableRow();
+ RtfTableCell c = r.newTableCell(80 * MM_TO_TWIPS);
+ c.newParagraph().newText("third test table: cell 0,0, width 40mm, "
+ + "the cell to its right contains a nested table with no other text.");
+ c = r.newTableCell(80 * MM_TO_TWIPS);
+ fillNestedTable(c.newTable(new DummyTableColumnsInfo()), 4);
+ }
+
+ // second row contains nested table
+ {
+ RtfTableRow r = tbl.newTableRow();
+ r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText
+ ("cell 1,0, width 40mm, to the left of nested tables.");
+
+ final RtfTableCell c = r.newTableCell(80 * MM_TO_TWIPS);
+ c.newParagraph().newText("cell 1,1, width 80mm, this text is "
+ + "followed by a nested table in the same cell, followed "
+ + "by text that says 'BETWEEN', then another table, then 'AFTER'.");
+ fillNestedTable(c.newTable(new DummyTableColumnsInfo()), 5);
+ c.newParagraph().newText("BETWEEN");
+ fillNestedTable(c.newTable(new DummyTableColumnsInfo()), 6);
+ c.newParagraph().newText("AFTER");
+
+ r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText
+ ("cell 1,2, width 40mm, to the right of nested table.");
+ }
+
+ // third row, normal
+ {
+ RtfTableRow r = tbl.newTableRow();
+ r.newTableCell(80 * MM_TO_TWIPS).newParagraph().newText
+ ("cell 2,0, width 80mm, this row has two cells.");
+ r.newTableCell(80 * MM_TO_TWIPS).newParagraph().newText
+ ("cell 2,1, width 80mm, last cell.");
+ }
+ }
+
+ /** fill the nested table */
+ private void fillNestedTable(RtfTable tbl, int index)
+ throws IOException {
+ final String id = "TABLE " + index;
+ {
+ RtfTableRow r = tbl.newTableRow();
+ r.newTableCell(80 * MM_TO_TWIPS).newParagraph().newText(
+ id + ":nested cell 0,0. Nested table contains 3 rows with 1,2 and 3 cells respectively"
+ );
+ }
+
+ {
+ RtfTableRow r = tbl.newTableRow();
+ r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText(id + ":nested cell 1,0, 40mm.");
+ r.newTableCell(40 * MM_TO_TWIPS).newParagraph().newText(id + ":nested cell 1,1, 40mm.");
+ }
+
+ {
+ RtfTableRow r = tbl.newTableRow();
+ r.newTableCell(30 * MM_TO_TWIPS).newParagraph().newText(id + ":nested cell 2,0, 30mm.");
+ r.newTableCell(30 * MM_TO_TWIPS).newParagraph().newText(id + ":nested cell 2,1, 30mm.");
+ r.newTableCell(20 * MM_TO_TWIPS).newParagraph().newText(id + ":nested cell 2,2, 20mm.");
+ }
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/testdocs/ParagraphAlignment.java b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/ParagraphAlignment.java
new file mode 100644
index 000000000..a63726ea3
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/ParagraphAlignment.java
@@ -0,0 +1,111 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.testdocs;
+
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfParagraph;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfText;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes;
+
+/** Generates a simple RTF test document for the jfor rtflib package.
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+public class ParagraphAlignment extends TestDocument {
+
+ /**
+ * Constructor
+ */
+ public ParagraphAlignment() {
+ }
+
+ /**
+ * Generate the document.
+ * @param rda RtfDocumentArea
+ * @param sect RtfSection
+ * @throws java.io.IOException for I/O errors
+ */
+ 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_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/render/rtf/rtflib/testdocs/SimpleDocument.java b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/SimpleDocument.java
new file mode 100644
index 000000000..54b8f5a4b
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/SimpleDocument.java
@@ -0,0 +1,85 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.testdocs;
+
+import java.io.IOException;
+
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfParagraph;
+
+/** Generates a simple RTF test document for the jfor rtflib package.
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+class SimpleDocument
+extends TestDocument {
+ /** generate the body of the test document */
+ protected void generateDocument(RtfDocumentArea rda, RtfSection sect)
+ throws IOException {
+ sect.newParagraph().newText("First paragraph of the simple RTF test document.");
+
+ final RtfParagraph para = sect.newParagraph();
+ para.newText("Second paragraph of simple RTF test document.\n");
+ for (int i = 0; i < 242; i++) {
+ para.newText("This is string " + i);
+ para.newLineBreak();
+ }
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/testdocs/SimpleLists.java b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/SimpleLists.java
new file mode 100644
index 000000000..21361ca14
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/SimpleLists.java
@@ -0,0 +1,109 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.testdocs;
+
+import java.io.IOException;
+
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfList;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfListItem;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfParagraph;
+
+/** Generates a simple RTF test document for the jfor rtflib package.
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+class SimpleLists extends TestDocument {
+ /** generate the body of the test document */
+ protected void generateDocument(RtfDocumentArea rda, RtfSection sect)
+ throws IOException {
+ sect.newParagraph().newText("First paragraph of the 'SimpleLists' RTF test document.");
+ sect.newParagraph().newText("First bulleted list with 5 items.");
+ makeList(sect, 1, 5, null);
+ sect.newParagraph().newText("Normal paragraph between lists 1 and 2.");
+ makeList(sect, 2, 3, null);
+ sect.newParagraph().newText("Normal paragraph after list 2.");
+
+ sect.newParagraph().newText("Now a numbered list (4 items):");
+ final RtfList.NumberingStyle nn = new RtfList.NumberingStyle();
+ nn.setIsBulletedList(false);
+ makeList(sect, 3, 4, nn);
+ }
+
+ private void makeList(RtfSection sect, int listIndex, int nItems, RtfList.NumberingStyle ns)
+ throws IOException {
+ final RtfList list = sect.newList(null);
+ if (ns != null) {
+ list.setNumberingStyle(ns);
+ }
+ for (int i = 0; i < nItems; i++) {
+ final RtfListItem item = list.newListItem();
+ for (int j = 0; j <= i; j++) {
+ final RtfParagraph para = item.newParagraph();
+ para.newText("List " + listIndex + ", item " + i + ", paragraph " + j);
+ if (i == 0 && j == 0) {
+ final String txt = "This item takes more than one line to check word-wrapping.";
+ para.newText(". " + "This list should have " + nItems
+ + " items. " + txt + " " + txt + " " + txt);
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/testdocs/SimpleTable.java b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/SimpleTable.java
new file mode 100644
index 000000000..6c44e1780
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/SimpleTable.java
@@ -0,0 +1,104 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.testdocs;
+
+import java.io.IOException;
+
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTable;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableRow;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableCell;
+
+/** Generates a simple RTF test document for the jfor rtflib package.
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+class SimpleTable extends TestDocument {
+ /** generate the body of the test document */
+ static final int MAX_ROW = 2;
+ static final int MAX_COL = 3;
+ static final int INCH_TO_TWIPS = 1440;
+ static final int C1W = 4;
+
+ protected void generateDocument(RtfDocumentArea rda, RtfSection sect)
+ throws IOException {
+ final RtfTable tbl = sect.newTable(new DummyTableColumnsInfo());
+ tbl.newTableRow().newTableCell(C1W * INCH_TO_TWIPS).newParagraph().newText
+ ("Here's a table row with just one cell, width " + C1W + "''");
+
+ for (int row = 0; row < MAX_ROW; row++) {
+ final RtfTableRow r = tbl.newTableRow();
+
+ for (int col = 0; col < MAX_COL; col++) {
+ final float widthInInches = col / 2f + 1f;
+ final int widthInTwips = (int)(widthInInches * INCH_TO_TWIPS);
+ final RtfTableCell c = r.newTableCell(widthInTwips);
+ c.newParagraph().newText("(" + row + "," + col + "), width "
+ + widthInInches + "''");
+ if (row == 0 && col == 1) {
+ for (int i = 0; i < 4; i++) {
+ c.newParagraph().newText("additional paragraph " + i + " of cell 0,1");
+ }
+ }
+ }
+ }
+
+ sect.newParagraph().newText("This paragraph follows the table.");
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/testdocs/TestDocument.java b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/TestDocument.java
new file mode 100644
index 000000000..4dca5c360
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/TestDocument.java
@@ -0,0 +1,121 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.testdocs;
+
+import java.util.Date;
+import java.io.File;
+import java.io.IOException;
+import java.io.FileWriter;
+
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfFile;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfParagraph;
+//import org.apache.fop.render.rtf.rtflib.jfor.main.JForVersionInfo;
+
+/** Base class for generating RTF documents used to test the jfor rtflib package.
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+abstract class TestDocument {
+ private File output;
+
+ final void setOutputDir(File outDir)
+ throws IOException {
+ output = new File(outDir, getRtfFilename());
+ }
+
+ final String getRtfFilename() {
+ // use class name for output filename
+ final String name = getClass().getName();
+ final int pos = name.lastIndexOf('.');
+ return name.substring(pos + 1) + ".rtf";
+ }
+
+ final void generateOutput()
+ throws IOException {
+ debugMsg("Generating document " + output + "...");
+ final RtfFile f = new RtfFile(new FileWriter(output));
+ final RtfDocumentArea rda = f.startDocumentArea();
+ final RtfSection sect = rda.newSection();
+ addIntroComments(sect);
+ generateDocument(rda, sect);
+ f.flush();
+ }
+
+ protected abstract void generateDocument(RtfDocumentArea rda, RtfSection sect)
+ throws IOException;
+
+ void debugMsg(String msg) {
+ System.err.println(msg);
+ }
+
+ protected void addIntroComments(RtfSection sect) throws IOException {
+ final RtfParagraph para = sect.newParagraph();
+
+ para.newText("jfor RTF library test document.");
+ para.newLineBreak();
+// para.newText(JForVersionInfo.getLongVersionInfo());
+ para.newLineBreak();
+ para.newText("generated by class " + getClass().getName());
+ para.newLineBreak();
+ para.newText("generated on " + new Date());
+ para.close();
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/testdocs/TextAttributes.java b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/TextAttributes.java
new file mode 100644
index 000000000..47bb0e33a
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/TextAttributes.java
@@ -0,0 +1,99 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.testdocs;
+
+import java.io.IOException;
+
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfParagraph;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfText;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes;
+
+/** Generates a simple RTF test document for the jfor rtflib package.
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+class TextAttributes extends TestDocument {
+ /** generate the body of the test document */
+ protected void generateDocument(RtfDocumentArea rda, RtfSection sect)
+ throws IOException {
+ final RtfParagraph para = sect.newParagraph();
+ para.newText("This is normal\n");
+ para.newText("This is bold\n", new RtfAttributes().set(RtfText.ATTR_BOLD));
+ para.newText("This is italic\n", new RtfAttributes().set(RtfText.ATTR_ITALIC));
+ para.newText("This is underline\n", new RtfAttributes().set(RtfText.ATTR_UNDERLINE));
+
+ // RTF font sizes are in half-points
+ para.newText("This is size 48\n", new RtfAttributes().set(RtfText.ATTR_FONT_SIZE, 96));
+
+ para.newText(
+ "This is bold and italic\n",
+ new RtfAttributes().set(RtfText.ATTR_BOLD).set(RtfText.ATTR_ITALIC)
+ );
+
+ final RtfAttributes attr = new RtfAttributes();
+ attr.set(RtfText.ATTR_BOLD).set(RtfText.ATTR_ITALIC);
+ attr.set(RtfText.ATTR_UNDERLINE);
+ attr.set(RtfText.ATTR_FONT_SIZE, 72);
+ para.newText("This is bold, italic, underline and size 36\n", attr);
+
+ para.newText("This is back to normal\n");
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/testdocs/Whitespace.java b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/Whitespace.java
new file mode 100644
index 000000000..cc2f80fe4
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/Whitespace.java
@@ -0,0 +1,99 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.testdocs;
+
+import java.io.IOException;
+
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfParagraph;
+
+/** Generates an RTF document to test the WhitespaceCollapser
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+class Whitespace extends TestDocument {
+ /** generate the body of the test document */
+ protected void generateDocument(RtfDocumentArea rda, RtfSection sect)
+ throws IOException {
+ final RtfParagraph p1 = sect.newParagraph();
+ p1.newText("\t Each word of this paragraph must be "
+ + "separated\tfrom\t\n\tthe next word with exactly\t \tone");
+ p1.newText(" space.");
+
+ final RtfParagraph p2 = sect.newParagraph();
+ p2.newText("");
+ p2.newText("In this");
+ p2.newText(" paragraph ");
+ p2.newText("as well,");
+ p2.newText(" there must\tbe \t");
+ p2.newText("exactly");
+ p2.newText(" one space ");
+ p2.newText("between each\tword and the next, and no spaces at the "
+ + "beginning or end of the paragraph.");
+
+ final RtfParagraph p3 = sect.newParagraph();
+ p3.newText("The word 'boomerang' must be written after this with no funny spacing: ");
+ p3.newText("boo");
+ p3.newText("me");
+ p3.newText("r");
+ p3.newText("a");
+ p3.newText("ng.");
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/testdocs/package.html b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/package.html
new file mode 100644
index 000000000..6d6d62fdf
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/testdocs/package.html
@@ -0,0 +1,7 @@
+<HTML>
+<TITLE>org.apache.fop.render.rtf.rtflib.testdocs</TITLE>
+<BODY>
+<P>Classes used to test/demonstrate RTFLib capabilities by generating sample
+RTF documents.</P>
+</BODY>
+</HTML> \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/tools/ImageConstants.java b/src/java/org/apache/fop/render/rtf/rtflib/tools/ImageConstants.java
new file mode 100644
index 000000000..3fe38e27e
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/tools/ImageConstants.java
@@ -0,0 +1,131 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.tools;
+
+import java.util.Hashtable;
+
+/** Here will be defined all supported image formats.
+ * This class belongs to the <fo:external-graphic> tag processing.
+ * @author a.putz@skynamics.com (Andreas Putz)
+ */
+
+public class ImageConstants {
+ //////////////////////////////////////////////////
+ // @@ Symbolic constants
+ //////////////////////////////////////////////////
+
+ /** Defines the case, if image is not supported */
+ public static final int I_NOT_SUPPORTED = -1;
+ /** Integer equivalent for EMF */
+ public static final int I_EMF = 0;
+ /** Integer equivalent for PNG */
+ public static final int I_PNG = 1;
+ /** Integer equivalent for JPG */
+ public static final int I_JPG = 2;
+
+ /** Defines the RTF properties */
+ public static final String [] RTF_TAGS = new String []
+ {
+ "emfblip", "pngblip", "jpegblip"
+ };
+
+ /** constant for image conversion basis (??) */
+ public static final int I_TO_CONVERT_BASIS = 50;
+ /** Integer equivalent for GIF */
+ public static final int I_GIF = 50;
+ /** Integer equivalent for JPEG C (??) */
+ public static final int I_JPG_C = 51;
+
+ /** Defines the types for converting rtf supported image types */
+ public static final int [] CONVERT_TO = new int []
+ {
+ I_JPG, I_JPG
+ };
+
+ /** EMF file extension */
+ public static final String EMF_EXT = "emf";
+ /** PNG file extension */
+ public static final String PNG_EXT = "png";
+ /** JPG file extension */
+ public static final String JPG_EXT = "jpg";
+ /** JPEG file extension */
+ public static final String JPEG_EXT = "jpeg";
+ /** GIF file extension */
+ public static final String GIF_EXT = "gif";
+
+ /** Defines the file extensions and the RTF property belongs to */
+ public static final 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
+ //////////////////////////////////////////////////
+
+ /**
+ * Private constructor.
+ */
+ private ImageConstants() {
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/tools/ImageUtil.java b/src/java/org/apache/fop/render/rtf/rtflib/tools/ImageUtil.java
new file mode 100644
index 000000000..a762083db
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/tools/ImageUtil.java
@@ -0,0 +1,226 @@
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.tools;
+
+/** Misc.utilities for images handling
+ * This class belongs to the <fo:external-graphic> tag processing.
+ * @author <a href="mailto:a.putz@skynamics.com">Andreas Putz</a>
+ */
+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
+ * 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
+ * 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 startAt Start index to read from
+ * @param length Number of data elements to read
+ * @param searchForward True if searching forward, False if not (??)
+ *
+ * @return integer
+ */
+ 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;
+ }
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/tools/package.html b/src/java/org/apache/fop/render/rtf/rtflib/tools/package.html
new file mode 100644
index 000000000..1a0347b9b
--- /dev/null
+++ b/src/java/org/apache/fop/render/rtf/rtflib/tools/package.html
@@ -0,0 +1,6 @@
+<HTML>
+<TITLE>org.apache.fop.render.rtf.rtflib.tools</TITLE>
+<BODY>
+<P>Utility classes used in RTF file generation.</P>
+</BODY>
+</HTML> \ No newline at end of file