001: /*
002: * $Id: RtfDocumentSettings.java 2776 2007-05-23 20:01:40Z hallm $
003: * $Name$
004: *
005: * Copyright 2003, 2004, 2005 by Mark Hall
006: *
007: * The contents of this file are subject to the Mozilla Public License Version 1.1
008: * (the "License"); you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
010: *
011: * Software distributed under the License is distributed on an "AS IS" basis,
012: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
013: * for the specific language governing rights and limitations under the License.
014: *
015: * The Original Code is 'iText, a free JAVA-PDF library'.
016: *
017: * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
018: * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
019: * All Rights Reserved.
020: * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
021: * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
022: *
023: * Contributor(s): all the names of the contributors are added in the source code
024: * where applicable.
025: *
026: * Alternatively, the contents of this file may be used under the terms of the
027: * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
028: * provisions of LGPL are applicable instead of those above. If you wish to
029: * allow use of your version of this file only under the terms of the LGPL
030: * License and not to allow others to use your version of this file under
031: * the MPL, indicate your decision by deleting the provisions above and
032: * replace them with the notice and other provisions required by the LGPL.
033: * If you do not delete the provisions above, a recipient may use your version
034: * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
035: *
036: * This library is free software; you can redistribute it and/or modify it
037: * under the terms of the MPL as stated above or under the terms of the GNU
038: * Library General Public License as published by the Free Software Foundation;
039: * either version 2 of the License, or any later version.
040: *
041: * This library is distributed in the hope that it will be useful, but WITHOUT
042: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
043: * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
044: * details.
045: *
046: * If you didn't download this code from the following link, you should check if
047: * you aren't using an obsolete version:
048: * http://www.lowagie.com/iText/
049: */
050:
051: package com.lowagie.text.rtf.document;
052:
053: import com.lowagie.text.rtf.document.output.RtfDataCache;
054: import com.lowagie.text.rtf.style.RtfParagraphStyle;
055:
056: /**
057: * The RtfDocumentSettings contains output specific settings. These settings modify
058: * how the actual document is then generated and some settings may mean that some
059: * RTF readers can't read the document or render it wrongly.
060: *
061: * @version $Id: RtfDocumentSettings.java 2776 2007-05-23 20:01:40Z hallm $
062: * @author Mark Hall (mhall@edu.uni-klu.ac.at)
063: * @author Thomas Bickel (tmb99@inode.at)
064: */
065: public class RtfDocumentSettings {
066:
067: /**
068: * The RtfDocument this RtfDocumentSettings belongs to.
069: */
070: private RtfDocument document = null;
071: /**
072: * Whether to also output the table row definition after the cell content.
073: */
074: private boolean outputTableRowDefinitionAfter = true;
075: /**
076: * Whether to output the line breaks that make the rtf document source more readable.
077: */
078: private boolean outputDebugLineBreaks = true;
079: /**
080: * Whether to always generate soft linebreaks for \n in Chunks.
081: */
082: private boolean alwaysGenerateSoftLinebreaks = false;
083: /**
084: * Whether to always translate characters past 'z' into unicode representations.
085: */
086: private boolean alwaysUseUnicode = true;
087: /**
088: * How to cache the document during generation. Defaults to RtfDataCache.CACHE_MEMORY;
089: */
090: private int dataCacheStyle = RtfDataCache.CACHE_MEMORY;
091: /**
092: * Whether to write image scaling information. This is required for Word 2000, 97 and Word for Mac
093: */
094: private boolean writeImageScalingInformation = false;
095: /**
096: * Whether images should be written in order to mimick the PDF output.
097: */
098: private boolean imagePDFConformance = true;
099:
100: /**
101: * Constructs a new RtfDocumentSettings object.
102: *
103: * @param document The RtfDocument this RtfDocumentSettings belong to.
104: */
105: public RtfDocumentSettings(RtfDocument document) {
106: this .document = document;
107: }
108:
109: /**
110: * Gets whether to output the line breaks for increased rtf document readability.
111: *
112: * @return Whether to output line breaks.
113: */
114: public boolean isOutputDebugLineBreaks() {
115: return outputDebugLineBreaks;
116: }
117:
118: /**
119: * Sets whether to output the line breaks for increased rtf document readability.
120: * Some line breaks may be added where the rtf specification demands it.
121: *
122: * @param outputDebugLineBreaks The outputDebugLineBreaks to set.
123: */
124: public void setOutputDebugLineBreaks(boolean outputDebugLineBreaks) {
125: this .outputDebugLineBreaks = outputDebugLineBreaks;
126: }
127:
128: /**
129: * Gets whether the table row definition should also be written after the cell content.
130: *
131: * @return Returns the outputTableRowDefinitionAfter.
132: */
133: public boolean isOutputTableRowDefinitionAfter() {
134: return outputTableRowDefinitionAfter;
135: }
136:
137: /**
138: * Sets whether the table row definition should also be written after the cell content.
139: * This is recommended to be set to <code>true</code> if you need Word2000 compatiblity and
140: * <code>false</code> if the document should be opened in OpenOffice.org Writer.
141: *
142: * @param outputTableRowDefinitionAfter The outputTableRowDefinitionAfter to set.
143: */
144: public void setOutputTableRowDefinitionAfter(
145: boolean outputTableRowDefinitionAfter) {
146: this .outputTableRowDefinitionAfter = outputTableRowDefinitionAfter;
147: }
148:
149: /**
150: * Gets whether all linebreaks inside Chunks are generated as soft linebreaks.
151: *
152: * @return <code>True</code> if soft linebreaks are generated, <code>false</code> for hard linebreaks.
153: */
154: public boolean isAlwaysGenerateSoftLinebreaks() {
155: return this .alwaysGenerateSoftLinebreaks;
156: }
157:
158: /**
159: * Sets whether to always generate soft linebreaks.
160: *
161: * @param alwaysGenerateSoftLinebreaks Whether to always generate soft linebreaks.
162: */
163: public void setAlwaysGenerateSoftLinebreaks(
164: 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(
193: RtfParagraphStyle rtfParagraphStyle) {
194: this .document.getDocumentHeader().registerParagraphStyle(
195: rtfParagraphStyle);
196: }
197:
198: /**
199: * Sets the data cache style. This controls where the document is cached during
200: * generation. Two cache styles are supported:
201: * <ul>
202: * <li>RtfDataCache.CACHE_MEMORY: The document is cached in memory. This is fast,
203: * but places a limit on how big the document can get before causing
204: * OutOfMemoryExceptions.</li>
205: * <li>RtfDataCache.CACHE_DISK: The document is cached on disk. This is slower
206: * than the CACHE_MEMORY setting, but the document size is now only constrained
207: * by the amount of free disk space.</li>
208: * </ul>
209: *
210: * @param dataCacheStyle The data cache style to set. Valid constants can be found
211: * in RtfDataCache.
212: * @see com.lowagie.text.rtf.document.output.RtfDataCache
213: */
214: public void setDataCacheStyle(int dataCacheStyle) {
215: switch (dataCacheStyle) {
216: case RtfDataCache.CACHE_MEMORY_EFFICIENT:
217: this .dataCacheStyle = RtfDataCache.CACHE_MEMORY_EFFICIENT;
218: break;
219: case RtfDataCache.CACHE_DISK:
220: this .dataCacheStyle = RtfDataCache.CACHE_DISK;
221: break;
222: default:
223: case RtfDataCache.CACHE_MEMORY:
224: this .dataCacheStyle = RtfDataCache.CACHE_MEMORY;
225: break;
226: }
227: }
228:
229: /**
230: * Gets the current data cache style.
231: *
232: * @return The current data cache style.
233: */
234: public int getDataCacheStyle() {
235: return this .dataCacheStyle;
236: }
237:
238: /**
239: * Gets the current setting on image PDF conformance.
240: *
241: * @return The current image PDF conformance.
242: */
243: public boolean isImagePDFConformance() {
244: return this .imagePDFConformance;
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: * Gets whether to write scaling information for images.
261: *
262: * @return Whether to write scaling information for images.
263: */
264: public boolean isWriteImageScalingInformation() {
265: return this .writeImageScalingInformation;
266: }
267:
268: /**
269: * Sets whether image scaling information should be written. This needs to be set to <code>true</code>
270: * MS Word 2000, MS Word 97 and Word for Mac.
271: *
272: * @param writeImageScalingInformation Whether to write image scaling information.
273: */
274: public void setWriteImageScalingInformation(
275: boolean writeImageScalingInformation) {
276: this .writeImageScalingInformation = writeImageScalingInformation;
277: }
278:
279: /**
280: * Set the options required for RTF documents to display correctly in MS Word 2000
281: * and MS Word 97.
282: * Sets <code>outputTableRowDefinitionAfter = true</code> and <code>writeImageScalingInformation = true</code>.
283: */
284: public void setOptionsForMSWord2000And97() {
285: this .setOutputTableRowDefinitionAfter(true);
286: this .setWriteImageScalingInformation(true);
287: }
288:
289: /**
290: * Set the options required for RTF documents to display correctly in MS Word for Mac.
291: * Sets <code>writeImageScalingInformation = true</code>.
292: */
293: public void setOptionsForMSWordForMac() {
294: this .setWriteImageScalingInformation(true);
295: }
296:
297: /**
298: * Set the options required for RTF documents to display correctly in MS Word XP (2002).
299: * Sets <code>writeImageScalingInformation = false</code>.
300: */
301: public void setOptionsForMSWordXP() {
302: this .setWriteImageScalingInformation(false);
303: }
304:
305: /**
306: * Set the options required for RTF documents to display correctly in OpenOffice.Org
307: * Writer.
308: * Sets <code>outputTableRowDefinitionAfter = false</code>.
309: */
310: public void setOptionsForOpenOfficeOrg() {
311: this .setOutputTableRowDefinitionAfter(false);
312: }
313: }
|