Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

RtfListStyleText.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. //Java
  26. import java.io.IOException;
  27. /**
  28. * Class to handle text list style.
  29. */
  30. public class RtfListStyleText extends RtfListStyle {
  31. private String text;
  32. /**
  33. * Constructs a RtfListStyleText object.
  34. * @param s Text to be displayed
  35. */
  36. public RtfListStyleText(String s) {
  37. text = s;
  38. }
  39. /**
  40. * Gets called before a RtfListItem has to be written.
  41. * @param item RtfListItem whose prefix has to be written
  42. * {@inheritDoc}
  43. * @throws IOException Thrown when an IO-problem occurs
  44. */
  45. public void writeListPrefix(RtfListItem item)
  46. throws IOException {
  47. // bulleted list
  48. item.writeControlWord("pnlvlblt");
  49. item.writeControlWord("ilvl0");
  50. item.writeOneAttribute(RtfListTable.LIST_NUMBER, item.getNumber());
  51. item.writeOneAttribute("pnindent",
  52. item.getParentList().attrib.getValue(RtfListTable.LIST_INDENT));
  53. item.writeControlWord("pnf1");
  54. item.writeGroupMark(true);
  55. //item.writeControlWord("pndec");
  56. item.writeOneAttribute(RtfListTable.LIST_FONT_TYPE, "2");
  57. item.writeControlWord("pntxtb");
  58. RtfStringConverter.getInstance().writeRtfString(item.writer, text);
  59. item.writeGroupMark(false);
  60. }
  61. /**
  62. * Gets called before a paragraph, which is contained by a RtfListItem has to be written.
  63. *
  64. * @param element RtfElement in whose context is to be written
  65. * {@inheritDoc}
  66. * @throws IOException Thrown when an IO-problem occurs
  67. */
  68. public void writeParagraphPrefix(RtfElement element)
  69. throws IOException {
  70. element.writeGroupMark(true);
  71. element.writeControlWord("pntext");
  72. element.writeGroupMark(false);
  73. }
  74. /**
  75. * Gets called when the list table has to be written.
  76. *
  77. * @param element RtfElement in whose context is to be written
  78. * {@inheritDoc}
  79. * @throws IOException Thrown when an IO-problem occurs
  80. */
  81. public void writeLevelGroup(RtfElement element)
  82. throws IOException {
  83. element.attrib.set(RtfListTable.LIST_NUMBER_TYPE, 23);
  84. element.writeGroupMark(true);
  85. String sCount;
  86. if (text.length() < 10) {
  87. sCount = "0" + String.valueOf(text.length());
  88. } else {
  89. sCount = String.valueOf(Integer.toHexString(text.length()));
  90. if (sCount.length() == 1) {
  91. sCount = "0" + sCount;
  92. }
  93. }
  94. element.writeOneAttributeNS(
  95. RtfListTable.LIST_TEXT_FORM, "\\'" + sCount
  96. + RtfStringConverter.getInstance().escape(text));
  97. element.writeGroupMark(false);
  98. element.writeGroupMark(true);
  99. element.writeOneAttributeNS(RtfListTable.LIST_NUM_POSITION, null);
  100. element.writeGroupMark(false);
  101. element.attrib.set(RtfListTable.LIST_FONT_TYPE, 2);
  102. }
  103. }