1 19 20 package jxl.biff.drawing; 21 22 import java.io.IOException ; 23 import common.Assert; 24 import common.Logger; 25 import jxl.WorkbookSettings; 26 import jxl.biff.ByteData; 27 import jxl.biff.IntegerHelper; 28 import jxl.biff.IndexMapping; 29 import jxl.biff.Type; 30 import jxl.read.biff.File; 31 32 36 public class Chart implements ByteData, EscherStream 37 { 38 41 private static final Logger logger = Logger.getLogger(Chart.class); 42 43 46 private MsoDrawingRecord msoDrawingRecord; 47 48 51 private ObjRecord objRecord; 52 53 56 private int startpos; 57 58 61 private int endpos; 62 63 66 private File file; 67 68 71 private DrawingData drawingData; 72 73 76 private int drawingNumber; 77 78 81 private byte[] data; 82 83 86 private boolean initialized; 87 88 91 private WorkbookSettings workbookSettings; 92 93 103 public Chart(MsoDrawingRecord mso, ObjRecord obj, 104 DrawingData dd, 105 int sp, int ep, File f, WorkbookSettings ws) 106 { 107 msoDrawingRecord = mso; 108 objRecord = obj; 109 startpos = sp; 110 endpos = ep; 111 file = f; 112 workbookSettings = ws; 113 114 if (msoDrawingRecord != null) 118 { 119 drawingData = dd; 120 drawingData.addData(msoDrawingRecord.getRecord().getData()); 121 drawingNumber = drawingData.getNumDrawings() - 1; 122 } 123 124 initialized = false; 125 126 Assert.verify((mso != null && obj != null) || 130 (mso == null && obj == null)); 131 } 132 133 138 public byte[] getBytes() 139 { 140 if (!initialized) 141 { 142 initialize(); 143 } 144 145 return data; 146 } 147 148 153 public byte[] getData() 154 { 155 return msoDrawingRecord.getRecord().getData(); 156 } 157 158 161 private void initialize() 162 { 163 data = file.read(startpos, endpos - startpos); 164 initialized = true; 165 } 166 167 173 public void rationalize(IndexMapping xfMapping, 174 IndexMapping fontMapping, 175 IndexMapping formatMapping) 176 { 177 if (!initialized) 178 { 179 initialize(); 180 } 181 182 int pos = 0; 186 int code = 0; 187 int length = 0; 188 Type type = null; 189 while (pos < data.length) 190 { 191 code = IntegerHelper.getInt(data[pos], data[pos+1]); 192 length = IntegerHelper.getInt(data[pos+2], data[pos+3]); 193 194 type = Type.getType(code); 195 196 if (type == Type.FONTX) 197 { 198 int fontind = IntegerHelper.getInt(data[pos+4], data[pos+5]); 199 IntegerHelper.getTwoBytes(fontMapping.getNewIndex(fontind), 200 data, pos+4); 201 } 202 else if (type == Type.FBI) 203 { 204 int fontind = IntegerHelper.getInt(data[pos+12], data[pos+13]); 205 IntegerHelper.getTwoBytes(fontMapping.getNewIndex(fontind), 206 data, pos+12); 207 } 208 else if (type == Type.IFMT) 209 { 210 int formind = IntegerHelper.getInt(data[pos+4], data[pos+5]); 211 IntegerHelper.getTwoBytes(formatMapping.getNewIndex(formind), 212 data, pos+4); 213 } 214 else if (type == Type.ALRUNS) 215 { 216 int numRuns = IntegerHelper.getInt(data[pos+4], data[pos+5]); 217 int fontPos = pos+6; 218 for (int i = 0 ; i < numRuns; i++) 219 { 220 int fontind = IntegerHelper.getInt(data[fontPos+2], data[fontPos+3]); 221 IntegerHelper.getTwoBytes(fontMapping.getNewIndex(fontind), 222 data, fontPos+2); 223 fontPos += 4; 224 } 225 } 226 227 pos += length+4; 228 } 229 } 230 231 236 EscherContainer getSpContainer() 237 { 238 EscherContainer spContainer = drawingData.getSpContainer(drawingNumber); 239 240 return spContainer; 241 } 242 243 248 MsoDrawingRecord getMsoDrawingRecord() 249 { 250 return msoDrawingRecord; 251 } 252 253 258 ObjRecord getObjRecord() 259 { 260 return objRecord; 261 } 262 } 263 264 265 266 267 268 | Popular Tags |