1 2 17 18 19 20 package org.apache.poi.hdf.model.hdftypes; 21 22 import java.util.*; 23 24 import org.apache.poi.hdf.extractor.*; 25 26 27 32 33 public class ListTables implements HDFType 34 { 35 36 LFO[] _pllfo; 37 Hashtable _lists = new Hashtable(); 38 39 public ListTables(byte[] plcflst, byte[] plflfo) 40 { 41 initLST(plcflst); 42 initLFO(plflfo); 43 } 44 public LVL getLevel(int list, int level) 45 { 46 47 LFO override = _pllfo[list - 1]; 48 49 for(int x = 0; x < override._clfolvl; x++) 50 { 51 if(override._levels[x]._ilvl == level) 52 { 53 LFOLVL lfolvl = override._levels[x]; 54 if(lfolvl._fFormatting) 55 { 56 LST lst = (LST)_lists.get(new Integer (override._lsid)); 57 LVL lvl = lfolvl._override; 58 lvl._istd = Utils.convertBytesToShort(lst._rgistd, level * 2); 59 return lvl; 60 } 61 else if(lfolvl._fStartAt) 62 { 63 LST lst = (LST)_lists.get(new Integer (override._lsid)); 64 LVL lvl = lst._levels[level]; 65 LVL newLvl = (LVL)lvl.clone(); 66 newLvl._istd = Utils.convertBytesToShort(lst._rgistd, level * 2); 67 newLvl._iStartAt = lfolvl._iStartAt; 68 return newLvl; 69 } 70 } 71 } 72 73 LST lst = (LST)_lists.get(new Integer (override._lsid)); 74 LVL lvl = lst._levels[level]; 75 lvl._istd = Utils.convertBytesToShort(lst._rgistd, level * 2); 76 return lvl; 77 78 79 } 80 private void initLST(byte[] plcflst) 81 { 82 short length = Utils.convertBytesToShort(plcflst, 0); 83 int nextLevelOffset = 0; 84 for(int x = 0; x < length; x++) 86 { 87 LST lst = new LST(); 88 lst._lsid = Utils.convertBytesToInt(plcflst, 2 + (x * 28)); 89 lst._tplc = Utils.convertBytesToInt(plcflst, 2 + 4 + (x * 28)); 90 System.arraycopy(plcflst, 2 + 8 + (x * 28), lst._rgistd, 0, 18); 91 byte code = plcflst[2 + 26 + (x * 28)]; 92 lst._fSimpleList = StyleSheet.getFlag(code & 0x01); 93 _lists.put(new Integer (lst._lsid), lst); 95 96 if(lst._fSimpleList) 97 { 98 lst._levels = new LVL[1]; 99 } 100 else 101 { 102 lst._levels = new LVL[9]; 103 } 104 105 for(int y = 0; y < lst._levels.length; y++) 106 { 107 int offset = 2 + (length * 28) + nextLevelOffset; 108 lst._levels[y] = new LVL(); 109 nextLevelOffset += createLVL(plcflst, offset, lst._levels[y]); 110 } 111 } 112 113 114 } 115 private void initLFO(byte[] plflfo) 116 { 117 int lfoSize = Utils.convertBytesToInt(plflfo, 0); 118 _pllfo = new LFO[lfoSize]; 119 for(int x = 0; x < lfoSize; x++) 120 { 121 LFO nextLFO = new LFO(); 122 nextLFO._lsid = Utils.convertBytesToInt(plflfo, 4 + (x * 16)); 123 nextLFO._clfolvl = plflfo[4 + 12 + (x * 16)]; 124 nextLFO._levels = new LFOLVL[nextLFO._clfolvl]; 125 _pllfo[x] = nextLFO; 126 } 127 128 int lfolvlOffset = (lfoSize * 16) + 4; 129 int lvlOffset = 0; 130 int lfolvlNum = 0; 131 for(int x = 0; x < lfoSize; x++) 132 { 133 if (_pllfo[x]._clfolvl == 0) 134 lfolvlNum++; 138 else 139 { 140 for(int y = 0; y < _pllfo[x]._clfolvl; y++) 141 { 142 int offset = lfolvlOffset + (lfolvlNum * 8) + lvlOffset; 143 LFOLVL lfolvl = new LFOLVL(); 144 lfolvl._iStartAt = Utils.convertBytesToInt(plflfo, offset); 145 lfolvl._ilvl = Utils.convertBytesToInt(plflfo, offset + 4); 146 lfolvl._fStartAt = StyleSheet.getFlag(lfolvl._ilvl & 0x10); 147 lfolvl._fFormatting = StyleSheet.getFlag(lfolvl._ilvl & 0x20); 148 lfolvl._ilvl = (lfolvl._ilvl & (byte)0x0f); 149 lfolvlNum++; 150 151 if(lfolvl._fFormatting) 152 { 153 offset = lfolvlOffset + (lfolvlNum * 8) + lvlOffset; 155 lfolvl._override = new LVL(); 156 lvlOffset += createLVL(plflfo, offset, lfolvl._override); 157 } 158 _pllfo[x]._levels[y] = lfolvl; 159 } 160 } 161 } 162 } 163 private int createLVL(byte[] data, int offset, LVL lvl) 164 { 165 int startingOffset = offset; 166 lvl._iStartAt = Utils.convertBytesToInt(data, offset); 167 offset += 4; 168 lvl._nfc = data[offset++]; 169 byte code = data[offset++]; 170 lvl._jc = (byte)(code & 0x03); 171 lvl._fLegal = StyleSheet.getFlag(code & 0x04); 172 lvl._fNoRestart = StyleSheet.getFlag(code & 0x08); 173 lvl._fPrev = StyleSheet.getFlag(code & 0x10); 174 lvl._fPrevSpace = StyleSheet.getFlag(code & 0x20); 175 lvl._fWord6 = StyleSheet.getFlag(code & 0x40); 176 177 System.arraycopy(data, offset, lvl._rgbxchNums, 0, 9); 180 offset += 9; 181 182 lvl._ixchFollow = data[offset++]; 183 184 if (lvl._fWord6) 185 { 186 lvl._dxaSpace = Utils.convertBytesToInt(data, offset); 187 lvl._dxaIndent = Utils.convertBytesToInt(data, offset + 4); 188 } 189 offset += 8; 190 191 int chpxSize = data[offset++]; 192 int papxSize = data[offset++]; 193 lvl._chpx = new byte[chpxSize]; 194 lvl._papx = new byte[papxSize]; 195 196 System.arraycopy(data, offset, lvl._chpx, 0, chpxSize); 197 System.arraycopy(data, offset + chpxSize, lvl._papx, 0, papxSize); 198 199 offset += papxSize + chpxSize + 2; int xstSize = Utils.convertBytesToShort(data, offset); 201 offset += 2; 202 lvl._xst = new char[xstSize]; 203 204 for(int x = 0; x < xstSize; x++) 205 { 206 lvl._xst[x] = (char)Utils.convertBytesToShort(data, offset + (x * 2)); 207 } 208 return offset + (xstSize * 2) - startingOffset; 209 } 210 } 211 | Popular Tags |