1 2 17 18 19 20 package org.apache.poi.hdf.extractor.data; 21 22 import java.util.*; 23 24 import org.apache.poi.hdf.extractor.*; 25 26 27 32 33 public class ListTables 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 for(int y = 0; y < _pllfo[x]._clfolvl; y++) 134 { 135 int offset = lfolvlOffset + (lfolvlNum * 8) + lvlOffset; 136 LFOLVL lfolvl = new LFOLVL(); 137 lfolvl._iStartAt = Utils.convertBytesToInt(plflfo, offset); 138 lfolvl._ilvl = Utils.convertBytesToInt(plflfo, offset + 4); 139 lfolvl._fStartAt = StyleSheet.getFlag(lfolvl._ilvl & 0x10); 140 lfolvl._fFormatting = StyleSheet.getFlag(lfolvl._ilvl & 0x20); 141 lfolvl._ilvl = (lfolvl._ilvl & (byte)0x0f); 142 lfolvlNum++; 143 144 if(lfolvl._fFormatting) 145 { 146 offset = lfolvlOffset + (lfolvlNum * 12) + lvlOffset; 147 lfolvl._override = new LVL(); 148 lvlOffset += createLVL(plflfo, offset, lfolvl._override); 149 } 150 _pllfo[x]._levels[y] = lfolvl; 151 } 152 } 153 } 154 private int createLVL(byte[] data, int offset, LVL lvl) 155 { 156 157 lvl._iStartAt = Utils.convertBytesToInt(data, offset); 158 lvl._nfc = data[offset + 4]; 159 int code = Utils.convertBytesToInt(data, offset + 5); 160 lvl._jc = (byte)(code & 0x03); 161 lvl._fLegal = StyleSheet.getFlag(code & 0x04); 162 lvl._fNoRestart = StyleSheet.getFlag(code & 0x08); 163 lvl._fPrev = StyleSheet.getFlag(code & 0x10); 164 lvl._fPrevSpace = StyleSheet.getFlag(code & 0x20); 165 lvl._fWord6 = StyleSheet.getFlag(code & 0x40); 166 System.arraycopy(data, offset + 6, lvl._rgbxchNums, 0, 9); 167 lvl._ixchFollow = data[offset + 15]; 168 int chpxSize = data[offset + 24]; 169 int papxSize = data[offset + 25]; 170 lvl._chpx = new byte[chpxSize]; 171 lvl._papx = new byte[papxSize]; 172 System.arraycopy(data, offset + 28, lvl._papx, 0, papxSize); 173 System.arraycopy(data, offset + 28 + papxSize, lvl._chpx, 0, chpxSize); 174 offset += 28 + papxSize + chpxSize; int xstSize = Utils.convertBytesToShort(data, offset); 176 lvl._xst = new char[xstSize]; 177 178 offset += 2; 179 for(int x = 0; x < xstSize; x++) 180 { 181 lvl._xst[x] = (char)Utils.convertBytesToShort(data, offset + (x * 2)); 182 } 183 return 28 + papxSize + chpxSize + 2 + (xstSize * 2); 184 } 185 } 186 | Popular Tags |