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.

FormattedDiskPage.java 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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;
  16. import org.apache.poi.util.Internal;
  17. import org.apache.poi.util.LittleEndian;
  18. /**
  19. * Represents an FKP data structure. This data structure is used to store the
  20. * grpprls of the paragraph and character properties of the document. A grpprl
  21. * is a list of sprms(decompression operations) to perform on a parent style.
  22. *
  23. * The style properties for paragraph and character runs
  24. * are stored in fkps. There are PAP fkps for paragraph properties and CHP fkps
  25. * for character run properties. The first part of the fkp for both CHP and PAP
  26. * fkps consists of an array of 4 byte int offsets in the main stream for that
  27. * Paragraph's or Character run's text. The ending offset is the next
  28. * value in the array. For example, if an fkp has X number of Paragraph's
  29. * stored in it then there are (x + 1) 4 byte ints in the beginning array. The
  30. * number X is determined by the last byte in a 512 byte fkp.
  31. *
  32. * CHP and PAP fkps also store the compressed styles(grpprl) that correspond to
  33. * the offsets on the front of the fkp. The offset of the grpprls is determined
  34. * differently for CHP fkps and PAP fkps.
  35. *
  36. * @author Ryan Ackley
  37. */
  38. @Internal
  39. public abstract class FormattedDiskPage {
  40. protected byte[] _fkp;
  41. protected int _crun;
  42. protected int _offset;
  43. public FormattedDiskPage() {
  44. }
  45. /**
  46. * Uses a 512-byte array to create a FKP
  47. */
  48. public FormattedDiskPage(byte[] documentStream, int offset) {
  49. _crun = LittleEndian.getUByte(documentStream, offset + 511);
  50. _fkp = documentStream;
  51. _offset = offset;
  52. }
  53. /**
  54. * Used to get a text offset corresponding to a grpprl in this fkp.
  55. * @param index The index of the property in this FKP
  56. * @return an int representing an offset in the "WordDocument" stream
  57. */
  58. protected int getStart(int index)
  59. {
  60. return LittleEndian.getInt(_fkp, _offset + (index * 4));
  61. }
  62. /**
  63. * Used to get the end of the text corresponding to a grpprl in this fkp.
  64. * @param index The index of the property in this fkp.
  65. * @return an int representing an offset in the "WordDocument" stream
  66. */
  67. protected int getEnd(int index)
  68. {
  69. return LittleEndian.getInt(_fkp, _offset + ((index + 1) * 4));
  70. }
  71. /**
  72. * Used to get the total number of grrprl's stored int this FKP
  73. * @return The number of grpprls in this FKP
  74. */
  75. public int size()
  76. {
  77. return _crun;
  78. }
  79. protected abstract byte[] getGrpprl(int index);
  80. }