Source code: org/jfor/jfor/rtflib/rtfdoc/RtfPage.java
1 package org.jfor.jfor.rtflib.rtfdoc;
2
3 import java.io.Writer;
4 import java.io.*;
5 import java.util.*;
6 import java.io.IOException;
7
8 /*-----------------------------------------------------------------------------
9 * jfor - Open-Source XSL-FO to RTF converter - see www.jfor.org
10 *
11 * ====================================================================
12 * jfor Apache-Style Software License.
13 * Copyright (c) 2002 by the jfor project. All rights reserved.
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 *
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 *
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in
24 * the documentation and/or other materials provided with the
25 * distribution.
26 *
27 * 3. The end-user documentation included with the redistribution,
28 * if any, must include the following acknowledgment:
29 * "This product includes software developed
30 * by the jfor project (http://www.jfor.org)."
31 * Alternately, this acknowledgment may appear in the software itself,
32 * if and wherever such third-party acknowledgments normally appear.
33 *
34 * 4. The name "jfor" must not be used to endorse
35 * or promote products derived from this software without prior written
36 * permission. For written permission, please contact info@jfor.org.
37 *
38 * 5. Products derived from this software may not be called "jfor",
39 * nor may "jfor" appear in their name, without prior written
40 * permission of info@jfor.org.
41 *
42 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
43 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
44 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45 * DISCLAIMED. IN NO EVENT SHALL THE JFOR PROJECT OR ITS CONTRIBUTORS BE
46 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
48 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
49 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
50 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
51 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
52 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 * ====================================================================
54 * Contributor(s):
55 * Christopher Scott, scottc@westinghouse.com
56 * Portions created by Christopher Scott, are Coypright (C) 2001
57 * Westinghouse Electric Company. All Rights Reserved.
58 -----------------------------------------------------------------------------*/
59
60 /** Specifies rtf control words. Is the container for page attributes.
61 * Overrides okToWriteRtf.
62 * @author Christopher Scott, scottc@westinghouse.com
63 */
64
65 //------------------------------------------------------------------------------
66 // $Id: RtfPage.java,v 1.3 2003/02/18 16:09:20 rmarra Exp $
67 // $Log: RtfPage.java,v $
68 // Revision 1.3 2003/02/18 16:09:20 rmarra
69 // Contributions Bob Hablutzel
70 // Fixed to emit "landscape" control work if page width is greater than page height.
71 //
72 // Revision 1.2 2002/07/12 08:08:31 bdelacretaz
73 // License changed to jfor Apache-style license
74 //
75 // Revision 1.1 2001/12/28 17:10:23 bdelacretaz
76 // V0.5.2 - first integration of Chris Scott's changes
77 //
78 //------------------------------------------------------------------------------
79
80
81 public class RtfPage
82 extends RtfContainer{
83 private final RtfAttributes m_attrib;
84
85 /**RtfPage attributes*/
86 public final static String PAGE_WIDTH = "paperw";
87 public final static String PAGE_HEIGHT = "paperh";
88
89 public final static String MARGIN_TOP = "margt";
90 public final static String MARGIN_BOTTOM = "margb";
91 public final static String MARGIN_LEFT = "margl";
92 public final static String MARGIN_RIGHT = "margr";
93
94 public final static String[] PAGE_ATTR = new String[]{
95 PAGE_WIDTH, PAGE_HEIGHT, MARGIN_TOP, MARGIN_BOTTOM,
96 MARGIN_LEFT, MARGIN_RIGHT
97 };
98
99 /** RtfPage creates new page attributes with the parent container, the writer
100 and the attributes*/
101 RtfPage(RtfPageArea parent, Writer w, RtfAttributes attrs) throws IOException {
102 super((RtfContainer)parent,w);
103 m_attrib = attrs;
104 }
105
106 /** RtfPage writes the attributes the attributes contained in the string
107 PAGE_ATTR, if not null */
108 protected void writeRtfContent() throws IOException {
109 writeAttributes(m_attrib, PAGE_ATTR);
110
111 if (m_attrib != null)
112 {
113 Object widthRaw = m_attrib.getValue( PAGE_WIDTH );
114 Object heightRaw = m_attrib.getValue( PAGE_HEIGHT );
115
116 if ((widthRaw instanceof Integer) && (heightRaw instanceof Integer) &&
117 ((Integer) widthRaw).intValue() > ((Integer) heightRaw).intValue())
118 {
119 writeControlWord( "landscape" );
120 }
121 }
122 }
123
124 /** RtfPage - attributes accessor */
125 public RtfAttributes getAttributes(){
126 return m_attrib;
127 }
128
129 /** RtfPage - is overwritten here because page attributes have no content
130 only attributes. RtfContainer is defined not to write when empty.
131 Therefore must make this true to print.*/
132 protected boolean okToWriteRtf()
133 {
134 return true;
135 }
136
137 }