KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hdf > model > hdftypes > PAPFormattedDiskPage


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    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         
18 package org.apache.poi.hdf.model.hdftypes;
19
20 import org.apache.poi.util.LittleEndian;
21
22 /**
23  * Represents a PAP FKP. 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 public class PAPFormattedDiskPage extends FormattedDiskPage
39 {
40
41     /**
42      * Creates a PAPFormattedDiskPage from a 512 byte array
43      *
44      * @param fkp a 512 byte array.
45      */

46     public PAPFormattedDiskPage(byte[] fkp)
47     {
48         super(fkp);
49     }
50
51     /**
52      * Gets the papx for the pagraph at index in this fkp.
53      *
54      * @param index The index of the papx to get.
55      * @return a papx grpprl.
56      */

57     public byte[] getGrpprl(int index)
58     {
59         int papxOffset = 2 * LittleEndian.getUnsignedByte(_fkp, ((_crun + 1) * 4) + (index * 13));
60         int size = 2 * LittleEndian.getUnsignedByte(_fkp, papxOffset);
61         if(size == 0)
62         {
63             size = 2 * LittleEndian.getUnsignedByte(_fkp, ++papxOffset);
64         }
65         else
66         {
67             size--;
68         }
69
70         byte[] papx = new byte[size];
71         System.arraycopy(_fkp, ++papxOffset, papx, 0, size);
72         return papx;
73     }
74 }
75
Popular Tags