KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hwpf > sprm > ParagraphSprmCompressor


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 package org.apache.poi.hwpf.sprm;
20
21 import java.util.List JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Arrays JavaDoc;
24
25 import org.apache.poi.util.LittleEndian;
26
27 import org.apache.poi.hwpf.usermodel.ParagraphProperties;
28
29 public class ParagraphSprmCompressor
30 {
31   public ParagraphSprmCompressor()
32   {
33   }
34
35   public static byte[] compressParagraphProperty(ParagraphProperties newPAP,
36                                                  ParagraphProperties oldPAP)
37   {
38     ArrayList JavaDoc sprmList = new ArrayList JavaDoc();
39     int size = 0;
40
41     if (newPAP.getJc() != oldPAP.getJc())
42     {
43       size += SprmUtils.addSprm((short)0x2403, newPAP.getJc(), null, sprmList);
44     }
45     if (newPAP.getFKeep() != oldPAP.getFKeep())
46     {
47       size += SprmUtils.addSprm((short)0x2405, newPAP.getFKeep(), null, sprmList);
48     }
49     if (newPAP.getFKeepFollow() != oldPAP.getFKeepFollow())
50     {
51       size += SprmUtils.addSprm((short)0x2406, newPAP.getFKeepFollow(), null, sprmList);
52     }
53     if (newPAP.getFPageBreakBefore() != oldPAP.getFPageBreakBefore())
54     {
55       size += SprmUtils.addSprm((short)0x2407, newPAP.getFPageBreakBefore(), null, sprmList);
56     }
57     if (newPAP.getBrcl() != oldPAP.getBrcl())
58     {
59       size += SprmUtils.addSprm((short)0x2408, newPAP.getBrcl(), null, sprmList);
60     }
61     if (newPAP.getBrcp() != oldPAP.getBrcp())
62     {
63       size += SprmUtils.addSprm((short)0x2409, newPAP.getBrcp(), null, sprmList);
64     }
65     if (newPAP.getIlvl() != oldPAP.getIlvl())
66     {
67       size += SprmUtils.addSprm((short)0x260A, newPAP.getIlvl(), null, sprmList);
68     }
69     if (newPAP.getIlfo() != oldPAP.getIlfo())
70     {
71       size += SprmUtils.addSprm((short)0x460b, newPAP.getIlfo(), null, sprmList);
72     }
73     if (newPAP.getFNoLnn() != oldPAP.getFNoLnn())
74     {
75       size += SprmUtils.addSprm((short)0x240C, newPAP.getFNoLnn(), null, sprmList);
76     }
77     if (newPAP.getFSideBySide() != oldPAP.getFSideBySide())
78     {
79       size += SprmUtils.addSprm((short)0x2404, newPAP.getFSideBySide(), null, sprmList);
80     }
81     if (newPAP.getFNoAutoHyph() != oldPAP.getFNoAutoHyph())
82     {
83       size += SprmUtils.addSprm((short)0x242A, newPAP.getFNoAutoHyph(), null, sprmList);
84     }
85     if (newPAP.getFWidowControl() != oldPAP.getFWidowControl())
86     {
87       size += SprmUtils.addSprm((short)0x2431, newPAP.getFWidowControl(), null, sprmList);
88     }
89     if (newPAP.getItbdMac() != oldPAP.getItbdMac() ||
90         !Arrays.equals(newPAP.getRgdxaTab(), oldPAP.getRgdxaTab()) ||
91         !Arrays.equals(newPAP.getRgtbd(), oldPAP.getRgtbd()))
92     {
93       /** @todo revisit this */
94 // byte[] oldTabArray = oldPAP.getRgdxaTab();
95
// byte[] newTabArray = newPAP.getRgdxaTab();
96
// byte[] newTabDescriptors = newPAP.getRgtbd();
97
// byte[] varParam = new byte[2 + oldTabArray.length + newTabArray.length +
98
// newTabDescriptors.length];
99
// varParam[0] = (byte)(oldTabArray.length/2);
100
// int offset = 1;
101
// System.arraycopy(oldTabArray, 0, varParam, offset, oldTabArray.length);
102
// offset += oldTabArray.length;
103
// varParam[offset] = (byte)(newTabArray.length/2);
104
// offset += 1;
105
// System.arraycopy(newTabArray, 0, varParam, offset, newTabArray.length);
106
// offset += newTabArray.length;
107
// System.arraycopy(newTabDescriptors, 0, varParam, offset, newTabDescriptors.length);
108
//
109
// size += SprmUtils.addSprm((short)0xC60D, 0, varParam, sprmList);
110
}
111     if (newPAP.getDxaRight() != oldPAP.getDxaRight())
112     {
113       size += SprmUtils.addSprm((short)0x840E, newPAP.getDxaRight(), null, sprmList);
114     }
115     if (newPAP.getDxaLeft() != oldPAP.getDxaLeft())
116     {
117       size += SprmUtils.addSprm((short)0x840F, newPAP.getDxaLeft(), null, sprmList);
118     }
119     if (newPAP.getDxaLeft1() != oldPAP.getDxaLeft1())
120     {
121       size += SprmUtils.addSprm((short)0x8411, newPAP.getDxaLeft1(), null, sprmList);
122     }
123     if (!newPAP.getLspd().equals(oldPAP.getLspd()))
124     {
125       byte[] buf = new byte[4];
126       newPAP.getLspd().serialize(buf, 0);
127
128       size += SprmUtils.addSprm((short)0x6412, LittleEndian.getInt(buf), null, sprmList);
129     }
130     if (newPAP.getDyaBefore() != oldPAP.getDyaBefore())
131     {
132       size += SprmUtils.addSprm((short)0xA413, newPAP.getDyaBefore(), null, sprmList);
133     }
134     if (newPAP.getDyaAfter() != oldPAP.getDyaAfter())
135     {
136       size += SprmUtils.addSprm((short)0xA414, newPAP.getDyaAfter(), null, sprmList);
137     }
138     if (newPAP.getDyaBefore() != oldPAP.getDyaBefore())
139     {
140       size += SprmUtils.addSprm((short)0x2404, newPAP.getDyaBefore(), null, sprmList);
141     }
142     if (newPAP.getFKinsoku() != oldPAP.getFKinsoku())
143     {
144       size += SprmUtils.addSprm((short)0x2433, newPAP.getDyaBefore(), null, sprmList);
145     }
146     if (newPAP.getFWordWrap() != oldPAP.getFWordWrap())
147     {
148       size += SprmUtils.addSprm((short)0x2434, newPAP.getFWordWrap(), null, sprmList);
149     }
150     if (newPAP.getFOverflowPunct() != oldPAP.getFOverflowPunct())
151     {
152       size += SprmUtils.addSprm((short)0x2435, newPAP.getFOverflowPunct(), null, sprmList);
153     }
154     if (newPAP.getFTopLinePunct() != oldPAP.getFTopLinePunct())
155     {
156       size += SprmUtils.addSprm((short)0x2436, newPAP.getFTopLinePunct(), null, sprmList);
157     }
158     if (newPAP.getFAutoSpaceDE() != oldPAP.getFAutoSpaceDE())
159     {
160       size += SprmUtils.addSprm((short)0x2437, newPAP.getFAutoSpaceDE(), null, sprmList);
161     }
162     if (newPAP.getFAutoSpaceDN() != oldPAP.getFAutoSpaceDN())
163     {
164       size += SprmUtils.addSprm((short)0x2438, newPAP.getFAutoSpaceDN(), null, sprmList);
165     }
166     if (newPAP.getWAlignFont() != oldPAP.getWAlignFont())
167     {
168       size += SprmUtils.addSprm((short)0x4439, newPAP.getWAlignFont(), null, sprmList);
169     }
170     if (newPAP.isFBackward() != oldPAP.isFBackward() ||
171         newPAP.isFVertical() != oldPAP.isFVertical() ||
172         newPAP.isFRotateFont() != oldPAP.isFRotateFont())
173     {
174       int val = 0;
175       if (newPAP.isFBackward())
176       {
177         val |= 0x2;
178       }
179       if (newPAP.isFVertical())
180       {
181         val |= 0x1;
182       }
183       if (newPAP.isFRotateFont())
184       {
185         val |= 0x4;
186       }
187       size += SprmUtils.addSprm((short)0x443A, val, null, sprmList);
188     }
189     if (!Arrays.equals(newPAP.getAnld(), oldPAP.getAnld()))
190     {
191       size += SprmUtils.addSprm((short)0xC63E, 0, newPAP.getAnld(), sprmList);
192     }
193     if (newPAP.getFInTable() != oldPAP.getFInTable())
194     {
195       size += SprmUtils.addSprm((short)0x2416, newPAP.getFInTable(), null, sprmList);
196     }
197     if (newPAP.getFTtp() != oldPAP.getFTtp())
198     {
199       size += SprmUtils.addSprm((short)0x2417, newPAP.getFTtp(), null, sprmList);
200     }
201     if (newPAP.getWr() != oldPAP.getWr())
202     {
203       size += SprmUtils.addSprm((short)0x2423, newPAP.getWr(), null, sprmList);
204     }
205     if (newPAP.getFLocked() != oldPAP.getFLocked())
206     {
207       size += SprmUtils.addSprm((short)0x2430, newPAP.getFLocked(), null, sprmList);
208     }
209     if (newPAP.getDxaAbs() != oldPAP.getDxaAbs())
210     {
211       size += SprmUtils.addSprm((short)0x8418, newPAP.getDxaAbs(), null, sprmList);
212     }
213     if (newPAP.getDyaAbs() != oldPAP.getDyaAbs())
214     {
215       size += SprmUtils.addSprm((short)0x8419, newPAP.getDyaAbs(), null, sprmList);
216     }
217     if (newPAP.getDxaWidth() != oldPAP.getDxaWidth())
218     {
219       size += SprmUtils.addSprm((short)0x841A, newPAP.getDxaWidth(), null, sprmList);
220     }
221     if (!newPAP.getBrcTop().equals(oldPAP.getBrcTop()))
222     {
223       int brc = newPAP.getBrcTop().toInt();
224       size += SprmUtils.addSprm((short)0x6424, brc, null, sprmList);
225     }
226     if (!newPAP.getBrcLeft().equals(oldPAP.getBrcLeft()))
227     {
228       int brc = newPAP.getBrcLeft().toInt();
229       size += SprmUtils.addSprm((short)0x6425, brc, null, sprmList);
230     }
231     if (!newPAP.getBrcBottom().equals(oldPAP.getBrcBottom()))
232     {
233       int brc = newPAP.getBrcBottom().toInt();
234       size += SprmUtils.addSprm((short)0x6426, brc, null, sprmList);
235     }
236     if (!newPAP.getBrcRight().equals(oldPAP.getBrcRight()))
237     {
238       int brc = newPAP.getBrcRight().toInt();
239       size += SprmUtils.addSprm((short)0x6427, brc, null, sprmList);
240     }
241     if (newPAP.getBrcBar().equals(oldPAP.getBrcBar()))
242     {
243       int brc = newPAP.getBrcBar().toInt();
244       size += SprmUtils.addSprm((short)0x6428, brc, null, sprmList);
245     }
246     if (newPAP.getDxaFromText() != oldPAP.getDxaFromText())
247     {
248       size += SprmUtils.addSprm((short)0x842F, newPAP.getDxaFromText(), null, sprmList);
249     }
250     if (newPAP.getDyaFromText() != oldPAP.getDyaFromText())
251     {
252       size += SprmUtils.addSprm((short)0x842E, newPAP.getDyaFromText(), null, sprmList);
253     }
254     if (newPAP.getDyaHeight() != oldPAP.getDyaHeight() ||
255         newPAP.getFMinHeight() != oldPAP.getFMinHeight())
256     {
257       short val = (short)newPAP.getDyaHeight();
258       if (newPAP.getFMinHeight() > 0)
259       {
260         val |= 0x8000;
261       }
262       size += SprmUtils.addSprm((short)0x442B, val, null, sprmList);
263     }
264     if (newPAP.getShd() != null && !newPAP.getShd().equals(oldPAP.getShd()))
265     {
266       size += SprmUtils.addSprm((short)0x442D, newPAP.getShd().toShort(), null, sprmList);
267     }
268     if (newPAP.getDcs() != null && !newPAP.getDcs().equals(oldPAP.getDcs()))
269     {
270       size += SprmUtils.addSprm((short)0x442C, newPAP.getDcs().toShort(), null, sprmList);
271     }
272     if (newPAP.getLvl() != oldPAP.getLvl())
273     {
274       size += SprmUtils.addSprm((short)0x2640, newPAP.getLvl(), null, sprmList);
275     }
276     if (newPAP.getFNumRMIns() != oldPAP.getFNumRMIns())
277     {
278       size += SprmUtils.addSprm((short)0x2443, newPAP.getFNumRMIns(), null, sprmList);
279     }
280     if (newPAP.getFPropRMark() != oldPAP.getFPropRMark() ||
281         newPAP.getIbstPropRMark() != oldPAP.getIbstPropRMark() ||
282         !newPAP.getDttmPropRMark().equals(oldPAP.getDttmPropRMark()))
283     {
284       byte[] buf = new byte[7];
285       buf[0] = (byte)newPAP.getFPropRMark();
286       LittleEndian.putShort(buf, 1, (short)newPAP.getIbstPropRMark());
287       newPAP.getDttmPropRMark().serialize(buf, 3);
288       size += SprmUtils.addSprm((short)0xC63F, 0, buf, sprmList);
289     }
290     if (!Arrays.equals(newPAP.getNumrm(), oldPAP.getNumrm()))
291     {
292       size += SprmUtils.addSprm((short)0xC645, 0, newPAP.getNumrm(), sprmList);
293     }
294
295     if (newPAP.getTableLevel() != oldPAP.getTableLevel())
296     {
297       size += SprmUtils.addSprm((short)0x6649, newPAP.getTableLevel(), null, sprmList);
298     }
299
300     if (newPAP.getEmbeddedCellMark() != oldPAP.getEmbeddedCellMark())
301     {
302       size += SprmUtils.addSprm((short)0x244b, newPAP.getEmbeddedCellMark(), null, sprmList);
303     }
304
305     if (newPAP.getFTtpEmbedded() != oldPAP.getFTtpEmbedded())
306     {
307       size += SprmUtils.addSprm((short)0x244c, newPAP.getFTtpEmbedded(), null, sprmList);
308     }
309
310     return SprmUtils.getGrpprl(sprmList, size);
311
312   }
313 }
314
Popular Tags