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.hwpf.usermodel.TableCellDescriptor; 23 import org.apache.poi.hwpf.usermodel.BorderCode; 24 25 import org.apache.poi.util.LittleEndian; 26 27 public class TableSprmUncompressor 28 extends SprmUncompressor 29 { 30 public TableSprmUncompressor() 31 { 32 } 33 34 public static TableProperties uncompressTAP(byte[] grpprl, 35 int offset) 36 { 37 TableProperties newProperties = new TableProperties(); 38 39 SprmIterator sprmIt = new SprmIterator(grpprl, offset); 40 41 while (sprmIt.hasNext()) 42 { 43 SprmOperation sprm = (SprmOperation)sprmIt.next(); 44 45 if (sprm.getType() == SprmOperation.TAP_TYPE) 48 { 49 unCompressTAPOperation(newProperties, sprm); 50 } 51 } 52 53 return newProperties; 54 } 55 56 65 static void unCompressTAPOperation (TableProperties newTAP, SprmOperation sprm) 66 { 67 switch (sprm.getOperation()) 68 { 69 case 0: 70 newTAP.setJc ((short) sprm.getOperand()); 71 break; 72 case 0x01: 73 { 74 short[] rgdxaCenter = newTAP.getRgdxaCenter (); 75 short itcMac = newTAP.getItcMac (); 76 int adjust = sprm.getOperand() - (rgdxaCenter[0] + newTAP.getDxaGapHalf ()); 77 for (int x = 0; x < itcMac; x++) 78 { 79 rgdxaCenter[x] += adjust; 80 } 81 break; 82 } 83 case 0x02: 84 { 85 short[] rgdxaCenter = newTAP.getRgdxaCenter (); 86 if (rgdxaCenter != null) 87 { 88 int adjust = newTAP.getDxaGapHalf () - sprm.getOperand(); 89 rgdxaCenter[0] += adjust; 90 } 91 newTAP.setDxaGapHalf (sprm.getOperand()); 92 break; 93 } 94 case 0x03: 95 newTAP.setFCantSplit (getFlag(sprm.getOperand())); 96 break; 97 case 0x04: 98 newTAP.setFTableHeader (getFlag (sprm.getOperand())); 99 break; 100 case 0x05: 101 { 102 byte[] buf = sprm.getGrpprl(); 103 int offset = sprm.getGrpprlOffset(); 104 newTAP.setBrcTop(new BorderCode(buf, offset)); 105 offset += BorderCode.SIZE; 106 newTAP.setBrcLeft(new BorderCode(buf, offset)); 107 offset += BorderCode.SIZE; 108 newTAP.setBrcBottom(new BorderCode(buf, offset)); 109 offset += BorderCode.SIZE; 110 newTAP.setBrcRight(new BorderCode(buf, offset)); 111 offset += BorderCode.SIZE; 112 newTAP.setBrcHorizontal(new BorderCode(buf, offset)); 113 offset += BorderCode.SIZE; 114 newTAP.setBrcVertical(new BorderCode(buf, offset)); 115 break; 116 } 117 case 0x06: 118 119 break; 121 case 0x07: 122 newTAP.setDyaRowHeight (sprm.getOperand()); 123 break; 124 case 0x08: 125 { 126 byte[] grpprl = sprm.getGrpprl(); 127 int offset = sprm.getGrpprlOffset(); 128 short itcMac = grpprl[offset]; 129 short[] rgdxaCenter = new short[itcMac + 1]; 130 TableCellDescriptor[] rgtc = new TableCellDescriptor[itcMac]; 131 newTAP.setItcMac (itcMac); 133 newTAP.setRgdxaCenter (rgdxaCenter); 134 newTAP.setRgtc (rgtc); 135 136 for (int x = 0; x < itcMac; x++) 138 { 139 rgdxaCenter[x] = LittleEndian.getShort (grpprl, offset + (1 + (x * 2))); 140 } 141 142 int endOfSprm = offset+sprm.size()-6; int startOfTCs = offset + (1 + (itcMac + 1) * 2); 145 146 boolean hasTCs = startOfTCs < endOfSprm; 147 148 for (int x = 0; x < itcMac; x++) 149 { 150 if(hasTCs) rgtc[x] = TableCellDescriptor.convertBytesToTC(grpprl, 151 offset + (1 + ( (itcMac + 1) * 2) + (x * 20))); 152 else 153 rgtc[x] = new TableCellDescriptor(); 154 } 155 156 rgdxaCenter[itcMac] = LittleEndian.getShort (grpprl, offset + (1 + (itcMac * 2))); 157 break; 158 } 159 case 0x09: 160 161 162 break; 163 case 0x0a: 164 165 166 break; 167 case 0x20: 168 break; 202 case 0x21: 203 { 204 int param = sprm.getOperand(); 205 int index = (param & 0xff000000) >> 24; 206 int count = (param & 0x00ff0000) >> 16; 207 int width = (param & 0x0000ffff); 208 int itcMac = newTAP.getItcMac(); 209 210 short[] rgdxaCenter = new short[itcMac + count + 1]; 211 TableCellDescriptor[] rgtc = new TableCellDescriptor[itcMac + count]; 212 if (index >= itcMac) 213 { 214 index = itcMac; 215 System.arraycopy(newTAP.getRgdxaCenter(), 0, rgdxaCenter, 0, 216 itcMac + 1); 217 System.arraycopy(newTAP.getRgtc(), 0, rgtc, 0, itcMac); 218 } 219 else 220 { 221 System.arraycopy(newTAP.getRgdxaCenter(), 0, rgdxaCenter, 0, 223 index + 1); 224 System.arraycopy(newTAP.getRgdxaCenter(), index + 1, rgdxaCenter, 225 index + count, itcMac - (index)); 226 System.arraycopy(newTAP.getRgtc(), 0, rgtc, 0, index); 228 System.arraycopy(newTAP.getRgtc(), index, rgtc, index + count, 229 itcMac - index); 230 } 231 232 for (int x = index; x < index + count; x++) 233 { 234 rgtc[x] = new TableCellDescriptor(); 235 rgdxaCenter[x] = (short)(rgdxaCenter[x - 1] + width); 236 } 237 rgdxaCenter[index + 238 count] = (short)(rgdxaCenter[(index + count) - 1] + width); 239 break; 240 } 241 242 case 0x22: 243 case 0x23: 244 case 0x24: 245 case 0x25: 246 case 0x26: 247 case 0x27: 248 case 0x28: 249 case 0x29: 250 case 0x2a: 251 case 0x2b: 252 case 0x2c: 253 break; 254 default: 255 break; 256 } 257 } 258 259 260 261 } 262 | Popular Tags |