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.

LVLFAbstractType.java 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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.model.types;
  16. import java.util.Arrays;
  17. import org.apache.poi.hwpf.model.Grfhic;
  18. import org.apache.poi.util.BitField;
  19. import org.apache.poi.util.Internal;
  20. import org.apache.poi.util.LittleEndian;
  21. /**
  22. * The LVLF structure contains formatting properties for an individual level in a list.
  23. */
  24. @Internal
  25. public abstract class LVLFAbstractType
  26. {
  27. protected int field_1_iStartAt;
  28. protected byte field_2_nfc;
  29. protected byte field_3_info;
  30. /**/private static final BitField jc = new BitField(0x03);
  31. /**/private static final BitField fLegal = new BitField(0x04);
  32. /**/private static final BitField fNoRestart = new BitField(0x08);
  33. /**/private static final BitField fIndentSav = new BitField(0x10);
  34. /**/private static final BitField fConverted = new BitField(0x20);
  35. /**/private static final BitField unused1 = new BitField(0x40);
  36. /**/private static final BitField fTentative = new BitField(0x80);
  37. protected byte[] field_4_rgbxchNums;
  38. protected byte field_5_ixchFollow;
  39. protected int field_6_dxaIndentSav;
  40. protected int field_7_unused2;
  41. protected short field_8_cbGrpprlChpx;
  42. protected short field_9_cbGrpprlPapx;
  43. protected short field_10_ilvlRestartLim;
  44. protected Grfhic field_11_grfhic;
  45. protected LVLFAbstractType()
  46. {
  47. this.field_4_rgbxchNums = new byte[9];
  48. this.field_11_grfhic = new Grfhic();
  49. }
  50. protected void fillFields( byte[] data, int offset )
  51. {
  52. field_1_iStartAt = LittleEndian.getInt( data, 0x0 + offset );
  53. field_2_nfc = data[ 0x4 + offset ];
  54. field_3_info = data[ 0x5 + offset ];
  55. field_4_rgbxchNums = Arrays.copyOfRange( data, 0x6 + offset, 0x6 + offset + 9 );
  56. field_5_ixchFollow = data[ 0xf + offset ];
  57. field_6_dxaIndentSav = LittleEndian.getInt( data, 0x10 + offset );
  58. field_7_unused2 = LittleEndian.getInt( data, 0x14 + offset );
  59. field_8_cbGrpprlChpx = LittleEndian.getUByte( data, 0x18 + offset );
  60. field_9_cbGrpprlPapx = LittleEndian.getUByte( data, 0x19 + offset );
  61. field_10_ilvlRestartLim = LittleEndian.getUByte( data, 0x1a + offset );
  62. field_11_grfhic = new Grfhic( data, 0x1b + offset );
  63. }
  64. public void serialize( byte[] data, int offset )
  65. {
  66. LittleEndian.putInt( data, 0x0 + offset, field_1_iStartAt );
  67. data[ 0x4 + offset ] = field_2_nfc;
  68. data[ 0x5 + offset ] = field_3_info;
  69. System.arraycopy( field_4_rgbxchNums, 0, data, 0x6 + offset, field_4_rgbxchNums.length );
  70. data[ 0xf + offset ] = field_5_ixchFollow;
  71. LittleEndian.putInt( data, 0x10 + offset, field_6_dxaIndentSav );
  72. LittleEndian.putInt( data, 0x14 + offset, field_7_unused2 );
  73. LittleEndian.putUByte( data, 0x18 + offset, field_8_cbGrpprlChpx );
  74. LittleEndian.putUByte( data, 0x19 + offset, field_9_cbGrpprlPapx );
  75. LittleEndian.putUByte( data, 0x1a + offset, field_10_ilvlRestartLim );
  76. field_11_grfhic.serialize( data, 0x1b + offset );
  77. }
  78. public byte[] serialize()
  79. {
  80. final byte[] result = new byte[ getSize() ];
  81. serialize( result, 0 );
  82. return result;
  83. }
  84. /**
  85. * Size of record
  86. */
  87. public static int getSize()
  88. {
  89. return 0 + 4 + 1 + 1 + 9 + 1 + 4 + 4 + 1 + 1 + 1 + 1;
  90. }
  91. @Override
  92. public boolean equals( Object obj )
  93. {
  94. if ( this == obj )
  95. return true;
  96. if ( obj == null )
  97. return false;
  98. if ( getClass() != obj.getClass() )
  99. return false;
  100. LVLFAbstractType other = (LVLFAbstractType) obj;
  101. if ( field_1_iStartAt != other.field_1_iStartAt )
  102. return false;
  103. if ( field_2_nfc != other.field_2_nfc )
  104. return false;
  105. if ( field_3_info != other.field_3_info )
  106. return false;
  107. if ( !Arrays.equals( field_4_rgbxchNums, other.field_4_rgbxchNums ) )
  108. return false;
  109. if ( field_5_ixchFollow != other.field_5_ixchFollow )
  110. return false;
  111. if ( field_6_dxaIndentSav != other.field_6_dxaIndentSav )
  112. return false;
  113. if ( field_7_unused2 != other.field_7_unused2 )
  114. return false;
  115. if ( field_8_cbGrpprlChpx != other.field_8_cbGrpprlChpx )
  116. return false;
  117. if ( field_9_cbGrpprlPapx != other.field_9_cbGrpprlPapx )
  118. return false;
  119. if ( field_10_ilvlRestartLim != other.field_10_ilvlRestartLim )
  120. return false;
  121. if ( field_11_grfhic == null )
  122. {
  123. if ( other.field_11_grfhic != null )
  124. return false;
  125. }
  126. else if ( !field_11_grfhic.equals( other.field_11_grfhic ) )
  127. return false;
  128. return true;
  129. }
  130. @Override
  131. public int hashCode() {
  132. return Arrays.deepHashCode(new Object[]{field_1_iStartAt, field_2_nfc, field_3_info, field_4_rgbxchNums,
  133. field_5_ixchFollow, field_6_dxaIndentSav, field_7_unused2, field_8_cbGrpprlChpx, field_9_cbGrpprlPapx,
  134. field_10_ilvlRestartLim, field_11_grfhic});
  135. }
  136. public String toString()
  137. {
  138. StringBuilder builder = new StringBuilder();
  139. builder.append("[LVLF]\n");
  140. builder.append(" .iStartAt = ");
  141. builder.append(" (").append(getIStartAt()).append(" )\n");
  142. builder.append(" .nfc = ");
  143. builder.append(" (").append(getNfc()).append(" )\n");
  144. builder.append(" .info = ");
  145. builder.append(" (").append(getInfo()).append(" )\n");
  146. builder.append(" .jc = ").append(getJc()).append('\n');
  147. builder.append(" .fLegal = ").append(isFLegal()).append('\n');
  148. builder.append(" .fNoRestart = ").append(isFNoRestart()).append('\n');
  149. builder.append(" .fIndentSav = ").append(isFIndentSav()).append('\n');
  150. builder.append(" .fConverted = ").append(isFConverted()).append('\n');
  151. builder.append(" .unused1 = ").append(isUnused1()).append('\n');
  152. builder.append(" .fTentative = ").append(isFTentative()).append('\n');
  153. builder.append(" .rgbxchNums = ");
  154. builder.append(" (").append(Arrays.toString(getRgbxchNums())).append(" )\n");
  155. builder.append(" .ixchFollow = ");
  156. builder.append(" (").append(getIxchFollow()).append(" )\n");
  157. builder.append(" .dxaIndentSav = ");
  158. builder.append(" (").append(getDxaIndentSav()).append(" )\n");
  159. builder.append(" .unused2 = ");
  160. builder.append(" (").append(getUnused2()).append(" )\n");
  161. builder.append(" .cbGrpprlChpx = ");
  162. builder.append(" (").append(getCbGrpprlChpx()).append(" )\n");
  163. builder.append(" .cbGrpprlPapx = ");
  164. builder.append(" (").append(getCbGrpprlPapx()).append(" )\n");
  165. builder.append(" .ilvlRestartLim = ");
  166. builder.append(" (").append(getIlvlRestartLim()).append(" )\n");
  167. builder.append(" .grfhic = ");
  168. builder.append(" (").append(getGrfhic()).append(" )\n");
  169. builder.append("[/LVLF]\n");
  170. return builder.toString();
  171. }
  172. /**
  173. * A signed integer that specifies the beginning number for the number sequence belonging to this level. This value MUST be less than or equal to 0x7FFF and MUST be greater than or equal to zero. If this level does not have a number sequence (see nfc), this MUST be ignored.
  174. */
  175. @Internal
  176. public int getIStartAt()
  177. {
  178. return field_1_iStartAt;
  179. }
  180. /**
  181. * A signed integer that specifies the beginning number for the number sequence belonging to this level. This value MUST be less than or equal to 0x7FFF and MUST be greater than or equal to zero. If this level does not have a number sequence (see nfc), this MUST be ignored.
  182. */
  183. @Internal
  184. public void setIStartAt( int field_1_iStartAt )
  185. {
  186. this.field_1_iStartAt = field_1_iStartAt;
  187. }
  188. /**
  189. * An MSONFC, as specified in [MS-OSHARED] section 2.2.1.3, that specifies the format of the level numbers that replace the placeholders for this level in the xst fields of the LVLs in this list. This value MUST not be equal to 0x08, 0x09, 0x0F, or 0x13. If this is equal to 0xFF or 0x17, this level does not have a number sequence and therefore has no number formatting. If this is equal to 0x17, the level uses bullets.
  190. */
  191. @Internal
  192. public byte getNfc()
  193. {
  194. return field_2_nfc;
  195. }
  196. /**
  197. * An MSONFC, as specified in [MS-OSHARED] section 2.2.1.3, that specifies the format of the level numbers that replace the placeholders for this level in the xst fields of the LVLs in this list. This value MUST not be equal to 0x08, 0x09, 0x0F, or 0x13. If this is equal to 0xFF or 0x17, this level does not have a number sequence and therefore has no number formatting. If this is equal to 0x17, the level uses bullets.
  198. */
  199. @Internal
  200. public void setNfc( byte field_2_nfc )
  201. {
  202. this.field_2_nfc = field_2_nfc;
  203. }
  204. /**
  205. * Get the info field for the LVLF record.
  206. */
  207. @Internal
  208. public byte getInfo()
  209. {
  210. return field_3_info;
  211. }
  212. /**
  213. * Set the info field for the LVLF record.
  214. */
  215. @Internal
  216. public void setInfo( byte field_3_info )
  217. {
  218. this.field_3_info = field_3_info;
  219. }
  220. /**
  221. * An array of 8-bit integers. Each integer specifies a one-based character offset to a level placeholder in the xst.rgtchar of the LVL that contains this LVLF. This array is zero-terminated, unless it is full. The count of elements in this array, before to the first terminating zero, MUST be less than or equal to the one-based level of the list to which this LVL corresponds. The integers in this array, before the first terminating zero, MUST be in ascending order, and MUST be unique.
  222. */
  223. @Internal
  224. public byte[] getRgbxchNums()
  225. {
  226. return field_4_rgbxchNums;
  227. }
  228. /**
  229. * An array of 8-bit integers. Each integer specifies a one-based character offset to a level placeholder in the xst.rgtchar of the LVL that contains this LVLF. This array is zero-terminated, unless it is full. The count of elements in this array, before to the first terminating zero, MUST be less than or equal to the one-based level of the list to which this LVL corresponds. The integers in this array, before the first terminating zero, MUST be in ascending order, and MUST be unique.
  230. */
  231. @Internal
  232. public void setRgbxchNums( byte[] field_4_rgbxchNums )
  233. {
  234. this.field_4_rgbxchNums = field_4_rgbxchNums;
  235. }
  236. /**
  237. * An unsigned integer that specifies the character that follows the number text.
  238. */
  239. @Internal
  240. public byte getIxchFollow()
  241. {
  242. return field_5_ixchFollow;
  243. }
  244. /**
  245. * An unsigned integer that specifies the character that follows the number text.
  246. */
  247. @Internal
  248. public void setIxchFollow( byte field_5_ixchFollow )
  249. {
  250. this.field_5_ixchFollow = field_5_ixchFollow;
  251. }
  252. /**
  253. * If fIndentSav is nonzero, this is a signed integer that specifies the size, in twips, of the indent that needs to be removed when the numbering is removed. This MUST be less than or equal to 0x00007BC0 or greater than or equal to 0xFFFF8440. If fIndentSav is zero, this MUST be ignored.
  254. */
  255. @Internal
  256. public int getDxaIndentSav()
  257. {
  258. return field_6_dxaIndentSav;
  259. }
  260. /**
  261. * If fIndentSav is nonzero, this is a signed integer that specifies the size, in twips, of the indent that needs to be removed when the numbering is removed. This MUST be less than or equal to 0x00007BC0 or greater than or equal to 0xFFFF8440. If fIndentSav is zero, this MUST be ignored.
  262. */
  263. @Internal
  264. public void setDxaIndentSav( int field_6_dxaIndentSav )
  265. {
  266. this.field_6_dxaIndentSav = field_6_dxaIndentSav;
  267. }
  268. /**
  269. * This field MUST be ignored.
  270. */
  271. @Internal
  272. public int getUnused2()
  273. {
  274. return field_7_unused2;
  275. }
  276. /**
  277. * This field MUST be ignored.
  278. */
  279. @Internal
  280. public void setUnused2( int field_7_unused2 )
  281. {
  282. this.field_7_unused2 = field_7_unused2;
  283. }
  284. /**
  285. * An unsigned integer that specifies the size, in bytes, of the grpprlChpx in the LVL that contains this LVLF.
  286. */
  287. @Internal
  288. public short getCbGrpprlChpx()
  289. {
  290. return field_8_cbGrpprlChpx;
  291. }
  292. /**
  293. * An unsigned integer that specifies the size, in bytes, of the grpprlChpx in the LVL that contains this LVLF.
  294. */
  295. @Internal
  296. public void setCbGrpprlChpx( short field_8_cbGrpprlChpx )
  297. {
  298. this.field_8_cbGrpprlChpx = field_8_cbGrpprlChpx;
  299. }
  300. /**
  301. * An unsigned integer that specifies the size, in bytes, of the grpprlPapx in the LVL that contains this LVLF.
  302. */
  303. @Internal
  304. public short getCbGrpprlPapx()
  305. {
  306. return field_9_cbGrpprlPapx;
  307. }
  308. /**
  309. * An unsigned integer that specifies the size, in bytes, of the grpprlPapx in the LVL that contains this LVLF.
  310. */
  311. @Internal
  312. public void setCbGrpprlPapx( short field_9_cbGrpprlPapx )
  313. {
  314. this.field_9_cbGrpprlPapx = field_9_cbGrpprlPapx;
  315. }
  316. /**
  317. * An unsigned integer that specifies the first (most-significant) zero-based level after which the number sequence of this level does not restart. The number sequence of this level does restart after any level that is more significant than the specified level. This MUST be less than or equal to the zero-based level of the list to which this LVLF corresponds. If fNoRestart is zero, this MUST be ignored. If this level does not have a number sequence (see nfc), this MUST be ignored.
  318. */
  319. @Internal
  320. public short getIlvlRestartLim()
  321. {
  322. return field_10_ilvlRestartLim;
  323. }
  324. /**
  325. * An unsigned integer that specifies the first (most-significant) zero-based level after which the number sequence of this level does not restart. The number sequence of this level does restart after any level that is more significant than the specified level. This MUST be less than or equal to the zero-based level of the list to which this LVLF corresponds. If fNoRestart is zero, this MUST be ignored. If this level does not have a number sequence (see nfc), this MUST be ignored.
  326. */
  327. @Internal
  328. public void setIlvlRestartLim( short field_10_ilvlRestartLim )
  329. {
  330. this.field_10_ilvlRestartLim = field_10_ilvlRestartLim;
  331. }
  332. /**
  333. * A grfhic that specifies the HTML incompatibilities of the level..
  334. */
  335. @Internal
  336. public Grfhic getGrfhic()
  337. {
  338. return field_11_grfhic;
  339. }
  340. /**
  341. * A grfhic that specifies the HTML incompatibilities of the level..
  342. */
  343. @Internal
  344. public void setGrfhic( Grfhic field_11_grfhic )
  345. {
  346. this.field_11_grfhic = field_11_grfhic;
  347. }
  348. /**
  349. * Sets the jc field value.
  350. * An unsigned integer that specifies the justification of this level
  351. */
  352. @Internal
  353. public void setJc( byte value )
  354. {
  355. field_3_info = (byte)jc.setValue(field_3_info, value);
  356. }
  357. /**
  358. * An unsigned integer that specifies the justification of this level
  359. * @return the jc field value.
  360. */
  361. @Internal
  362. public byte getJc()
  363. {
  364. return ( byte )jc.getValue(field_3_info);
  365. }
  366. /**
  367. * Sets the fLegal field value.
  368. * A bit that specifies whether this level overrides the nfc of all inherited level numbers. If the original nfc of a level number is msonfcArabicLZ, it is preserved. Otherwise, the nfc of the level number is overridden by msonfcArabic.
  369. */
  370. @Internal
  371. public void setFLegal( boolean value )
  372. {
  373. field_3_info = (byte)fLegal.setBoolean(field_3_info, value);
  374. }
  375. /**
  376. * A bit that specifies whether this level overrides the nfc of all inherited level numbers. If the original nfc of a level number is msonfcArabicLZ, it is preserved. Otherwise, the nfc of the level number is overridden by msonfcArabic.
  377. * @return the fLegal field value.
  378. */
  379. @Internal
  380. public boolean isFLegal()
  381. {
  382. return fLegal.isSet(field_3_info);
  383. }
  384. /**
  385. * Sets the fNoRestart field value.
  386. * A bit that specifies whether the number sequence of the level does not restart after a level is encountered that is more significant than the level to which this LVLF corresponds
  387. */
  388. @Internal
  389. public void setFNoRestart( boolean value )
  390. {
  391. field_3_info = (byte)fNoRestart.setBoolean(field_3_info, value);
  392. }
  393. /**
  394. * A bit that specifies whether the number sequence of the level does not restart after a level is encountered that is more significant than the level to which this LVLF corresponds
  395. * @return the fNoRestart field value.
  396. */
  397. @Internal
  398. public boolean isFNoRestart()
  399. {
  400. return fNoRestart.isSet(field_3_info);
  401. }
  402. /**
  403. * Sets the fIndentSav field value.
  404. * A bit that specifies whether the level indented the text it was applied to and that the indent needs to be removed when numbering is removed. The indent to be removed is stored in dxaIndentSav
  405. */
  406. @Internal
  407. public void setFIndentSav( boolean value )
  408. {
  409. field_3_info = (byte)fIndentSav.setBoolean(field_3_info, value);
  410. }
  411. /**
  412. * A bit that specifies whether the level indented the text it was applied to and that the indent needs to be removed when numbering is removed. The indent to be removed is stored in dxaIndentSav
  413. * @return the fIndentSav field value.
  414. */
  415. @Internal
  416. public boolean isFIndentSav()
  417. {
  418. return fIndentSav.isSet(field_3_info);
  419. }
  420. /**
  421. * Sets the fConverted field value.
  422. * A bit that specifies whether the nfc of this LVLF structure was previously a temporary value used for bidirectional compatibility that was converted into a standard MSONFC
  423. */
  424. @Internal
  425. public void setFConverted( boolean value )
  426. {
  427. field_3_info = (byte)fConverted.setBoolean(field_3_info, value);
  428. }
  429. /**
  430. * A bit that specifies whether the nfc of this LVLF structure was previously a temporary value used for bidirectional compatibility that was converted into a standard MSONFC
  431. * @return the fConverted field value.
  432. */
  433. @Internal
  434. public boolean isFConverted()
  435. {
  436. return fConverted.isSet(field_3_info);
  437. }
  438. /**
  439. * Sets the unused1 field value.
  440. * This bit MUST be ignored
  441. */
  442. @Internal
  443. public void setUnused1( boolean value )
  444. {
  445. field_3_info = (byte)unused1.setBoolean(field_3_info, value);
  446. }
  447. /**
  448. * This bit MUST be ignored
  449. * @return the unused1 field value.
  450. * @deprecated This field should not be used according to specification
  451. */
  452. @Internal
  453. @Deprecated
  454. public boolean isUnused1()
  455. {
  456. return unused1.isSet(field_3_info);
  457. }
  458. /**
  459. * Sets the fTentative field value.
  460. * A bit that specifies whether the format of the level is tentative
  461. */
  462. @Internal
  463. public void setFTentative( boolean value )
  464. {
  465. field_3_info = (byte)fTentative.setBoolean(field_3_info, value);
  466. }
  467. /**
  468. * A bit that specifies whether the format of the level is tentative
  469. * @return the fTentative field value.
  470. */
  471. @Internal
  472. public boolean isFTentative()
  473. {
  474. return fTentative.isSet(field_3_info);
  475. }
  476. } // END OF CLASS