You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RtfPage.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.render.rtf.rtflib.rtfdoc;
  19. /*
  20. * This file is part of the RTF library of the FOP project, which was originally
  21. * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
  22. * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
  23. * the FOP project.
  24. */
  25. import java.io.IOException;
  26. import java.io.Writer;
  27. /** Specifies rtf control words. Is the container for page attributes.
  28. * Overrides okToWriteRtf.
  29. * @author Christopher Scott, scottc@westinghouse.com
  30. */
  31. public class RtfPage
  32. extends RtfContainer {
  33. private final RtfAttributes attrib;
  34. /**RtfPage attributes*/
  35. /** constant for page width */
  36. public static final String PAGE_WIDTH = "paperw";
  37. /** constant for page height */
  38. public static final String PAGE_HEIGHT = "paperh";
  39. /** constant for landscape format */
  40. public static final String LANDSCAPE = "landscape";
  41. /** constant for top margin */
  42. public static final String MARGIN_TOP = "margt";
  43. /** constant for bottom margin */
  44. public static final String MARGIN_BOTTOM = "margb";
  45. /** constant for left margin */
  46. public static final String MARGIN_LEFT = "margl";
  47. /** constant for right margin */
  48. public static final String MARGIN_RIGHT = "margr";
  49. /** constant for header position */
  50. public static final String HEADERY = "headery";
  51. /** constant for footer position */
  52. public static final String FOOTERY = "footery";
  53. /** constant for itap level */
  54. public static final String ITAP = "itap";
  55. /** String array of RtfPage attributes */
  56. public static final String[] PAGE_ATTR = new String[]{
  57. PAGE_WIDTH, PAGE_HEIGHT, LANDSCAPE, MARGIN_TOP, MARGIN_BOTTOM,
  58. MARGIN_LEFT, MARGIN_RIGHT, HEADERY, FOOTERY, ITAP
  59. };
  60. /** RtfPage creates new page attributes with the parent container, the writer
  61. and the attributes*/
  62. RtfPage(RtfPageArea parent, Writer w, RtfAttributes attrs) throws IOException {
  63. super((RtfContainer)parent, w);
  64. attrib = attrs;
  65. }
  66. /**
  67. * RtfPage writes the attributes the attributes contained in the string
  68. * PAGE_ATTR, if not null
  69. * @throws IOException for I/O problems
  70. */
  71. protected void writeRtfContent() throws IOException {
  72. writeAttributes(attrib, PAGE_ATTR);
  73. if (attrib != null) {
  74. Object widthRaw = attrib.getValue(PAGE_WIDTH);
  75. Object heightRaw = attrib.getValue(PAGE_HEIGHT);
  76. if ((widthRaw instanceof Integer) && (heightRaw instanceof Integer)
  77. && ((Integer) widthRaw).intValue() > ((Integer) heightRaw).intValue()) {
  78. writeControlWord(LANDSCAPE);
  79. }
  80. }
  81. }
  82. /**
  83. * RtfPage - attributes accessor
  84. * @return attributes
  85. */
  86. public RtfAttributes getAttributes() {
  87. return attrib;
  88. }
  89. /**
  90. * RtfPage - is overwritten here because page attributes have no content
  91. * only attributes. RtfContainer is defined not to write when empty.
  92. * Therefore must make this true to print.
  93. * @return true
  94. */
  95. protected boolean okToWriteRtf() {
  96. return true;
  97. }
  98. }