KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hdf > extractor > StyleDescription


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
19
20 package org.apache.poi.hdf.extractor;
21
22
23 /**
24  * Comment me
25  *
26  * @author Ryan Ackley
27  */

28
29 public class StyleDescription
30 {
31
32   private static int PARAGRAPH_STYLE = 1;
33   private static int CHARACTER_STYLE = 2;
34
35   int _baseStyleIndex;
36   int _styleTypeCode;
37   int _numUPX;
38   byte[] _papx;
39   byte[] _chpx;
40   PAP _pap;
41   CHP _chp;
42
43   public StyleDescription()
44   {
45       _pap = new PAP();
46       _chp = new CHP();
47   }
48   public StyleDescription(byte[] std, int baseLength, boolean word9)
49   {
50       int infoShort = Utils.convertBytesToShort(std, 2);
51       _styleTypeCode = (infoShort & 0xf);
52       _baseStyleIndex = (infoShort & 0xfff0) >> 4;
53
54       infoShort = Utils.convertBytesToShort(std, 4);
55       _numUPX = infoShort & 0xf;
56
57       //first byte(s) of variable length section of std is the length of the
58
//style name and aliases string
59
int nameLength = 0;
60       int multiplier = 1;
61       if(word9)
62       {
63           nameLength = Utils.convertBytesToShort(std, baseLength);
64           multiplier = 2;
65       }
66       else
67       {
68           nameLength = std[baseLength];
69       }
70       //2 bytes for length, length then null terminator.
71
int grupxStart = multiplier + ((nameLength + 1) * multiplier) + baseLength;
72
73       int offset = 0;
74       for(int x = 0; x < _numUPX; x++)
75       {
76           int upxSize = Utils.convertBytesToShort(std, grupxStart + offset);
77           if(_styleTypeCode == PARAGRAPH_STYLE)
78           {
79               if(x == 0)
80               {
81                   _papx = new byte[upxSize];
82                   System.arraycopy(std, grupxStart + offset + 2, _papx, 0, upxSize);
83               }
84               else if(x == 1)
85               {
86                   _chpx = new byte[upxSize];
87                   System.arraycopy(std, grupxStart + offset + 2, _chpx, 0, upxSize);
88               }
89           }
90           else if(_styleTypeCode == CHARACTER_STYLE && x == 0)
91           {
92               _chpx = new byte[upxSize];
93               System.arraycopy(std, grupxStart + offset + 2, _chpx, 0, upxSize);
94           }
95
96           if(upxSize % 2 == 1)
97           {
98               ++upxSize;
99           }
100           offset += 2 + upxSize;
101       }
102
103
104
105   }
106   public int getBaseStyle()
107   {
108       return _baseStyleIndex;
109   }
110   public byte[] getCHPX()
111   {
112       return _chpx;
113   }
114   public byte[] getPAPX()
115   {
116       return _papx;
117   }
118   public PAP getPAP()
119   {
120       return _pap;
121   }
122   public CHP getCHP()
123   {
124       return _chp;
125   }
126   public void setPAP(PAP pap)
127   {
128       _pap = pap;
129   }
130   public void setCHP(CHP chp)
131   {
132       _chp = chp;
133   }
134 }
135
Popular Tags