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.

RtfHeader.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. import java.util.HashMap;
  28. import java.util.Map;
  29. /**
  30. * <p>RTF file header, contains style, font and other document-level information.</p>
  31. *
  32. * <p>This work was authored by Bertrand Delacretaz (bdelacretaz@codeconsult.ch),
  33. * Andreas Putz (a.putz@skynamics.com), and
  34. * Marc Wilhelm Kuester.</p>
  35. */
  36. class RtfHeader extends RtfContainer {
  37. private static final String CHARSET = "ansi";
  38. private final Map userProperties = new HashMap();
  39. /** Create an RTF header */
  40. RtfHeader(RtfFile f, Writer w) throws IOException {
  41. super(f, w);
  42. new RtfFontTable(this, w);
  43. new RtfGenerator(this, w);
  44. // m_userProperties.put("jforVersion",JForVersionInfo.getLongVersionInfo());
  45. }
  46. /** Overridden to write our own data before our children's data */
  47. protected void writeRtfContent() throws IOException {
  48. writeControlWord(CHARSET);
  49. writeUserProperties();
  50. RtfColorTable.getInstance().writeColors(this);
  51. super.writeRtfContent();
  52. RtfTemplate.getInstance().writeTemplate(this);
  53. RtfStyleSheetTable.getInstance().writeStyleSheet(this);
  54. writeFootnoteProperties();
  55. }
  56. /** write user properties if any */
  57. private void writeUserProperties() throws IOException {
  58. if (userProperties.size() > 0) {
  59. writeGroupMark(true);
  60. writeStarControlWord("userprops");
  61. for (Object o : userProperties.entrySet()) {
  62. final Map.Entry entry = (Map.Entry) o;
  63. writeGroupMark(true);
  64. writeControlWord("propname");
  65. RtfStringConverter.getInstance().writeRtfString(writer,
  66. entry.getKey().toString());
  67. writeGroupMark(false);
  68. writeControlWord("proptype30");
  69. writeGroupMark(true);
  70. writeControlWord("staticval");
  71. RtfStringConverter.getInstance().writeRtfString(writer,
  72. entry.getValue().toString());
  73. writeGroupMark(false);
  74. }
  75. writeGroupMark(false);
  76. }
  77. }
  78. /** write directly to our Writer
  79. * TODO should check that this done at the right point, or even better, store
  80. * what is written here to render it in writeRtfContent. <-- it is for the color table
  81. */
  82. void write(String toWrite) throws IOException {
  83. writer.write(toWrite);
  84. }
  85. /** write to our Writer using an RtfStringConverter */
  86. void writeRtfString(String toWrite) throws IOException {
  87. RtfStringConverter.getInstance().writeRtfString(writer, toWrite);
  88. }
  89. /**
  90. *write properties for footnote handling
  91. */
  92. private void writeFootnoteProperties() throws IOException {
  93. newLine();
  94. writeControlWord("fet0"); //footnotes, not endnotes
  95. writeControlWord("ftnbj"); //place footnotes at the end of the
  96. //page (should be the default, but
  97. //Word 2000 thinks otherwise)
  98. }
  99. }