KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Arrays JavaDoc;
24
25 import org.apache.poi.hwpf.usermodel.CharacterProperties;
26 import org.apache.poi.util.LittleEndian;
27
28 public class CharacterSprmCompressor
29 {
30   public CharacterSprmCompressor()
31   {
32   }
33   public static byte[] compressCharacterProperty(CharacterProperties newCHP, CharacterProperties oldCHP)
34   {
35     ArrayList JavaDoc sprmList = new ArrayList JavaDoc();
36     int size = 0;
37
38     if (newCHP.isFRMarkDel() != oldCHP.isFRMarkDel())
39     {
40       int value = 0;
41       if (newCHP.isFRMarkDel())
42       {
43         value = 0x01;
44       }
45       size += SprmUtils.addSprm((short)0x0800, value, null, sprmList);
46     }
47     if (newCHP.isFRMark() != oldCHP.isFRMark())
48     {
49       int value = 0;
50       if (newCHP.isFRMark())
51       {
52         value = 0x01;
53       }
54       size += SprmUtils.addSprm((short)0x0801, value, null, sprmList);
55     }
56     if (newCHP.isFFldVanish() != oldCHP.isFFldVanish())
57     {
58       int value = 0;
59       if (newCHP.isFFldVanish())
60       {
61         value = 0x01;
62       }
63       size += SprmUtils.addSprm((short)0x0802, value, null, sprmList);
64     }
65     if (newCHP.isFSpec() != oldCHP.isFSpec() || newCHP.getFcPic() != oldCHP.getFcPic())
66     {
67       size += SprmUtils.addSprm((short)0x6a03, newCHP.getFcPic(), null, sprmList);
68     }
69     if (newCHP.getIbstRMark() != oldCHP.getIbstRMark())
70     {
71        size += SprmUtils.addSprm((short)0x4804, newCHP.getIbstRMark(), null, sprmList);
72     }
73     if (!newCHP.getDttmRMark().equals(oldCHP.getDttmRMark()))
74     {
75       byte[] buf = new byte[4];
76       newCHP.getDttmRMark().serialize(buf, 0);
77
78       size += SprmUtils.addSprm((short)0x6805, LittleEndian.getInt(buf), null, sprmList);
79     }
80     if (newCHP.isFData() != oldCHP.isFData())
81     {
82       int value = 0;
83       if (newCHP.isFData())
84       {
85         value = 0x01;
86       }
87       size += SprmUtils.addSprm((short)0x0806, value, null, sprmList);
88     }
89     if (newCHP.isFSpec() && newCHP.getFtcSym() != 0)
90     {
91        byte[] varParam = new byte[4];
92        LittleEndian.putShort(varParam, 0, (short)newCHP.getFtcSym());
93        LittleEndian.putShort(varParam, 2, (short)newCHP.getXchSym());
94
95        size += SprmUtils.addSprm((short)0x6a09, 0, varParam, sprmList);
96     }
97     if (newCHP.isFOle2() != newCHP.isFOle2())
98     {
99       int value = 0;
100       if (newCHP.isFOle2())
101       {
102         value = 0x01;
103       }
104       size += SprmUtils.addSprm((short)0x080a, value, null, sprmList);
105     }
106     if (newCHP.getIcoHighlight() != oldCHP.getIcoHighlight())
107     {
108       size += SprmUtils.addSprm((short)0x2a0c, newCHP.getIcoHighlight(), null, sprmList);
109     }
110     if (newCHP.getFcObj() != oldCHP.getFcObj())
111     {
112       size += SprmUtils.addSprm((short)0x680e, newCHP.getFcObj(), null, sprmList);
113     }
114     if (newCHP.getIstd() != oldCHP.getIstd())
115     {
116       size += SprmUtils.addSprm((short)0x4a30, newCHP.getIstd(), null, sprmList);
117     }
118     if (newCHP.isFBold() != oldCHP.isFBold())
119     {
120       int value = 0;
121       if (newCHP.isFBold())
122       {
123         value = 0x01;
124       }
125       size += SprmUtils.addSprm((short)0x0835, value, null, sprmList);
126     }
127     if (newCHP.isFItalic() != oldCHP.isFItalic())
128     {
129       int value = 0;
130       if (newCHP.isFItalic())
131       {
132         value = 0x01;
133       }
134       size += SprmUtils.addSprm((short)0x0836, value, null, sprmList);
135     }
136     if (newCHP.isFStrike() != oldCHP.isFStrike())
137     {
138       int value = 0;
139       if (newCHP.isFStrike())
140       {
141         value = 0x01;
142       }
143       size += SprmUtils.addSprm((short)0x0837, value, null, sprmList);
144     }
145     if (newCHP.isFOutline() != oldCHP.isFOutline())
146     {
147       int value = 0;
148       if (newCHP.isFOutline())
149       {
150         value = 0x01;
151       }
152       size += SprmUtils.addSprm((short)0x0838, value, null, sprmList);
153     }
154     if (newCHP.isFShadow() != oldCHP.isFShadow())
155     {
156       int value = 0;
157       if (newCHP.isFShadow())
158       {
159         value = 0x01;
160       }
161       size += SprmUtils.addSprm((short)0x0839, value, null, sprmList);
162     }
163     if (newCHP.isFSmallCaps() != oldCHP.isFSmallCaps())
164     {
165       int value = 0;
166       if (newCHP.isFSmallCaps())
167       {
168         value = 0x01;
169       }
170       size += SprmUtils.addSprm((short)0x083a, value, null, sprmList);
171     }
172     if (newCHP.isFCaps() != oldCHP.isFCaps())
173     {
174       int value = 0;
175       if (newCHP.isFCaps())
176       {
177         value = 0x01;
178       }
179       size += SprmUtils.addSprm((short)0x083b, value, null, sprmList);
180     }
181     if (newCHP.isFVanish() != oldCHP.isFVanish())
182     {
183       int value = 0;
184       if (newCHP.isFVanish())
185       {
186         value = 0x01;
187       }
188       size += SprmUtils.addSprm((short)0x083c, value, null, sprmList);
189     }
190     if (newCHP.getKul() != oldCHP.getKul())
191     {
192       size += SprmUtils.addSprm((short)0x2a3e, newCHP.getKul(), null, sprmList);
193     }
194     if (newCHP.getDxaSpace() != oldCHP.getDxaSpace())
195     {
196       size += SprmUtils.addSprm((short)0x8840, newCHP.getDxaSpace(), null, sprmList);
197     }
198     if (newCHP.getIco() != oldCHP.getIco())
199     {
200       size += SprmUtils.addSprm((short)0x2a42, newCHP.getIco(), null, sprmList);
201     }
202     if (newCHP.getHps() != oldCHP.getHps())
203     {
204       size += SprmUtils.addSprm((short)0x4a43, newCHP.getHps(), null, sprmList);
205     }
206     if (newCHP.getHpsPos() != oldCHP.getHpsPos())
207     {
208       size += SprmUtils.addSprm((short)0x4845, newCHP.getHpsPos(), null, sprmList);
209     }
210     if (newCHP.getHpsKern() != oldCHP.getHpsKern())
211     {
212       size += SprmUtils.addSprm((short)0x484b, newCHP.getHpsKern(), null, sprmList);
213     }
214     if (newCHP.getYsr() != oldCHP.getYsr())
215     {
216       size += SprmUtils.addSprm((short)0x484e, newCHP.getYsr(), null, sprmList);
217     }
218     if (newCHP.getFtcAscii() != oldCHP.getFtcAscii())
219     {
220       size += SprmUtils.addSprm((short)0x4a4f, newCHP.getFtcAscii(), null, sprmList);
221     }
222     if (newCHP.getFtcFE() != oldCHP.getFtcFE())
223     {
224       size += SprmUtils.addSprm((short)0x4a50, newCHP.getFtcFE(), null, sprmList);
225     }
226     if (newCHP.getFtcOther() != oldCHP.getFtcOther())
227     {
228       size += SprmUtils.addSprm((short)0x4a51, newCHP.getFtcOther(), null, sprmList);
229     }
230
231     if (newCHP.isFDStrike() != oldCHP.isFDStrike())
232     {
233       int value = 0;
234       if (newCHP.isFDStrike())
235       {
236         value = 0x01;
237       }
238       size += SprmUtils.addSprm((short)0x2a53, value, null, sprmList);
239     }
240     if (newCHP.isFImprint() != oldCHP.isFImprint())
241     {
242       int value = 0;
243       if (newCHP.isFImprint())
244       {
245         value = 0x01;
246       }
247       size += SprmUtils.addSprm((short)0x0854, value, null, sprmList);
248     }
249     if (newCHP.isFSpec() != oldCHP.isFSpec())
250     {
251       int value = 0;
252       if (newCHP.isFSpec())
253       {
254         value = 0x01;
255       }
256       size += SprmUtils.addSprm((short)0x0855, value, null, sprmList);
257     }
258     if (newCHP.isFObj() != oldCHP.isFObj())
259     {
260       int value = 0;
261       if (newCHP.isFObj())
262       {
263         value = 0x01;
264       }
265       size += SprmUtils.addSprm((short)0x0856, value, null, sprmList);
266     }
267     if (newCHP.isFEmboss() != oldCHP.isFEmboss())
268     {
269       int value = 0;
270       if (newCHP.isFEmboss())
271       {
272         value = 0x01;
273       }
274       size += SprmUtils.addSprm((short)0x0858, value, null, sprmList);
275     }
276     if (newCHP.getSfxtText() != oldCHP.getSfxtText())
277     {
278       size += SprmUtils.addSprm((short)0x2859, newCHP.getSfxtText(), null, sprmList);
279     }
280     if (newCHP.getIco24() != oldCHP.getIco24())
281     {
282       if(newCHP.getIco24() != -1) // don't add a sprm if we're looking at an ico = Auto
283
size += SprmUtils.addSprm((short)0x6870, newCHP.getIco24(), null, sprmList);
284     }
285
286     return SprmUtils.getGrpprl(sprmList, size);
287   }
288
289
290
291 }
292
Popular Tags