01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: 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:
18: package org.apache.poi.hwpf.model;
19:
20: import org.apache.poi.util.LittleEndian;
21:
22: /**
23: * Represents an FKP data structure. This data structure is used to store the
24: * grpprls of the paragraph and character properties of the document. A grpprl
25: * is a list of sprms(decompression operations) to perform on a parent style.
26: *
27: * The style properties for paragraph and character runs
28: * are stored in fkps. There are PAP fkps for paragraph properties and CHP fkps
29: * for character run properties. The first part of the fkp for both CHP and PAP
30: * fkps consists of an array of 4 byte int offsets in the main stream for that
31: * Paragraph's or Character run's text. The ending offset is the next
32: * value in the array. For example, if an fkp has X number of Paragraph's
33: * stored in it then there are (x + 1) 4 byte ints in the beginning array. The
34: * number X is determined by the last byte in a 512 byte fkp.
35: *
36: * CHP and PAP fkps also store the compressed styles(grpprl) that correspond to
37: * the offsets on the front of the fkp. The offset of the grpprls is determined
38: * differently for CHP fkps and PAP fkps.
39: *
40: * @author Ryan Ackley
41: */
42: public abstract class FormattedDiskPage {
43: protected byte[] _fkp;
44: protected int _crun;
45: protected int _offset;
46:
47: public FormattedDiskPage() {
48:
49: }
50:
51: /**
52: * Uses a 512-byte array to create a FKP
53: */
54: public FormattedDiskPage(byte[] documentStream, int offset) {
55: _crun = LittleEndian.getUnsignedByte(documentStream,
56: offset + 511);
57: _fkp = documentStream;
58: _offset = offset;
59: }
60:
61: /**
62: * Used to get a text offset corresponding to a grpprl in this fkp.
63: * @param index The index of the property in this FKP
64: * @return an int representing an offset in the "WordDocument" stream
65: */
66: protected int getStart(int index) {
67: return LittleEndian.getInt(_fkp, _offset + (index * 4));
68: }
69:
70: /**
71: * Used to get the end of the text corresponding to a grpprl in this fkp.
72: * @param index The index of the property in this fkp.
73: * @return an int representing an offset in the "WordDocument" stream
74: */
75: protected int getEnd(int index) {
76: return LittleEndian.getInt(_fkp, _offset + ((index + 1) * 4));
77: }
78:
79: /**
80: * Used to get the total number of grrprl's stored int this FKP
81: * @return The number of grpprls in this FKP
82: */
83: public int size() {
84: return _crun;
85: }
86:
87: protected abstract byte[] getGrpprl(int index);
88: }
|