KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > text > rtf > document > RtfDocumentSettings


1 /*
2  * $Id: RtfDocumentSettings.java 2776 2007-05-23 20:01:40Z hallm $
3  * $Name$
4  *
5  * Copyright 2003, 2004, 2005 by Mark Hall
6  *
7  * The contents of this file are subject to the Mozilla Public License Version 1.1
8  * (the "License"); you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the License.
14  *
15  * The Original Code is 'iText, a free JAVA-PDF library'.
16  *
17  * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
18  * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
19  * All Rights Reserved.
20  * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
21  * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
22  *
23  * Contributor(s): all the names of the contributors are added in the source code
24  * where applicable.
25  *
26  * Alternatively, the contents of this file may be used under the terms of the
27  * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
28  * provisions of LGPL are applicable instead of those above. If you wish to
29  * allow use of your version of this file only under the terms of the LGPL
30  * License and not to allow others to use your version of this file under
31  * the MPL, indicate your decision by deleting the provisions above and
32  * replace them with the notice and other provisions required by the LGPL.
33  * If you do not delete the provisions above, a recipient may use your version
34  * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Library General Public License as published by the Free Software Foundation;
39  * either version 2 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
43  * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
44  * details.
45  *
46  * If you didn't download this code from the following link, you should check if
47  * you aren't using an obsolete version:
48  * http://www.lowagie.com/iText/
49  */

50
51 package com.lowagie.text.rtf.document;
52
53 import com.lowagie.text.rtf.document.output.RtfDataCache;
54 import com.lowagie.text.rtf.style.RtfParagraphStyle;
55
56
57 /**
58  * The RtfDocumentSettings contains output specific settings. These settings modify
59  * how the actual document is then generated and some settings may mean that some
60  * RTF readers can't read the document or render it wrongly.
61  *
62  * @version $Id: RtfDocumentSettings.java 2776 2007-05-23 20:01:40Z hallm $
63  * @author Mark Hall (mhall@edu.uni-klu.ac.at)
64  * @author Thomas Bickel (tmb99@inode.at)
65  */

66 public class RtfDocumentSettings {
67
68     /**
69      * The RtfDocument this RtfDocumentSettings belongs to.
70      */

71     private RtfDocument document = null;
72     /**
73      * Whether to also output the table row definition after the cell content.
74      */

75     private boolean outputTableRowDefinitionAfter = true;
76     /**
77      * Whether to output the line breaks that make the rtf document source more readable.
78      */

79     private boolean outputDebugLineBreaks = true;
80     /**
81      * Whether to always generate soft linebreaks for \n in Chunks.
82      */

83     private boolean alwaysGenerateSoftLinebreaks = false;
84     /**
85      * Whether to always translate characters past 'z' into unicode representations.
86      */

87     private boolean alwaysUseUnicode = true;
88     /**
89      * How to cache the document during generation. Defaults to RtfDataCache.CACHE_MEMORY;
90      */

91     private int dataCacheStyle = RtfDataCache.CACHE_MEMORY;
92     /**
93      * Whether to write image scaling information. This is required for Word 2000, 97 and Word for Mac
94      */

95     private boolean writeImageScalingInformation = false;
96     /**
97      * Whether images should be written in order to mimick the PDF output.
98      */

99     private boolean imagePDFConformance = true;
100     
101     /**
102      * Constructs a new RtfDocumentSettings object.
103      *
104      * @param document The RtfDocument this RtfDocumentSettings belong to.
105      */

106     public RtfDocumentSettings(RtfDocument document) {
107         this.document = document;
108     }
109     
110     /**
111      * Gets whether to output the line breaks for increased rtf document readability.
112      *
113      * @return Whether to output line breaks.
114      */

115     public boolean isOutputDebugLineBreaks() {
116         return outputDebugLineBreaks;
117     }
118     
119     /**
120      * Sets whether to output the line breaks for increased rtf document readability.
121      * Some line breaks may be added where the rtf specification demands it.
122      *
123      * @param outputDebugLineBreaks The outputDebugLineBreaks to set.
124      */

125     public void setOutputDebugLineBreaks(boolean outputDebugLineBreaks) {
126         this.outputDebugLineBreaks = outputDebugLineBreaks;
127     }
128     
129     /**
130      * Gets whether the table row definition should also be written after the cell content.
131      *
132      * @return Returns the outputTableRowDefinitionAfter.
133      */

134     public boolean isOutputTableRowDefinitionAfter() {
135         return outputTableRowDefinitionAfter;
136     }
137     
138     /**
139      * Sets whether the table row definition should also be written after the cell content.
140      * This is recommended to be set to <code>true</code> if you need Word2000 compatiblity and
141      * <code>false</code> if the document should be opened in OpenOffice.org Writer.
142      *
143      * @param outputTableRowDefinitionAfter The outputTableRowDefinitionAfter to set.
144      */

145     public void setOutputTableRowDefinitionAfter(
146             boolean outputTableRowDefinitionAfter) {
147         this.outputTableRowDefinitionAfter = outputTableRowDefinitionAfter;
148     }
149     
150     /**
151      * Gets whether all linebreaks inside Chunks are generated as soft linebreaks.
152      *
153      * @return <code>True</code> if soft linebreaks are generated, <code>false</code> for hard linebreaks.
154      */

155     public boolean isAlwaysGenerateSoftLinebreaks() {
156         return this.alwaysGenerateSoftLinebreaks;
157     }
158
159     /**
160      * Sets whether to always generate soft linebreaks.
161      *
162      * @param alwaysGenerateSoftLinebreaks Whether to always generate soft linebreaks.
163      */

164     public void setAlwaysGenerateSoftLinebreaks(boolean alwaysGenerateSoftLinebreaks) {
165         this.alwaysGenerateSoftLinebreaks = alwaysGenerateSoftLinebreaks;
166     }
167     
168     /**
169      * Gets whether all characters bigger than 'z' are represented as unicode.
170      *
171      * @return <code>True</code> if unicode representation is used, <code>false</code> otherwise.
172      */

173     public boolean isAlwaysUseUnicode() {
174         return this.alwaysUseUnicode;
175     }
176     
177     /**
178      * Sets whether to represent all characters bigger than 'z' as unicode.
179      *
180      * @param alwaysUseUnicode <code>True</code> to use unicode representation, <code>false</code> otherwise.
181      */

182     public void setAlwaysUseUnicode(boolean alwaysUseUnicode) {
183         this.alwaysUseUnicode = alwaysUseUnicode;
184     }
185
186     /**
187      * Registers the RtfParagraphStyle for further use in the document. This does not need to be
188      * done for the default styles in the RtfParagraphStyle object. Those are added automatically.
189      *
190      * @param rtfParagraphStyle The RtfParagraphStyle to register.
191      */

192     public void registerParagraphStyle(RtfParagraphStyle rtfParagraphStyle) {
193         this.document.getDocumentHeader().registerParagraphStyle(rtfParagraphStyle);
194     }
195     
196     /**
197      * Sets the data cache style. This controls where the document is cached during
198      * generation. Two cache styles are supported:
199      * <ul>
200      * <li>RtfDataCache.CACHE_MEMORY: The document is cached in memory. This is fast,
201      * but places a limit on how big the document can get before causing
202      * OutOfMemoryExceptions.</li>
203      * <li>RtfDataCache.CACHE_DISK: The document is cached on disk. This is slower
204      * than the CACHE_MEMORY setting, but the document size is now only constrained
205      * by the amount of free disk space.</li>
206      * </ul>
207      *
208      * @param dataCacheStyle The data cache style to set. Valid constants can be found
209      * in RtfDataCache.
210      * @see com.lowagie.text.rtf.document.output.RtfDataCache
211      */

212     public void setDataCacheStyle(int dataCacheStyle) {
213         switch(dataCacheStyle) {
214             case RtfDataCache.CACHE_MEMORY_EFFICIENT:
215                 this.dataCacheStyle = RtfDataCache.CACHE_MEMORY_EFFICIENT;
216                 break;
217             case RtfDataCache.CACHE_DISK:
218                 this.dataCacheStyle = RtfDataCache.CACHE_DISK;
219                 break;
220             default:
221             case RtfDataCache.CACHE_MEMORY:
222                 this.dataCacheStyle = RtfDataCache.CACHE_MEMORY;
223                 break;
224         }
225     }
226     
227     /**
228      * Gets the current data cache style.
229      *
230      * @return The current data cache style.
231      */

232     public int getDataCacheStyle() {
233         return this.dataCacheStyle;
234     }
235
236     
237     /**
238      * Gets the current setting on image PDF conformance.
239      *
240      * @return The current image PDF conformance.
241      */

242     public boolean isImagePDFConformance() {
243         return this.imagePDFConformance;
244     }
245
246     
247     /**
248      * Sets the image PDF conformance setting. By default images will be added
249      * as if they were displayed with 72dpi. Set this to <code>false</code>
250      * if images should be generated with the Word default DPI setting.
251      *
252      * @param imagePDFConformance <code>True</code> if PDF equivalence is desired, <code>false</code>
253      * for the default Word display.
254      */

255     public void setImagePDFConformance(boolean imagePDFConformance) {
256         this.imagePDFConformance = imagePDFConformance;
257     }
258
259     
260     /**
261      * Gets whether to write scaling information for images.
262      *
263      * @return Whether to write scaling information for images.
264      */

265     public boolean isWriteImageScalingInformation() {
266         return this.writeImageScalingInformation;
267     }
268
269     
270     /**
271      * Sets whether image scaling information should be written. This needs to be set to <code>true</code>
272      * MS Word 2000, MS Word 97 and Word for Mac.
273      *
274      * @param writeImageScalingInformation Whether to write image scaling information.
275      */

276     public void setWriteImageScalingInformation(boolean writeImageScalingInformation) {
277         this.writeImageScalingInformation = writeImageScalingInformation;
278     }
279     
280     /**
281      * Set the options required for RTF documents to display correctly in MS Word 2000
282      * and MS Word 97.
283      * Sets <code>outputTableRowDefinitionAfter = true</code> and <code>writeImageScalingInformation = true</code>.
284      */

285     public void setOptionsForMSWord2000And97() {
286         this.setOutputTableRowDefinitionAfter(true);
287         this.setWriteImageScalingInformation(true);
288     }
289     
290     /**
291      * Set the options required for RTF documents to display correctly in MS Word for Mac.
292      * Sets <code>writeImageScalingInformation = true</code>.
293      */

294     public void setOptionsForMSWordForMac() {
295         this.setWriteImageScalingInformation(true);
296     }
297     
298     /**
299      * Set the options required for RTF documents to display correctly in MS Word XP (2002).
300      * Sets <code>writeImageScalingInformation = false</code>.
301      */

302     public void setOptionsForMSWordXP() {
303         this.setWriteImageScalingInformation(false);
304     }
305
306     /**
307      * Set the options required for RTF documents to display correctly in OpenOffice.Org
308      * Writer.
309      * Sets <code>outputTableRowDefinitionAfter = false</code>.
310      */

311     public void setOptionsForOpenOfficeOrg() {
312         this.setOutputTableRowDefinitionAfter(false);
313     }
314 }
315
Popular Tags