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.

RtfLeader.java 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. import java.io.IOException;
  20. import java.io.Writer;
  21. import java.util.Iterator;
  22. /**
  23. * Generates the leader in RTF.
  24. */
  25. public class RtfLeader extends RtfContainer {
  26. /*
  27. * Format : \tqr \style \tx## { \pard \format \tab }
  28. * ## represents the width \style represents the style (tldot, tlth, ...)
  29. * \format represents standard formats (color, fontsize, ...)
  30. *
  31. *
  32. * \pard \zwnj {\fsxx <format> } \zwnj
  33. *
  34. * <format>: \\ulcN Underline color. \\uld Dotted underline. \\uldash Dashed
  35. * underline. \\uldashd Dash-dotted underline. \\uldashdd Dash-dot-dotted
  36. * underline. \\uldb Double underline. \\ulhwave Heavy wave underline.
  37. * \\ulldash Long dashed underline. \\ulnone Stops all underlining. \\ulth
  38. * Thick underline. \\ulthd Thick dotted underline. \\ulthdash Thick dashed
  39. * underline. \\ulthdashd Thick dash-dotted underline. \\ulthdashdd Thick
  40. * dash-dot-dotted underline. \\ulthldash Thick long dashed underline.
  41. * \\ululdbwave Double wave underline.
  42. */
  43. private RtfAttributes attrs = null;
  44. /** Private attribute: tab style */
  45. public static final String LEADER_TABLEAD = "tablead";
  46. /** Private attribute: tab usage indicator */
  47. public static final String LEADER_USETAB = "tabuse";
  48. /** Private attribute: leader width */
  49. public static final String LEADER_WIDTH = "lwidth";
  50. // +++++++++++++++ Styles Underline ++++++++++++++++++++++
  51. /** Dotted underline */
  52. public static final String LEADER_DOTTED = "uld"; // dotted
  53. /** Dashed underline */
  54. public static final String LEADER_MIDDLEDOTTED = "uldash"; // dashed
  55. /** Heavy wave underline */
  56. public static final String LEADER_HYPHENS = "ulhwave"; // groove
  57. /** Dash-dot-dotted underline */
  58. public static final String LEADER_UNDERLINE = "ulthdashdd"; // ridge
  59. /** Double underline */
  60. public static final String LEADER_EQUAL = "uldb"; // double
  61. /** Thick underline */
  62. public static final String LEADER_THICK = "ulth"; // solid
  63. // +++++++++++++++ Styles Tabulator +++++++++++++++++++++++
  64. /** Leader dots */
  65. public static final String LEADER_TAB_DOTTED = "tldot"; // dotted
  66. /** Leader middle dots */
  67. public static final String LEADER_TAB_MIDDLEDOTTED = "tlmdot"; // dashed
  68. /** Leader hyphens */
  69. public static final String LEADER_TAB_HYPHENS = "tlhyph"; // groove
  70. /** Leader underline */
  71. public static final String LEADER_TAB_UNDERLINE = "tlul"; // ridge
  72. /** Leader equal sign */
  73. public static final String LEADER_TAB_EQUAL = "tleq"; // double
  74. /** Leader thick line */
  75. public static final String LEADER_TAB_THICK = "tlth"; // solid
  76. // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  77. /** Resets to default properties */
  78. public static final String LEADER_IGNORE_STYLE = "pard";
  79. /** Font size determines rule thickness */
  80. public static final String LEADER_RULE_THICKNESS = "fs"; // thickness = fontsize
  81. /** Expansion or compression of the space between characters in twips */
  82. public static final String LEADER_PATTERN_WIDTH = "expndtw";
  83. /** Zero-width break opportunity */
  84. public static final String LEADER_ZERO_WIDTH = "zwbo";
  85. /** Standard leader width */
  86. public static final int LEADER_STANDARD_WIDTH = 30;
  87. /** Move up 4 half-points */
  88. public static final String LEADER_UP = "up4";
  89. /** Negative expansion */
  90. public static final String LEADER_EXPAND = "expnd-2"; // negative value
  91. // for compression
  92. /** Tab */
  93. public static final String LEADER_TAB_VALUE = "tab";
  94. /** Right-aligned tab */
  95. public static final String LEADER_TAB_RIGHT = "tqr";
  96. /** Tab width */
  97. public static final String LEADER_TAB_WIDTH = "tx";
  98. RtfLeader(RtfContainer parent, Writer w, RtfAttributes attrs) throws IOException {
  99. super(parent, w);
  100. this.attrs = attrs;
  101. }
  102. /** {@inheritDoc} */
  103. protected void writeRtfContent() throws IOException {
  104. int thickness = LEADER_STANDARD_WIDTH;
  105. String tablead = null;
  106. String tabwidth = null;
  107. for (Iterator it = attrs.nameIterator(); it.hasNext();) {
  108. final String name = (String)it.next();
  109. if (attrs.isSet(name)) {
  110. if (name.equals(LEADER_TABLEAD)) {
  111. tablead = attrs.getValue(LEADER_TABLEAD).toString();
  112. } else if (name.equals(LEADER_WIDTH)) {
  113. tabwidth = attrs.getValue(LEADER_WIDTH).toString();
  114. }
  115. }
  116. }
  117. if (attrs.getValue(LEADER_RULE_THICKNESS) != null) {
  118. thickness += Integer.parseInt(attrs.getValue(LEADER_RULE_THICKNESS).toString())
  119. / 1000 * 2;
  120. attrs.unset(LEADER_RULE_THICKNESS);
  121. }
  122. //Remove private attributes
  123. attrs.unset(LEADER_WIDTH);
  124. attrs.unset(LEADER_TABLEAD);
  125. // If leader is 100% we use a tabulator, because its more
  126. // comfortable, specially for the table of content
  127. if (attrs.getValue(LEADER_USETAB) != null) {
  128. attrs.unset(LEADER_USETAB);
  129. writeControlWord(LEADER_TAB_RIGHT);
  130. if (tablead != null) {
  131. writeControlWord(tablead);
  132. }
  133. writeControlWord(LEADER_TAB_WIDTH + tabwidth);
  134. writeGroupMark(true);
  135. writeControlWord(LEADER_IGNORE_STYLE);
  136. writeAttributes(attrs, null);
  137. writeControlWord(LEADER_EXPAND);
  138. writeControlWord(LEADER_TAB_VALUE);
  139. writeGroupMark(false);
  140. }
  141. // Using white spaces with different underline formats
  142. else {
  143. writeControlWord(LEADER_IGNORE_STYLE);
  144. writeControlWord(LEADER_ZERO_WIDTH);
  145. writeGroupMark(true);
  146. writeControlWord(LEADER_RULE_THICKNESS + thickness);
  147. writeControlWord(LEADER_UP);
  148. super.writeAttributes(attrs, null);
  149. if (tablead != null) {
  150. writeControlWord(tablead);
  151. }
  152. // Calculation for the necessary amount of white spaces
  153. // Depending on font-size 15 -> 1cm = 7,5 spaces
  154. // TODO for rule-thickness this has to be done better
  155. for (double d = (Integer.parseInt(tabwidth) / 560) * 7.5; d >= 1; d--) {
  156. RtfStringConverter.getInstance().writeRtfString(writer, " ");
  157. }
  158. writeGroupMark(false);
  159. writeControlWord(LEADER_ZERO_WIDTH);
  160. }
  161. }
  162. /** {@inheritDoc} */
  163. public boolean isEmpty() {
  164. return false;
  165. }
  166. }