aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/lowagie/text/rtf/text
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/lowagie/text/rtf/text')
-rw-r--r--src/main/java/com/lowagie/text/rtf/text/RtfAnnotation.java133
-rw-r--r--src/main/java/com/lowagie/text/rtf/text/RtfChapter.java105
-rw-r--r--src/main/java/com/lowagie/text/rtf/text/RtfChunk.java202
-rw-r--r--src/main/java/com/lowagie/text/rtf/text/RtfNewPage.java53
-rw-r--r--src/main/java/com/lowagie/text/rtf/text/RtfParagraph.java211
-rw-r--r--src/main/java/com/lowagie/text/rtf/text/RtfPhrase.java203
-rw-r--r--src/main/java/com/lowagie/text/rtf/text/RtfSection.java201
-rw-r--r--src/main/java/com/lowagie/text/rtf/text/RtfTab.java140
-rw-r--r--src/main/java/com/lowagie/text/rtf/text/RtfTabGroup.java127
9 files changed, 1375 insertions, 0 deletions
diff --git a/src/main/java/com/lowagie/text/rtf/text/RtfAnnotation.java b/src/main/java/com/lowagie/text/rtf/text/RtfAnnotation.java
new file mode 100644
index 0000000..f7c02c2
--- /dev/null
+++ b/src/main/java/com/lowagie/text/rtf/text/RtfAnnotation.java
@@ -0,0 +1,133 @@
+/*
+ * $Id: RtfAnnotation.java,v 1.16 2005/05/04 14:33:46 blowagie Exp $
+ * $Name: $
+ *
+ * Copyright 2001, 2002, 2003, 2004 by Mark Hall
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * (the "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the License.
+ *
+ * The Original Code is 'iText, a free JAVA-PDF library'.
+ *
+ * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
+ * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
+ * All Rights Reserved.
+ * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
+ * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
+ *
+ * Contributor(s): all the names of the contributors are added in the source code
+ * where applicable.
+ *
+ * Alternatively, the contents of this file may be used under the terms of the
+ * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
+ * provisions of LGPL are applicable instead of those above. If you wish to
+ * allow use of your version of this file only under the terms of the LGPL
+ * License and not to allow others to use your version of this file under
+ * the MPL, indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by the LGPL.
+ * If you do not delete the provisions above, a recipient may use your version
+ * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the MPL as stated above or under the terms of the GNU
+ * Library General Public License as published by the Free Software Foundation;
+ * either version 2 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
+ * details.
+ *
+ * If you didn't download this code from the following link, you should check if
+ * you aren't using an obsolete version:
+ * http://www.lowagie.com/iText/
+ */
+
+package com.lowagie.text.rtf.text;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import com.lowagie.text.Annotation;
+import com.lowagie.text.rtf.RtfElement;
+import com.lowagie.text.rtf.document.RtfDocument;
+
+
+/**
+ * The RtfAnnotation provides support for adding Annotations to the rtf document.
+ * Only simple Annotations with Title / Content are supported.
+ *
+ * @version $Version:$
+ * @author Mark Hall (mhall@edu.uni-klu.ac.at)
+ */
+public class RtfAnnotation extends RtfElement {
+
+ /**
+ * Constant for the id of the annotation
+ */
+ private static final byte[] ANNOTATION_ID = "\\*\\atnid".getBytes();
+ /**
+ * Constant for the author of the annotation
+ */
+ private static final byte[] ANNOTATION_AUTHOR = "\\*\\atnauthor".getBytes();
+ /**
+ * Constant for the actual annotation
+ */
+ private static final byte[] ANNOTATION = "\\*\\annotation".getBytes();
+
+ /**
+ * The title of this RtfAnnotation
+ */
+ private String title = "";
+ /**
+ * The content of this RtfAnnotation
+ */
+ private String content = "";
+
+ /**
+ * Constructs a RtfAnnotation based on an Annotation.
+ *
+ * @param doc The RtfDocument this RtfAnnotation belongs to
+ * @param annotation The Annotation this RtfAnnotation is based off
+ */
+ public RtfAnnotation(RtfDocument doc, Annotation annotation) {
+ super(doc);
+ title = annotation.title();
+ content = annotation.content();
+ }
+
+ /**
+ * Writes the content of the RtfAnnotation
+ *
+ * @return The content of this RtfAnnotation
+ */
+ public byte[] write() {
+ ByteArrayOutputStream result = new ByteArrayOutputStream();
+ try {
+ result.write(OPEN_GROUP);
+ result.write(ANNOTATION_ID);
+ result.write(DELIMITER);
+ result.write(intToByteArray(document.getRandomInt()));
+ result.write(CLOSE_GROUP);
+ result.write(OPEN_GROUP);
+ result.write(ANNOTATION_AUTHOR);
+ result.write(DELIMITER);
+ result.write(title.getBytes());
+ result.write(CLOSE_GROUP);
+ result.write(OPEN_GROUP);
+ result.write(ANNOTATION);
+ result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
+ result.write(DELIMITER);
+ result.write(content.getBytes());
+ result.write(CLOSE_GROUP);
+ } catch(IOException ioe) {
+ ioe.printStackTrace();
+ }
+ return result.toByteArray();
+ }
+}
diff --git a/src/main/java/com/lowagie/text/rtf/text/RtfChapter.java b/src/main/java/com/lowagie/text/rtf/text/RtfChapter.java
new file mode 100644
index 0000000..df176ca
--- /dev/null
+++ b/src/main/java/com/lowagie/text/rtf/text/RtfChapter.java
@@ -0,0 +1,105 @@
+/*
+ * $Id: RtfChapter.java,v 1.18 2005/09/11 20:17:41 hallm Exp $
+ * $Name: $
+ *
+ * Copyright 2001, 2002 by Mark Hall
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * (the "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the License.
+ *
+ * The Original Code is 'iText, a free JAVA-PDF library'.
+ *
+ * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
+ * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
+ * All Rights Reserved.
+ * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
+ * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
+ *
+ * Contributor(s): all the names of the contributors are added in the source code
+ * where applicable.
+ *
+ * Alternatively, the contents of this file may be used under the terms of the
+ * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
+ * provisions of LGPL are applicable instead of those above. If you wish to
+ * allow use of your version of this file only under the terms of the LGPL
+ * License and not to allow others to use your version of this file under
+ * the MPL, indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by the LGPL.
+ * If you do not delete the provisions above, a recipient may use your version
+ * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the MPL as stated above or under the terms of the GNU
+ * Library General Public License as published by the Free Software Foundation;
+ * either version 2 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
+ * details.
+ *
+ * If you didn't download this code from the following link, you should check if
+ * you aren't using an obsolete version:
+ * http://www.lowagie.com/iText/
+ */
+
+package com.lowagie.text.rtf.text;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import com.lowagie.text.Chapter;
+import com.lowagie.text.rtf.RtfBasicElement;
+import com.lowagie.text.rtf.document.RtfDocument;
+
+
+/**
+ * The RtfChapter wraps a Chapter element.
+ * INTERNAL CLASS
+ *
+ * @version $Revision: 1.18 $
+ * @author Mark Hall (mhall@edu.uni-klu.ac.at)
+ */
+public class RtfChapter extends RtfSection {
+
+ /**
+ * Constructs a RtfChapter for a given Chapter
+ *
+ * @param doc The RtfDocument this RtfChapter belongs to
+ * @param chapter The Chapter this RtfChapter is based on
+ */
+ public RtfChapter(RtfDocument doc, Chapter chapter) {
+ super(doc, chapter);
+ }
+
+ /**
+ * Writes the RtfChapter and its contents
+ *
+ * @return A byte array containing the RtfChapter and its contents
+ */
+ public byte[] write() {
+ ByteArrayOutputStream result = new ByteArrayOutputStream();
+ try {
+ if(this.document.getLastElementWritten() != null && !(this.document.getLastElementWritten() instanceof RtfChapter)) {
+ result.write("\\page".getBytes());
+ }
+ result.write("\\sectd".getBytes());
+ result.write(document.getDocumentHeader().writeSectionDefinition());
+ if(this.title != null) {
+ result.write(this.title.write());
+ }
+ for(int i = 0; i < items.size(); i++) {
+ result.write(((RtfBasicElement) items.get(i)).write());
+ }
+ result.write("\\sect".getBytes());
+ } catch(IOException ioe) {
+ ioe.printStackTrace();
+ }
+ return result.toByteArray();
+ }
+}
diff --git a/src/main/java/com/lowagie/text/rtf/text/RtfChunk.java b/src/main/java/com/lowagie/text/rtf/text/RtfChunk.java
new file mode 100644
index 0000000..7368c48
--- /dev/null
+++ b/src/main/java/com/lowagie/text/rtf/text/RtfChunk.java
@@ -0,0 +1,202 @@
+/*
+ * $Id: RtfChunk.java,v 1.12 2005/07/23 10:57:32 hallm Exp $
+ * $Name: $
+ *
+ * Copyright 2001, 2002, 2003, 2004 by Mark Hall
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * (the "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the License.
+ *
+ * The Original Code is 'iText, a free JAVA-PDF library'.
+ *
+ * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
+ * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
+ * All Rights Reserved.
+ * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
+ * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
+ *
+ * Contributor(s): all the names of the contributors are added in the source code
+ * where applicable.
+ *
+ * Alternatively, the contents of this file may be used under the terms of the
+ * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
+ * provisions of LGPL are applicable instead of those above. If you wish to
+ * allow use of your version of this file only under the terms of the LGPL
+ * License and not to allow others to use your version of this file under
+ * the MPL, indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by the LGPL.
+ * If you do not delete the provisions above, a recipient may use your version
+ * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the MPL as stated above or under the terms of the GNU
+ * Library General Public License as published by the Free Software Foundation;
+ * either version 2 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
+ * details.
+ *
+ * If you didn't download this code from the following link, you should check if
+ * you aren't using an obsolete version:
+ * http://www.lowagie.com/iText/
+ */
+
+package com.lowagie.text.rtf.text;
+
+import java.awt.Color;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import com.lowagie.text.Chunk;
+import com.lowagie.text.rtf.RtfElement;
+import com.lowagie.text.rtf.document.RtfDocument;
+import com.lowagie.text.rtf.style.RtfColor;
+import com.lowagie.text.rtf.style.RtfFont;
+
+
+/**
+ * The RtfChunk contains one piece of text. The smallest text element available
+ * in iText.
+ *
+ * @version $Version:$
+ * @author Mark Hall (mhall@edu.uni-klu.ac.at)
+ */
+public class RtfChunk extends RtfElement {
+
+ /**
+ * Constant for the subscript flag
+ */
+ private static final byte[] FONT_SUBSCRIPT = "\\sub".getBytes();
+ /**
+ * Constant for the superscript flag
+ */
+ private static final byte[] FONT_SUPERSCRIPT = "\\super".getBytes();
+ /**
+ * Constant for the end of sub / superscript flag
+ */
+ private static final byte[] FONT_END_SUPER_SUBSCRIPT = "\\nosupersub".getBytes();
+ /**
+ * Constant for background colour.
+ */
+ private static final byte[] HIGHLIGHT = "\\highlight".getBytes();
+
+ /**
+ * The font of this RtfChunk
+ */
+ private RtfFont font = null;
+ /**
+ * The actual content of this RtfChunk
+ */
+ private String content = "";
+ /**
+ * Whether to use soft line breaks instead of hard ones.
+ */
+ private boolean softLineBreaks = false;
+ /**
+ * The super / subscript of this RtfChunk
+ */
+ private float superSubScript = 0;
+ /**
+ * An optional background colour.
+ */
+ private RtfColor background = null;
+
+ /**
+ * Constructs a RtfChunk based on the content of a Chunk
+ *
+ * @param doc The RtfDocument that this Chunk belongs to
+ * @param chunk The Chunk that this RtfChunk is based on
+ */
+ public RtfChunk(RtfDocument doc, Chunk chunk) {
+ super(doc);
+
+ if(chunk == null) {
+ return;
+ }
+
+ if(chunk.getAttributes() != null && chunk.getAttributes().get(Chunk.SUBSUPSCRIPT) != null) {
+ this.superSubScript = ((Float)chunk.getAttributes().get(Chunk.SUBSUPSCRIPT)).floatValue();
+ }
+ if(chunk.getAttributes() != null && chunk.getAttributes().get(Chunk.BACKGROUND) != null) {
+ this.background = new RtfColor(this.document, (Color) ((Object[]) chunk.getAttributes().get(Chunk.BACKGROUND))[0]);
+ }
+ font = new RtfFont(doc, chunk.font());
+ content = chunk.content();
+ }
+
+ /**
+ * Writes the content of this RtfChunk. First the font information
+ * is written, then the content, and then more font information
+ *
+ * @return A byte array with the content of this RtfChunk
+ */
+ public byte[] write() {
+ ByteArrayOutputStream result = new ByteArrayOutputStream();
+ try {
+ if(this.background != null) {
+ result.write(OPEN_GROUP);
+ }
+
+ result.write(font.writeBegin());
+ if(superSubScript < 0) {
+ result.write(FONT_SUBSCRIPT);
+ } else if(superSubScript > 0) {
+ result.write(FONT_SUPERSCRIPT);
+ }
+ if(this.background != null) {
+ result.write(HIGHLIGHT);
+ result.write(intToByteArray(this.background.getColorNumber()));
+ }
+ result.write(DELIMITER);
+
+ result.write(document.filterSpecialChar(content, false, softLineBreaks || this.document.getDocumentSettings().isAlwaysGenerateSoftLinebreaks()).getBytes());
+
+ if(superSubScript != 0) {
+ result.write(FONT_END_SUPER_SUBSCRIPT);
+ }
+ result.write(font.writeEnd());
+
+ if(this.background != null) {
+ result.write(CLOSE_GROUP);
+ }
+ } catch(IOException ioe) {
+ ioe.printStackTrace();
+ }
+ return result.toByteArray();
+ }
+
+ /**
+ * Sets the RtfDocument this RtfChunk belongs to.
+ *
+ * @param doc The RtfDocument to use
+ */
+ public void setRtfDocument(RtfDocument doc) {
+ super.setRtfDocument(doc);
+ this.font.setRtfDocument(this.document);
+ }
+
+ /**
+ * Sets whether to use soft line breaks instead of default hard ones.
+ *
+ * @param softLineBreaks whether to use soft line breaks instead of default hard ones.
+ */
+ public void setSoftLineBreaks(boolean softLineBreaks) {
+ this.softLineBreaks = softLineBreaks;
+ }
+
+ /**
+ * Gets whether to use soft line breaks instead of default hard ones.
+ *
+ * @return whether to use soft line breaks instead of default hard ones.
+ */
+ public boolean getSoftLineBreaks() {
+ return this.softLineBreaks;
+ }
+}
diff --git a/src/main/java/com/lowagie/text/rtf/text/RtfNewPage.java b/src/main/java/com/lowagie/text/rtf/text/RtfNewPage.java
new file mode 100644
index 0000000..3bb7a88
--- /dev/null
+++ b/src/main/java/com/lowagie/text/rtf/text/RtfNewPage.java
@@ -0,0 +1,53 @@
+/*
+ * Created on Aug 12, 2004
+ *
+ * To change the template for this generated file go to
+ * Window - Preferences - Java - Code Generation - Code and Comments
+ */
+package com.lowagie.text.rtf.text;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import com.lowagie.text.rtf.RtfElement;
+import com.lowagie.text.rtf.document.RtfDocument;
+
+
+/**
+ * The RtfNewPage creates a new page. INTERNAL CLASS
+ *
+ * @version $Version:$
+ * @author Mark Hall (mhall@edu.uni-klu.ac.at)
+ */
+public class RtfNewPage extends RtfElement {
+
+ /**
+ * Constant for a new page
+ */
+ private static final byte[] NEW_PAGE = "\\page".getBytes();
+
+ /**
+ * Constructs a RtfNewPage
+ *
+ * @param doc The RtfDocument this RtfNewPage belongs to
+ */
+ public RtfNewPage(RtfDocument doc) {
+ super(doc);
+ }
+
+ /**
+ * Writes a new page
+ *
+ * @return A byte array with the new page set
+ */
+ public byte[] write() {
+ ByteArrayOutputStream result = new ByteArrayOutputStream();
+ try {
+ result.write(NEW_PAGE);
+ result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
+ } catch(IOException ioe) {
+ ioe.printStackTrace();
+ }
+ return result.toByteArray();
+ }
+}
diff --git a/src/main/java/com/lowagie/text/rtf/text/RtfParagraph.java b/src/main/java/com/lowagie/text/rtf/text/RtfParagraph.java
new file mode 100644
index 0000000..c600069
--- /dev/null
+++ b/src/main/java/com/lowagie/text/rtf/text/RtfParagraph.java
@@ -0,0 +1,211 @@
+/*
+ * $Id: RtfParagraph.java,v 1.20 2005/12/24 13:12:43 hallm Exp $
+ * $Name: $
+ *
+ * Copyright 2001, 2002, 2003, 2004 by Mark Hall
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * (the "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the License.
+ *
+ * The Original Code is 'iText, a free JAVA-PDF library'.
+ *
+ * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
+ * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
+ * All Rights Reserved.
+ * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
+ * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
+ *
+ * Contributor(s): all the names of the contributors are added in the source code
+ * where applicable.
+ *
+ * Alternatively, the contents of this file may be used under the terms of the
+ * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
+ * provisions of LGPL are applicable instead of those above. If you wish to
+ * allow use of your version of this file only under the terms of the LGPL
+ * License and not to allow others to use your version of this file under
+ * the MPL, indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by the LGPL.
+ * If you do not delete the provisions above, a recipient may use your version
+ * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the MPL as stated above or under the terms of the GNU
+ * Library General Public License as published by the Free Software Foundation;
+ * either version 2 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
+ * details.
+ *
+ * If you didn't download this code from the following link, you should check if
+ * you aren't using an obsolete version:
+ * http://www.lowagie.com/iText/
+ */
+
+package com.lowagie.text.rtf.text;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import com.lowagie.text.Chunk;
+import com.lowagie.text.DocumentException;
+import com.lowagie.text.Element;
+import com.lowagie.text.Paragraph;
+import com.lowagie.text.rtf.RtfBasicElement;
+import com.lowagie.text.rtf.RtfElement;
+import com.lowagie.text.rtf.document.RtfDocument;
+import com.lowagie.text.rtf.graphic.RtfImage;
+import com.lowagie.text.rtf.style.RtfFont;
+import com.lowagie.text.rtf.style.RtfParagraphStyle;
+
+
+/**
+ * The RtfParagraph is an extension of the RtfPhrase that adds alignment and
+ * indentation properties. It wraps a Paragraph.
+ *
+ * @version $Revision: 1.20 $
+ * @author Mark Hall (mhall@edu.uni-klu.ac.at)
+ */
+public class RtfParagraph extends RtfPhrase {
+
+ /**
+ * Constant for the end of a paragraph
+ */
+ public static final byte[] PARAGRAPH = "\\par".getBytes();
+
+ /**
+ * An optional RtfParagraphStyle to use for styling.
+ */
+ private RtfParagraphStyle paragraphStyle = null;
+
+ /**
+ * Constructs a RtfParagraph belonging to a RtfDocument based on a Paragraph.
+ *
+ * @param doc The RtfDocument this RtfParagraph belongs to
+ * @param paragraph The Paragraph that this RtfParagraph is based on
+ */
+ public RtfParagraph(RtfDocument doc, Paragraph paragraph) {
+ super(doc);
+
+ RtfFont baseFont = null;
+ if(paragraph.font() instanceof RtfParagraphStyle) {
+ this.paragraphStyle = this.document.getDocumentHeader().getRtfParagraphStyle(((RtfParagraphStyle) paragraph.font()).getStyleName());
+ baseFont = this.paragraphStyle;
+ } else {
+ baseFont = new RtfFont(this.document, paragraph.font());
+ this.paragraphStyle = new RtfParagraphStyle(this.document, this.document.getDocumentHeader().getRtfParagraphStyle("Normal"));
+ this.paragraphStyle.setAlignment(paragraph.alignment());
+ this.paragraphStyle.setIndentLeft((int) (paragraph.indentationLeft() * RtfElement.TWIPS_FACTOR));
+ this.paragraphStyle.setIndentRight((int) (paragraph.indentationRight() * RtfElement.TWIPS_FACTOR));
+ this.paragraphStyle.setSpacingBefore((int) (paragraph.spacingBefore() * RtfElement.TWIPS_FACTOR));
+ this.paragraphStyle.setSpacingAfter((int) (paragraph.spacingAfter() * RtfElement.TWIPS_FACTOR));
+ if(paragraph.leadingDefined()) {
+ this.paragraphStyle.setLineLeading((int) (paragraph.leading() * RtfElement.TWIPS_FACTOR));
+ }
+ this.paragraphStyle.setKeepTogether(paragraph.getKeepTogether());
+ }
+
+ for(int i = 0; i < paragraph.size(); i++) {
+ Element chunk = (Element) paragraph.get(i);
+ if(chunk instanceof Chunk) {
+ ((Chunk) chunk).setFont(baseFont.difference(((Chunk) chunk).font()));
+ } else if(chunk instanceof RtfImage) {
+ ((RtfImage) chunks.get(i)).setAlignment(this.paragraphStyle.getAlignment());
+ }
+ try {
+ chunks.add(doc.getMapper().mapElement(chunk));
+ } catch(DocumentException de) {
+ }
+ }
+ }
+
+ /**
+ * Set whether this RtfParagraph must stay on the same page as the next one.
+ *
+ * @param keepTogetherWithNext Whether this RtfParagraph must keep together with the next.
+ */
+ public void setKeepTogetherWithNext(boolean keepTogetherWithNext) {
+ this.paragraphStyle.setKeepTogetherWithNext(keepTogetherWithNext);
+ }
+
+ /**
+ * Writes the content of this RtfParagraph. First paragraph specific data is written
+ * and then the RtfChunks of this RtfParagraph are added.
+ *
+ * @return The content of this RtfParagraph
+ */
+ public byte[] write() {
+ ByteArrayOutputStream result = new ByteArrayOutputStream();
+ try {
+ result.write(PARAGRAPH_DEFAULTS);
+
+ if(inTable) {
+ result.write(IN_TABLE);
+ }
+
+ if(this.paragraphStyle != null) {
+ result.write(this.paragraphStyle.writeBegin());
+ }
+
+ for(int i = 0; i < chunks.size(); i++) {
+ result.write(((RtfBasicElement) chunks.get(i)).write());
+ }
+
+ if(this.paragraphStyle != null) {
+ result.write(this.paragraphStyle.writeEnd());
+ }
+
+ if(!inTable) {
+ result.write(PARAGRAPH);
+ }
+ if(this.document.getDocumentSettings().isOutputDebugLineBreaks()) {
+ result.write('\n');
+ }
+ } catch(IOException ioe) {
+ ioe.printStackTrace();
+ }
+ return result.toByteArray();
+ }
+
+ /**
+ * Gets the left indentation of this RtfParagraph.
+ *
+ * @return The left indentation.
+ */
+ public int getIndentLeft() {
+ return this.paragraphStyle.getIndentLeft();
+ }
+
+ /**
+ * Sets the left indentation of this RtfParagraph.
+ *
+ * @param indentLeft The left indentation to use.
+ */
+ public void setIndentLeft(int indentLeft) {
+ this.paragraphStyle.setIndentLeft(indentLeft);
+ }
+
+ /**
+ * Gets the right indentation of this RtfParagraph.
+ *
+ * @return The right indentation.
+ */
+ public int getIndentRight() {
+ return this.paragraphStyle.getIndentRight();
+ }
+
+ /**
+ * Sets the right indentation of this RtfParagraph.
+ *
+ * @param indentRight The right indentation to use.
+ */
+ public void setIndentRight(int indentRight) {
+ this.paragraphStyle.setIndentRight(indentRight);
+ }
+}
diff --git a/src/main/java/com/lowagie/text/rtf/text/RtfPhrase.java b/src/main/java/com/lowagie/text/rtf/text/RtfPhrase.java
new file mode 100644
index 0000000..f5d79a9
--- /dev/null
+++ b/src/main/java/com/lowagie/text/rtf/text/RtfPhrase.java
@@ -0,0 +1,203 @@
+/*
+ * $Id: RtfPhrase.java,v 1.14 2006/02/09 17:13:35 hallm Exp $
+ * $Name: $
+ *
+ * Copyright 2001, 2002, 2003, 2004 by Mark Hall
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * (the "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the License.
+ *
+ * The Original Code is 'iText, a free JAVA-PDF library'.
+ *
+ * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
+ * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
+ * All Rights Reserved.
+ * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
+ * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
+ *
+ * Contributor(s): all the names of the contributors are added in the source code
+ * where applicable.
+ *
+ * Alternatively, the contents of this file may be used under the terms of the
+ * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
+ * provisions of LGPL are applicable instead of those above. If you wish to
+ * allow use of your version of this file only under the terms of the LGPL
+ * License and not to allow others to use your version of this file under
+ * the MPL, indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by the LGPL.
+ * If you do not delete the provisions above, a recipient may use your version
+ * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the MPL as stated above or under the terms of the GNU
+ * Library General Public License as published by the Free Software Foundation;
+ * either version 2 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
+ * details.
+ *
+ * If you didn't download this code from the following link, you should check if
+ * you aren't using an obsolete version:
+ * http://www.lowagie.com/iText/
+ */
+
+package com.lowagie.text.rtf.text;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import com.lowagie.text.Chunk;
+import com.lowagie.text.DocumentException;
+import com.lowagie.text.Element;
+import com.lowagie.text.Phrase;
+import com.lowagie.text.rtf.RtfBasicElement;
+import com.lowagie.text.rtf.RtfElement;
+import com.lowagie.text.rtf.document.RtfDocument;
+import com.lowagie.text.rtf.style.RtfFont;
+
+
+/**
+ * The RtfPhrase contains multiple RtfChunks
+ *
+ * @version $Id: RtfPhrase.java,v 1.14 2006/02/09 17:13:35 hallm Exp $
+ * @author Mark Hall (mhall@edu.uni-klu.ac.at)
+ */
+public class RtfPhrase extends RtfElement {
+
+ /**
+ * Constant for the resetting of the paragraph defaults
+ */
+ public static final byte[] PARAGRAPH_DEFAULTS = "\\pard".getBytes();
+ /**
+ * Constant for phrase in a table indication
+ */
+ public static final byte[] IN_TABLE = "\\intbl".getBytes();
+ /**
+ * Constant for the line spacing.
+ */
+ public static final byte[] LINE_SPACING = "\\sl".getBytes();
+
+ /**
+ * ArrayList containing the RtfChunks of this RtfPhrase
+ */
+ protected ArrayList chunks = new ArrayList();
+ /**
+ * The height of each line.
+ */
+ private int lineLeading = 0;
+
+ /**
+ * A basically empty constructor that is used by the RtfParagraph.
+ *
+ * @param doc The RtfDocument this RtfPhrase belongs to.
+ */
+ protected RtfPhrase(RtfDocument doc) {
+ super(doc);
+ }
+
+ /**
+ * Constructs a new RtfPhrase for the RtfDocument with the given Phrase
+ *
+ * @param doc The RtfDocument this RtfPhrase belongs to
+ * @param phrase The Phrase this RtfPhrase is based on
+ */
+ public RtfPhrase(RtfDocument doc, Phrase phrase) {
+ super(doc);
+
+ if(phrase == null) {
+ return;
+ }
+
+ if(phrase.leadingDefined()) {
+ this.lineLeading = (int) (phrase.leading() * RtfElement.TWIPS_FACTOR);
+ } else {
+ this.lineLeading = 0;
+ }
+
+ RtfFont phraseFont = new RtfFont(null, phrase.font());
+ for(int i = 0; i < phrase.size(); i++) {
+ Element chunk = (Element) phrase.get(i);
+ if(chunk instanceof Chunk) {
+ ((Chunk) chunk).setFont(phraseFont.difference(((Chunk) chunk).font()));
+ }
+ try {
+ chunks.add(doc.getMapper().mapElement(chunk));
+ } catch(DocumentException de) {
+ }
+ }
+ }
+
+ /**
+ * Write the content of this RtfPhrase. First resets to the paragraph defaults
+ * then if the RtfPhrase is in a RtfCell a marker for this is written and finally
+ * the RtfChunks of this RtfPhrase are written.
+ *
+ * @return The content of this RtfPhrase
+ */
+ public byte[] write() {
+ ByteArrayOutputStream result = new ByteArrayOutputStream();
+ try {
+ result.write(PARAGRAPH_DEFAULTS);
+ if(inTable) {
+ result.write(IN_TABLE);
+ }
+ if(this.lineLeading > 0) {
+ result.write(LINE_SPACING);
+ result.write(intToByteArray(this.lineLeading));
+ }
+ for(int i = 0; i < chunks.size(); i++) {
+ result.write(((RtfBasicElement) chunks.get(i)).write());
+ }
+ } catch(IOException ioe) {
+ ioe.printStackTrace();
+ }
+ return result.toByteArray();
+ }
+
+ /**
+ * Sets whether this RtfPhrase is in a table. Sets the correct inTable setting for all
+ * child elements.
+ *
+ * @param inTable <code>True</code> if this RtfPhrase is in a table, <code>false</code> otherwise
+ */
+ public void setInTable(boolean inTable) {
+ super.setInTable(inTable);
+ for(int i = 0; i < this.chunks.size(); i++) {
+ ((RtfBasicElement) this.chunks.get(i)).setInTable(inTable);
+ }
+ }
+
+ /**
+ * Sets whether this RtfPhrase is in a header. Sets the correct inTable setting for all
+ * child elements.
+ *
+ * @param inHeader <code>True</code> if this RtfPhrase is in a header, <code>false</code> otherwise
+ */
+ public void setInHeader(boolean inHeader) {
+ super.setInHeader(inHeader);
+ for(int i = 0; i < this.chunks.size(); i++) {
+ ((RtfBasicElement) this.chunks.get(i)).setInHeader(inHeader);
+ }
+ }
+
+ /**
+ * Sets the RtfDocument this RtfPhrase belongs to. Also sets the RtfDocument for all child
+ * elements.
+ *
+ * @param doc The RtfDocument to use
+ */
+ public void setRtfDocument(RtfDocument doc) {
+ super.setRtfDocument(doc);
+ for(int i = 0; i < this.chunks.size(); i++) {
+ ((RtfBasicElement) this.chunks.get(i)).setRtfDocument(this.document);
+ }
+ }
+}
diff --git a/src/main/java/com/lowagie/text/rtf/text/RtfSection.java b/src/main/java/com/lowagie/text/rtf/text/RtfSection.java
new file mode 100644
index 0000000..2b5ad86
--- /dev/null
+++ b/src/main/java/com/lowagie/text/rtf/text/RtfSection.java
@@ -0,0 +1,201 @@
+/*
+ * $Id: RtfSection.java,v 1.11 2005/08/19 21:17:04 hallm Exp $
+ * $Name: $
+ *
+ * Copyright 2001, 2002, 2003, 2004 by Mark Hall
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * (the "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the License.
+ *
+ * The Original Code is 'iText, a free JAVA-PDF library'.
+ *
+ * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
+ * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
+ * All Rights Reserved.
+ * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
+ * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
+ *
+ * Contributor(s): all the names of the contributors are added in the source code
+ * where applicable.
+ *
+ * Alternatively, the contents of this file may be used under the terms of the
+ * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
+ * provisions of LGPL are applicable instead of those above. If you wish to
+ * allow use of your version of this file only under the terms of the LGPL
+ * License and not to allow others to use your version of this file under
+ * the MPL, indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by the LGPL.
+ * If you do not delete the provisions above, a recipient may use your version
+ * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the MPL as stated above or under the terms of the GNU
+ * Library General Public License as published by the Free Software Foundation;
+ * either version 2 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
+ * details.
+ *
+ * If you didn't download this code from the following link, you should check if
+ * you aren't using an obsolete version:
+ * http://www.lowagie.com/iText/
+ */
+
+package com.lowagie.text.rtf.text;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.ArrayList;
+
+import com.lowagie.text.Chunk;
+import com.lowagie.text.DocumentException;
+import com.lowagie.text.Element;
+import com.lowagie.text.Section;
+import com.lowagie.text.rtf.RtfBasicElement;
+import com.lowagie.text.rtf.RtfElement;
+import com.lowagie.text.rtf.document.RtfDocument;
+import com.lowagie.text.rtf.field.RtfTOCEntry;
+
+
+/**
+ * The RtfSection wraps a Section element.
+ * INTERNAL CLASS
+ *
+ * @version $Revision: 1.11 $
+ * @author Mark Hall (mhall@edu.uni-klu.ac.at)
+ */
+public class RtfSection extends RtfElement {
+
+ /**
+ * The title paragraph of this RtfSection
+ */
+ protected RtfParagraph title = null;
+ /**
+ * The sub-items of this RtfSection
+ */
+ protected ArrayList items = null;
+
+ /**
+ * Constructs a RtfSection for a given Section. If the autogenerateTOCEntries
+ * property of the RtfDocument is set and the title is not empty then a TOC entry
+ * is generated for the title.
+ *
+ * @param doc The RtfDocument this RtfSection belongs to
+ * @param section The Section this RtfSection is based on
+ */
+ public RtfSection(RtfDocument doc, Section section) {
+ super(doc);
+ items = new ArrayList();
+ try {
+ if(section.title() != null) {
+ this.title = (RtfParagraph) doc.getMapper().mapElement(section.title());
+ }
+ if(document.getAutogenerateTOCEntries()) {
+ StringBuffer titleText = new StringBuffer();
+ Iterator it = section.title().iterator();
+ while(it.hasNext()) {
+ Element element = (Element) it.next();
+ if(element.type() == Element.CHUNK) {
+ titleText.append(((Chunk) element).content());
+ }
+ }
+ if(titleText.toString().trim().length() > 0) {
+ RtfTOCEntry tocEntry = new RtfTOCEntry(titleText.toString(), section.title().font());
+ tocEntry.setRtfDocument(this.document);
+ this.items.add(tocEntry);
+ }
+ }
+ Iterator iterator = section.iterator();
+ while(iterator.hasNext()) {
+ Element element = (Element) iterator.next();
+ RtfBasicElement rtfElement = doc.getMapper().mapElement(element);
+ if(rtfElement != null) {
+ items.add(rtfElement);
+ }
+ }
+
+ updateIndentation(section.indentationLeft(), section.indentationRight(), section.indentation());
+ } catch(DocumentException de) {
+ de.printStackTrace();
+ }
+ }
+
+ /**
+ * Write this RtfSection and its contents
+ *
+ * @return A byte array with the RtfSection and its contents
+ */
+ public byte[] write() {
+ ByteArrayOutputStream result = new ByteArrayOutputStream();
+ try {
+ result.write(RtfParagraph.PARAGRAPH);
+ if(this.title != null) {
+ result.write(this.title.write());
+ }
+ for(int i = 0; i < items.size(); i++) {
+ result.write(((RtfBasicElement) items.get(i)).write());
+ }
+ } catch(IOException ioe) {
+ ioe.printStackTrace();
+ }
+ return result.toByteArray();
+ }
+
+ /**
+ * Sets whether this RtfSection is in a table. Sets the correct inTable setting for all
+ * child elements.
+ *
+ * @param inTable <code>True</code> if this RtfSection is in a table, <code>false</code> otherwise
+ */
+ public void setInTable(boolean inTable) {
+ super.setInTable(inTable);
+ for(int i = 0; i < this.items.size(); i++) {
+ ((RtfBasicElement) this.items.get(i)).setInTable(inTable);
+ }
+ }
+
+ /**
+ * Sets whether this RtfSection is in a header. Sets the correct inTable setting for all
+ * child elements.
+ *
+ * @param inHeader <code>True</code> if this RtfSection is in a header, <code>false</code> otherwise
+ */
+ public void setInHeader(boolean inHeader) {
+ super.setInHeader(inHeader);
+ for(int i = 0; i < this.items.size(); i++) {
+ ((RtfBasicElement) this.items.get(i)).setInHeader(inHeader);
+ }
+ }
+
+ /**
+ * Updates the left, right and content indentation of all RtfParagraph and RtfSection
+ * elements that this RtfSection contains.
+ *
+ * @param indentLeft The left indentation to add.
+ * @param indentRight The right indentation to add.
+ * @param indentContent The content indentation to add.
+ */
+ private void updateIndentation(float indentLeft, float indentRight, float indentContent) {
+ if(this.title != null) {
+ this.title.setIndentLeft((int) (this.title.getIndentLeft() + indentLeft * RtfElement.TWIPS_FACTOR));
+ this.title.setIndentRight((int) (this.title.getIndentRight() + indentRight * RtfElement.TWIPS_FACTOR));
+ }
+ for(int i = 0; i < this.items.size(); i++) {
+ RtfBasicElement rtfElement = (RtfBasicElement) this.items.get(i);
+ if(rtfElement instanceof RtfSection) {
+ ((RtfSection) rtfElement).updateIndentation(indentLeft + indentContent, indentRight, 0);
+ } else if(rtfElement instanceof RtfParagraph) {
+ ((RtfParagraph) rtfElement).setIndentLeft((int) (((RtfParagraph) rtfElement).getIndentLeft() + (indentLeft + indentContent) * RtfElement.TWIPS_FACTOR));
+ ((RtfParagraph) rtfElement).setIndentRight((int) (((RtfParagraph) rtfElement).getIndentRight() + indentRight * RtfElement.TWIPS_FACTOR));
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/lowagie/text/rtf/text/RtfTab.java b/src/main/java/com/lowagie/text/rtf/text/RtfTab.java
new file mode 100644
index 0000000..1041ae6
--- /dev/null
+++ b/src/main/java/com/lowagie/text/rtf/text/RtfTab.java
@@ -0,0 +1,140 @@
+/*
+ * $Id: RtfTab.java,v 1.1 2006/06/17 09:51:30 hallm Exp $
+ * $Name: $
+ *
+ * Copyright 2001, 2002, 2003, 2004 by Mark Hall
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * (the "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the License.
+ *
+ * The Original Code is 'iText, a free JAVA-PDF library'.
+ *
+ * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
+ * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
+ * All Rights Reserved.
+ * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
+ * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
+ * Co-Developer of the code is Mark Hall. Portions created by the Co-Developer are
+ * Copyright (C) 2006 by Mark Hall. All Rights Reserved
+ *
+ * Contributor(s): all the names of the contributors are added in the source code
+ * where applicable.
+ *
+ * Alternatively, the contents of this file may be used under the terms of the
+ * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
+ * provisions of LGPL are applicable instead of those above. If you wish to
+ * allow use of your version of this file only under the terms of the LGPL
+ * License and not to allow others to use your version of this file under
+ * the MPL, indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by the LGPL.
+ * If you do not delete the provisions above, a recipient may use your version
+ * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the MPL as stated above or under the terms of the GNU
+ * Library General Public License as published by the Free Software Foundation;
+ * either version 2 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
+ * details.
+ *
+ * If you didn't download this code from the following link, you should check if
+ * you aren't using an obsolete version:
+ * http://www.lowagie.com/iText/
+ */
+
+package com.lowagie.text.rtf.text;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import com.lowagie.text.rtf.RtfAddableElement;
+
+/**
+ * The RtfTab encapsulates a tab position and tab type in a paragraph.
+ * To add tabs to a paragraph construct new RtfTab objects with the desired
+ * tab position and alignment and then add them to the paragraph. In the actual
+ * text the tabs are then defined as standard \t characters.<br /><br />
+ *
+ * <code>RtfTab tab = new RtfTab(300, RtfTab.TAB_LEFT_ALIGN);<br />
+ * Paragraph para = new Paragraph();<br />
+ * para.add(tab);<br />
+ * para.add("This paragraph has a\ttab defined.");</code>
+ *
+ * @version $Revision: 1.1 $
+ * @author Mark Hall (mhall@edu.uni-klu.ac.at)
+ */
+public class RtfTab extends RtfAddableElement {
+
+ /**
+ * A tab where the text is left aligned.
+ */
+ public static final int TAB_LEFT_ALIGN = 0;
+ /**
+ * A tab where the text is centre aligned.
+ */
+ public static final int TAB_CENTER_ALIGN = 1;
+ /**
+ * A tab where the text is right aligned.
+ */
+ public static final int TAB_RIGHT_ALIGN = 2;
+ /**
+ * A tab where the text is aligned on the decimal character. Which
+ * character that is depends on the language settings of the viewer.
+ */
+ public static final int TAB_DECIMAL_ALIGN = 3;
+
+ /**
+ * The tab position in twips.
+ */
+ private int position = 0;
+ /**
+ * The tab alignment.
+ */
+ private int type = TAB_LEFT_ALIGN;
+
+ /**
+ * Constructs a new RtfTab with the given position and type. The position
+ * is in standard iText points. The type is one of the tab alignment
+ * constants defined in the RtfTab.
+ *
+ * @param position The position of the tab in points.
+ * @param type The tab type constant.
+ */
+ public RtfTab(float position, int type) {
+ this.position = (int) Math.round(position * TWIPS_FACTOR);
+ switch(type) {
+ case TAB_LEFT_ALIGN: this.type = TAB_LEFT_ALIGN; break;
+ case TAB_CENTER_ALIGN: this.type = TAB_CENTER_ALIGN; break;
+ case TAB_RIGHT_ALIGN: this.type = TAB_RIGHT_ALIGN; break;
+ case TAB_DECIMAL_ALIGN: this.type = TAB_DECIMAL_ALIGN; break;
+ default: this.type = TAB_LEFT_ALIGN; break;
+ }
+ }
+
+ /**
+ * Writes the tab settings.
+ */
+ public byte[] write() {
+ ByteArrayOutputStream result = new ByteArrayOutputStream();
+ try {
+ switch(this.type) {
+ case TAB_CENTER_ALIGN: result.write("\\tqc".getBytes()); break;
+ case TAB_RIGHT_ALIGN: result.write("\\tqr".getBytes()); break;
+ case TAB_DECIMAL_ALIGN: result.write("\\tqdec".getBytes()); break;
+ }
+ result.write("\\tx".getBytes());
+ result.write(intToByteArray(this.position));
+ } catch(IOException ioe) {
+ ioe.printStackTrace();
+ }
+ return result.toByteArray();
+ }
+}
diff --git a/src/main/java/com/lowagie/text/rtf/text/RtfTabGroup.java b/src/main/java/com/lowagie/text/rtf/text/RtfTabGroup.java
new file mode 100644
index 0000000..e298221
--- /dev/null
+++ b/src/main/java/com/lowagie/text/rtf/text/RtfTabGroup.java
@@ -0,0 +1,127 @@
+/*
+ * $Id: RtfTabGroup.java,v 1.1 2006/06/17 09:51:30 hallm Exp $
+ * $Name: $
+ *
+ * Copyright 2001, 2002, 2003, 2004 by Mark Hall
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * (the "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the License.
+ *
+ * The Original Code is 'iText, a free JAVA-PDF library'.
+ *
+ * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
+ * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
+ * All Rights Reserved.
+ * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
+ * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
+ * Co-Developer of the code is Mark Hall. Portions created by the Co-Developer are
+ * Copyright (C) 2006 by Mark Hall. All Rights Reserved
+ *
+ * Contributor(s): all the names of the contributors are added in the source code
+ * where applicable.
+ *
+ * Alternatively, the contents of this file may be used under the terms of the
+ * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
+ * provisions of LGPL are applicable instead of those above. If you wish to
+ * allow use of your version of this file only under the terms of the LGPL
+ * License and not to allow others to use your version of this file under
+ * the MPL, indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by the LGPL.
+ * If you do not delete the provisions above, a recipient may use your version
+ * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the MPL as stated above or under the terms of the GNU
+ * Library General Public License as published by the Free Software Foundation;
+ * either version 2 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
+ * details.
+ *
+ * If you didn't download this code from the following link, you should check if
+ * you aren't using an obsolete version:
+ * http://www.lowagie.com/iText/
+ */
+
+package com.lowagie.text.rtf.text;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import com.lowagie.text.rtf.RtfAddableElement;
+
+/**
+ * The RtfTabGroup is a convenience class if the same tabs are to be added
+ * to multiple paragraphs.<br /><br />
+ *
+ * <code>RtfTabGroup tabs = new RtfTabGroup();<br />
+ * tabs.add(new RtfTab(70, RtfTab.TAB_LEFT_ALIGN));<br />
+ * tabs.add(new RtfTab(160, RtfTab.TAB_CENTER_ALIGN));<br />
+ * tabs.add(new RtfTab(250, RtfTab.TAB_DECIMAL_ALIGN));<br />
+ * tabs.add(new RtfTab(500, RtfTab.TAB_RIGHT_ALIGN));<br />
+ * Paragraph para = new Paragraph();<br />
+ * para.add(tabs);<br />
+ * para.add("\tLeft aligned\tCentre aligned\t12,45\tRight aligned");</code>
+ *
+ * @version $Revision: 1.1 $
+ * @author Mark Hall (mhall@edu.uni-klu.ac.at)
+ */
+public class RtfTabGroup extends RtfAddableElement {
+ /**
+ * The tabs to add.
+ */
+ private ArrayList tabs = null;
+
+ /**
+ * Constructs an empty RtfTabGroup.
+ */
+ public RtfTabGroup() {
+ this.tabs = new ArrayList();
+ }
+
+ /**
+ * Constructs a RtfTabGroup with a set of tabs.
+ *
+ * @param tabs An ArrayList with the RtfTabs to group in this RtfTabGroup.
+ */
+ public RtfTabGroup(ArrayList tabs) {
+ this.tabs = new ArrayList();
+ for(int i = 0; i < tabs.size(); i++) {
+ if(tabs.get(i) instanceof RtfTab) {
+ this.tabs.add(tabs.get(i));
+ }
+ }
+ }
+
+ /**
+ * Adds a RtfTab to the list of grouped tabs.
+ *
+ * @param tab The RtfTab to add.
+ */
+ public void add(RtfTab tab) {
+ this.tabs.add(tab);
+ }
+
+ /**
+ * Combines the tab output form all grouped tabs.
+ */
+ public byte[] write() {
+ ByteArrayOutputStream result = new ByteArrayOutputStream();
+ try {
+ for(int i = 0; i < this.tabs.size(); i++) {
+ result.write(((RtfTab) this.tabs.get(i)).write());
+ }
+ } catch(IOException ioe) {
+ ioe.printStackTrace();
+ }
+ return result.toByteArray();
+ }
+}