aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfPage.java
blob: bd2e9e62dad3d061633557545318e33d37b9421f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (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.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* $Id$ */

package org.apache.fop.render.rtf.rtflib.rtfdoc;

/*
 * 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.
 */

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 landscape format */
    public static final String LANDSCAPE = "landscape";

    /** 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";
    
    /** constant for header position */
    public static final String HEADERY = "headery";
    /** constant for footer position */
    public static final String FOOTERY = "footery";

    /** String array of RtfPage attributes */
    public static final String[] PAGE_ATTR = new String[]{
        PAGE_WIDTH, PAGE_HEIGHT, LANDSCAPE, MARGIN_TOP, MARGIN_BOTTOM,
        MARGIN_LEFT, MARGIN_RIGHT, HEADERY, FOOTERY
    };

    /**    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;
    }

}