001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: RtfPage.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020: package org.apache.fop.render.rtf.rtflib.rtfdoc;
021:
022: /*
023: * This file is part of the RTF library of the FOP project, which was originally
024: * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
025: * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
026: * the FOP project.
027: */
028:
029: import java.io.IOException;
030: import java.io.Writer;
031:
032: /** Specifies rtf control words. Is the container for page attributes.
033: * Overrides okToWriteRtf.
034: * @author Christopher Scott, scottc@westinghouse.com
035: */
036:
037: public class RtfPage extends RtfContainer {
038: private final RtfAttributes attrib;
039:
040: /**RtfPage attributes*/
041: /** constant for page width */
042: public static final String PAGE_WIDTH = "paperw";
043: /** constant for page height */
044: public static final String PAGE_HEIGHT = "paperh";
045:
046: /** constant for landscape format */
047: public static final String LANDSCAPE = "landscape";
048:
049: /** constant for top margin */
050: public static final String MARGIN_TOP = "margt";
051: /** constant for bottom margin */
052: public static final String MARGIN_BOTTOM = "margb";
053: /** constant for left margin */
054: public static final String MARGIN_LEFT = "margl";
055: /** constant for right margin */
056: public static final String MARGIN_RIGHT = "margr";
057:
058: /** constant for header position */
059: public static final String HEADERY = "headery";
060: /** constant for footer position */
061: public static final String FOOTERY = "footery";
062:
063: /** String array of RtfPage attributes */
064: public static final String[] PAGE_ATTR = new String[] { PAGE_WIDTH,
065: PAGE_HEIGHT, LANDSCAPE, MARGIN_TOP, MARGIN_BOTTOM,
066: MARGIN_LEFT, MARGIN_RIGHT, HEADERY, FOOTERY };
067:
068: /** RtfPage creates new page attributes with the parent container, the writer
069: and the attributes*/
070: RtfPage(RtfPageArea parent, Writer w, RtfAttributes attrs)
071: throws IOException {
072: super ((RtfContainer) parent, w);
073: attrib = attrs;
074: }
075:
076: /**
077: * RtfPage writes the attributes the attributes contained in the string
078: * PAGE_ATTR, if not null
079: * @throws IOException for I/O problems
080: */
081: protected void writeRtfContent() throws IOException {
082: writeAttributes(attrib, PAGE_ATTR);
083:
084: if (attrib != null) {
085: Object widthRaw = attrib.getValue(PAGE_WIDTH);
086: Object heightRaw = attrib.getValue(PAGE_HEIGHT);
087:
088: if ((widthRaw instanceof Integer)
089: && (heightRaw instanceof Integer)
090: && ((Integer) widthRaw).intValue() > ((Integer) heightRaw)
091: .intValue()) {
092: writeControlWord(LANDSCAPE);
093: }
094: }
095: }
096:
097: /**
098: * RtfPage - attributes accessor
099: * @return attributes
100: */
101: public RtfAttributes getAttributes() {
102: return attrib;
103: }
104:
105: /**
106: * RtfPage - is overwritten here because page attributes have no content
107: * only attributes. RtfContainer is defined not to write when empty.
108: * Therefore must make this true to print.
109: * @return true
110: */
111: protected boolean okToWriteRtf() {
112: return true;
113: }
114:
115: }
|