1 2 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 ; 28 import java.util.Arrays ; 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 sprmList = new ArrayList (); 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 } 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 |