KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hwpf > model > PAPX


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.hwpf.model;
21
22
23 import org.apache.poi.util.LittleEndian;
24
25 import org.apache.poi.hwpf.usermodel.ParagraphProperties;
26 import org.apache.poi.hwpf.sprm.ParagraphSprmUncompressor;
27 import org.apache.poi.hwpf.sprm.SprmBuffer;
28 import org.apache.poi.hwpf.sprm.SprmOperation;
29
30 /**
31  * Comment me
32  *
33  * @author Ryan Ackley
34  */

35
36 public class PAPX extends PropertyNode
37 {
38
39   private ParagraphHeight _phe;
40   private int _hugeGrpprlOffset = -1;
41
42   public PAPX(int fcStart, int fcEnd, byte[] papx, ParagraphHeight phe, byte[] dataStream)
43   {
44     super(fcStart, fcEnd, new SprmBuffer(papx));
45     _phe = phe;
46     SprmBuffer buf = findHuge(new SprmBuffer(papx), dataStream);
47     if(buf != null)
48       _buf = buf;
49   }
50
51   public PAPX(int fcStart, int fcEnd, SprmBuffer buf, byte[] dataStream)
52   {
53     super(fcStart, fcEnd, buf);
54     _phe = new ParagraphHeight();
55     buf = findHuge(buf, dataStream);
56     if(buf != null)
57       _buf = buf;
58   }
59
60   private SprmBuffer findHuge(SprmBuffer buf, byte[] datastream)
61   {
62     byte[] grpprl = buf.toByteArray();
63     if(grpprl.length==8 && datastream!=null) // then check for sprmPHugePapx
64
{
65       SprmOperation sprm = new SprmOperation(grpprl, 2);
66       if ((sprm.getOperation()==0x45 || sprm.getOperation()==0x46)
67           && sprm.getSizeCode() == 3)
68       {
69         int hugeGrpprlOffset = sprm.getOperand();
70         if(hugeGrpprlOffset+1 < datastream.length)
71         {
72           int grpprlSize = LittleEndian.getShort(datastream, hugeGrpprlOffset);
73           if( hugeGrpprlOffset+grpprlSize < datastream.length)
74           {
75             byte[] hugeGrpprl = new byte[grpprlSize + 2];
76             // copy original istd into huge Grpprl
77
hugeGrpprl[0] = grpprl[0]; hugeGrpprl[1] = grpprl[1];
78             // copy Grpprl from dataStream
79
System.arraycopy(datastream, hugeGrpprlOffset + 2, hugeGrpprl, 2,
80                              grpprlSize);
81             // save a pointer to where we got the huge Grpprl from
82
_hugeGrpprlOffset = hugeGrpprlOffset;
83             return new SprmBuffer(hugeGrpprl);
84           }
85         }
86       }
87     }
88     return null;
89   }
90
91
92   public ParagraphHeight getParagraphHeight()
93   {
94     return _phe;
95   }
96
97   public byte[] getGrpprl()
98   {
99     return ((SprmBuffer)_buf).toByteArray();
100   }
101
102   public int getHugeGrpprlOffset()
103   {
104     return _hugeGrpprlOffset;
105   }
106
107   public short getIstd()
108   {
109     byte[] buf = getGrpprl();
110     if (buf.length == 0)
111     {
112       return 0;
113     }
114     else
115     {
116       return LittleEndian.getShort(buf);
117     }
118   }
119
120   public SprmBuffer getSprmBuf()
121   {
122     return (SprmBuffer)_buf;
123   }
124
125   public ParagraphProperties getParagraphProperties(StyleSheet ss)
126   {
127     short istd = getIstd();
128     ParagraphProperties baseStyle = ss.getParagraphStyle(istd);
129     ParagraphProperties props = ParagraphSprmUncompressor.uncompressPAP(baseStyle, getGrpprl(), 2);
130     return props;
131   }
132
133   public boolean equals(Object JavaDoc o)
134   {
135     if (super.equals(o))
136     {
137       return _phe.equals(((PAPX)o)._phe);
138     }
139     return false;
140   }
141 }
142
Popular Tags