KickJava   Java API By Example, From Geeks To Geeks.

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


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 CHP 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 that represent a
27  * Paragraph's or Character run's text offset in the main stream. The ending
28  * offset is the next value in the array. For example, if an fkp has X number of
29  * Paragraph's stored in it then there are (x + 1) 4 byte ints in the beginning
30  * array. The 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 CHPFormattedDiskPage extends FormattedDiskPage
39 {
40
41
42     /**
43      * This constructs a CHPFormattedDiskPage from a raw fkp (512 byte array
44      * read from a Word file).
45      *
46      * @param fkp The 512 byte array to read data from
47      */

48     public CHPFormattedDiskPage(byte[] fkp)
49     {
50         super(fkp);
51     }
52
53     /**
54      * Gets the chpx for the character run at index in this fkp.
55      *
56      * @param index The index of the chpx to get.
57      * @return a chpx grpprl.
58      */

59     public byte[] getGrpprl(int index)
60     {
61         int chpxOffset = 2 * LittleEndian.getUnsignedByte(_fkp, ((_crun + 1) * 4) + index);
62
63         //optimization if offset == 0 use "Normal" style
64
if(chpxOffset == 0)
65         {
66             return new byte[0];
67
68         }
69
70         int size = LittleEndian.getUnsignedByte(_fkp, chpxOffset);
71
72         byte[] chpx = new byte[size];
73
74         System.arraycopy(_fkp, ++chpxOffset, chpx, 0, size);
75         return chpx;
76     }
77 }
78
Popular Tags