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.

Section.java 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hwpf.usermodel;
  16. import org.apache.poi.common.Duplicatable;
  17. import org.apache.poi.hwpf.HWPFOldDocument;
  18. import org.apache.poi.hwpf.model.SEPX;
  19. import org.apache.poi.util.Removal;
  20. public final class Section extends Range implements Duplicatable {
  21. private final SectionProperties _props;
  22. public Section(Section other) {
  23. super(other);
  24. _props = other._props.copy();
  25. }
  26. public Section( SEPX sepx, Range parent ) {
  27. super( Math.max( parent._start, sepx.getStart() ), Math.min(parent._end, sepx.getEnd() ), parent );
  28. // XXX: temporary workaround for old Word95 document
  29. if ( parent.getDocument() instanceof HWPFOldDocument )
  30. _props = new SectionProperties();
  31. else
  32. _props = sepx.getSectionProperties();
  33. }
  34. @Override
  35. @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"})
  36. @Deprecated
  37. @Removal(version = "5.0.0")
  38. public Section clone() {
  39. return copy();
  40. }
  41. @Override
  42. public Section copy() {
  43. return new Section(this);
  44. }
  45. /**
  46. * @return distance to be maintained between columns, in twips. Used when
  47. * {@link #isColumnsEvenlySpaced()} == true
  48. */
  49. public int getDistanceBetweenColumns()
  50. {
  51. return _props.getDxaColumns();
  52. }
  53. public int getMarginBottom()
  54. {
  55. return _props.getDyaBottom();
  56. }
  57. public int getMarginLeft()
  58. {
  59. return _props.getDxaLeft();
  60. }
  61. public int getMarginRight()
  62. {
  63. return _props.getDxaRight();
  64. }
  65. public int getMarginTop()
  66. {
  67. return _props.getDyaTop();
  68. }
  69. public int getNumColumns()
  70. {
  71. return _props.getCcolM1() + 1;
  72. }
  73. /**
  74. * @return page height (in twips) in current section. Default value is 15840
  75. * twips
  76. */
  77. public int getPageHeight()
  78. {
  79. return _props.getYaPage();
  80. }
  81. /**
  82. * @return page width (in twips) in current section. Default value is 12240
  83. * twips
  84. */
  85. public int getPageWidth()
  86. {
  87. return _props.getXaPage();
  88. }
  89. /**
  90. * Set the height of the bottom margin in twips. In the AbstractWordUtils class, a constant
  91. * is defined that indicates how many twips there are per inch and it can be used in setting
  92. * the margins width a little like this;
  93. *
  94. * section.setMarginBottom( (int) 1.5 * AbstractWordUtils.TWIPS_PER_INCH );
  95. *
  96. * @param marginWidth A primitive int whose value will indciate how high the margin should
  97. * be - in twips.
  98. */
  99. public void setMarginBottom(int marginWidth)
  100. {
  101. this._props.setDyaBottom(marginWidth);
  102. }
  103. /**
  104. * Set the width of the left hand margin in twips. In the AbstractWordUtils class, a constant
  105. * is defined that indicates how many twips there are per inch and it can be used in setting
  106. * the margins width a little like this;
  107. *
  108. * section.setMarginLeft( (int) 1.5 * AbstractWordUtils.TWIPS_PER_INCH );
  109. *
  110. * @param marginWidth A primitive int whose value will indciate how high the margin should
  111. * be - in twips.
  112. */
  113. public void setMarginLeft(int marginWidth)
  114. {
  115. this._props.setDxaLeft(marginWidth);
  116. }
  117. /**
  118. * Set the width of the right hand margin in twips. In the AbstractWordUtils class, a constant
  119. * is defined that indicates how many twips there are per inch and it can be used in setting
  120. * the margins width a little like this;
  121. *
  122. * section.setMarginRight( (int) 1.5 * AbstractWordUtils.TWIPS_PER_INCH );
  123. *
  124. * @param marginWidth A primitive int whose value will indciate how high the margin should
  125. * be - in twips.
  126. */
  127. public void setMarginRight(int marginWidth)
  128. {
  129. this._props.setDxaRight(marginWidth);
  130. }
  131. /**
  132. * Set the height of the top margin in twips. In the AbstractWordUtils class, a constant
  133. * is defined that indicates how many twips there are per inch and it can be used in setting
  134. * the margins width a little like this;
  135. *
  136. * section.setMarginTop( (int) 1.5 * AbstractWordUtils.TWIPS_PER_INCH );
  137. *
  138. * @param marginWidth A primitive int whose value will indciate how high the margin should
  139. * be - in twips.
  140. */
  141. public void setMarginTop(int marginWidth)
  142. {
  143. this._props.setDyaTop(marginWidth);
  144. }
  145. public boolean isColumnsEvenlySpaced()
  146. {
  147. return _props.getFEvenlySpaced();
  148. }
  149. /**
  150. * Get the footnote restart qualifier
  151. *
  152. * <dl>
  153. * <dt>{@code 0x00}</dt><dd>If the numbering is continuous throughout the entire document</dd>
  154. * <dt>{@code 0x01}</dt><dd>If the numbering restarts at the beginning of this section</dd>
  155. * <dt>{@code 0x02}</dt><dd>If the numbering restarts on every page</dd>
  156. * </dl>
  157. *
  158. * @return an Rnc, as decribed above, specifying when and where footnote numbering restarts
  159. */
  160. public short getFootnoteRestartQualifier() {
  161. return _props.getRncFtn();
  162. }
  163. /**
  164. * @return an offset to be added to footnote numbers
  165. */
  166. public int getFootnoteNumberingOffset() {
  167. return _props.getNFtn();
  168. }
  169. /**
  170. * Get the numbering format of embedded footnotes
  171. *
  172. * <p>The full list of possible return values is given in [MS-OSHARED], v20140428, 2.2.1.3</p>
  173. *
  174. * @return an Nfc specifying the numbering format for footnotes
  175. */
  176. public int getFootnoteNumberingFormat() {
  177. return _props.getNfcFtnRef();
  178. }
  179. /**
  180. * Get the endnote restart qualifier
  181. *
  182. * <dl>
  183. * <dt>{@code 0x00}</dt><dd>If the numbering is continuous throughout the entire document</dd>
  184. * <dt>{@code 0x01}</dt><dd>If the numbering restarts at the beginning of this section</dd>
  185. * <dt>{@code 0x02}</dt><dd>If the numbering restarts on every page</dd>
  186. * </dl>
  187. *
  188. * @return an Rnc, as decribed above, specifying when and where endnote numbering restarts
  189. */
  190. public short getEndnoteRestartQualifier() {
  191. return _props.getRncEdn();
  192. }
  193. /**
  194. * @return an offset to be added to endnote numbers
  195. */
  196. public int getEndnoteNumberingOffset() {
  197. return _props.getNEdn();
  198. }
  199. /**
  200. * Get the numbering format of embedded endnotes
  201. *
  202. * <p>The full list of possible return values is given in [MS-OSHARED], v20140428, 2.2.1.3</p>
  203. *
  204. * @return an Nfc specifying the numbering format for endnotes
  205. */
  206. public int getEndnoteNumberingFormat() {
  207. return _props.getNfcEdnRef();
  208. }
  209. @Override
  210. public String toString()
  211. {
  212. return "Section [" + getStartOffset() + "; " + getEndOffset() + ")";
  213. }
  214. public int type()
  215. {
  216. return TYPE_SECTION;
  217. }
  218. }