KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.poi.hwpf.usermodel.TableProperties;
22 import org.apache.poi.util.LittleEndian;
23 import org.apache.poi.hwpf.usermodel.TableCellDescriptor;
24 import org.apache.poi.hwpf.usermodel.ShadingDescriptor;
25 import org.apache.poi.hwpf.usermodel.BorderCode;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.Arrays JavaDoc;
29
30 public class TableSprmCompressor
31 {
32   public TableSprmCompressor()
33   {
34   }
35   public static byte[] compressTableProperty(TableProperties newTAP)
36   {
37     int size = 0;
38     ArrayList JavaDoc sprmList = new ArrayList JavaDoc();
39
40     if (newTAP.getJc() != 0)
41     {
42       size += SprmUtils.addSprm((short)0x5400, newTAP.getJc(), null, sprmList);
43     }
44     if (newTAP.getFCantSplit())
45     {
46       size += SprmUtils.addSprm((short)0x3403, 1, null, sprmList);
47     }
48     if (newTAP.getFTableHeader())
49     {
50       size += SprmUtils.addSprm((short)0x3404, 1, null, sprmList);
51     }
52     byte[] brcBuf = new byte[6 * BorderCode.SIZE];
53     int offset = 0;
54     newTAP.getBrcTop().serialize(brcBuf, offset);
55     offset += BorderCode.SIZE;
56     newTAP.getBrcLeft().serialize(brcBuf, offset);
57     offset += BorderCode.SIZE;
58     newTAP.getBrcBottom().serialize(brcBuf, offset);
59     offset += BorderCode.SIZE;
60     newTAP.getBrcRight().serialize(brcBuf, offset);
61     offset += BorderCode.SIZE;
62     newTAP.getBrcHorizontal().serialize(brcBuf, offset);
63     offset += BorderCode.SIZE;
64     newTAP.getBrcVertical().serialize(brcBuf, offset);
65     byte[] compare = new byte[6 * BorderCode.SIZE];
66     if (!Arrays.equals(brcBuf, compare))
67     {
68       size += SprmUtils.addSprm((short)0xD605, 0, brcBuf, sprmList);
69     }
70     if (newTAP.getDyaRowHeight() != 0)
71     {
72       size += SprmUtils.addSprm((short)0x9407, newTAP.getDyaRowHeight(), null, sprmList);
73     }
74     if (newTAP.getItcMac() > 0)
75     {
76       int itcMac = newTAP.getItcMac();
77       byte[] buf = new byte[1 + (LittleEndian.SHORT_SIZE*(itcMac + 1)) + (TableCellDescriptor.SIZE*itcMac)];
78       buf[0] = (byte)itcMac;
79
80       short[] dxaCenters = newTAP.getRgdxaCenter();
81       for (int x = 0; x < dxaCenters.length; x++)
82       {
83         LittleEndian.putShort(buf, 1 + (x * LittleEndian.SHORT_SIZE),
84                               dxaCenters[x]);
85       }
86
87       TableCellDescriptor[] cellDescriptors = newTAP.getRgtc();
88       for (int x = 0; x < cellDescriptors.length; x++)
89       {
90         cellDescriptors[x].serialize(buf,
91           1+((itcMac+1)*LittleEndian.SHORT_SIZE)+(x*TableCellDescriptor.SIZE));
92       }
93       size += SprmUtils.addSpecialSprm((short)0xD608, buf, sprmList);
94
95 // buf = new byte[(itcMac * ShadingDescriptor.SIZE) + 1];
96
// buf[0] = (byte)itcMac;
97
// ShadingDescriptor[] shds = newTAP.getRgshd();
98
// for (int x = 0; x < itcMac; x++)
99
// {
100
// shds[x].serialize(buf, 1 + (x * ShadingDescriptor.SIZE));
101
// }
102
// size += SprmUtils.addSpecialSprm((short)0xD609, buf, sprmList);
103
}
104     if (newTAP.getTlp() != 0)
105     {
106       size += SprmUtils.addSprm((short)0x740a, newTAP.getTlp(), null, sprmList);
107     }
108
109     return SprmUtils.getGrpprl(sprmList, size);
110   }
111 }
112
Popular Tags