1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.xmerge.converter.xml.sxc.pexcel.records; 25 26 import java.io.IOException; 27 import java.io.InputStream; 28 import java.io.OutputStream; 29 30 import org.openoffice.xmerge.util.Debug; 31 import org.openoffice.xmerge.util.EndianConverter; 32 import org.openoffice.xmerge.converter.xml.sxc.pexcel.PocketExcelConstants; 33 34 /** 35 * ColInfo describes the formatting for a column 36 * 37 */ 38 public class ColInfo implements BIFFRecord { 39 40 private byte[] colFirst = new byte[2]; // first column this formatting applies to 41 private byte[] colLast = new byte[2]; // last column this formatting applies to 42 private byte[] colDX = new byte[2]; // column width 43 private byte[] ixfe = new byte[2]; // index for formatting 44 private byte grbit; // options flags 45 private float scale = (float) 2.5; // 1.798; 46 47 /** 48 * Constructs a pocket Excel Document from the 49 * <code>InputStream</code> and assigns it the document name passed in 50 * 51 * @param colFirst the first column this formatting applies to 52 * @param colLast last column this formatting applies to 53 * @param colDX column width 54 * @param ixfe options flags 55 */ ColInfo(int colFirst, int colLast, int colDX, int ixfe)56 public ColInfo(int colFirst, int colLast, int colDX, int ixfe) { 57 this.colFirst = EndianConverter.writeShort((short)colFirst); 58 this.colLast = EndianConverter.writeShort((short)colLast); 59 colDX *= scale; 60 this.colDX = EndianConverter.writeShort((short)colDX); 61 this.ixfe = EndianConverter.writeShort((short)ixfe); 62 this.grbit = 0x00; 63 } 64 65 /** 66 * Construct a ColInfo from the InputStream 67 * 68 * @param is the <code>Inputstream</code> to read from 69 */ ColInfo(InputStream is)70 public ColInfo(InputStream is) throws IOException { 71 read(is); 72 } 73 74 /** 75 * Reads ColInfo record from the InputStream 76 * 77 * @param input the InputStream to read from 78 * @return the number of bytes read 79 */ read(InputStream input)80 public int read(InputStream input) throws IOException { 81 82 int numOfBytesRead = input.read(colFirst); 83 numOfBytesRead += input.read(colLast); 84 numOfBytesRead += input.read(colDX); 85 short scaledDX = (short) (EndianConverter.readShort(colDX) / scale); 86 colDX = EndianConverter.writeShort(scaledDX); 87 numOfBytesRead += input.read(ixfe); 88 grbit = (byte) input.read(); 89 numOfBytesRead ++; 90 91 Debug.log(Debug.TRACE,"\tcolFirst : "+ EndianConverter.readShort(colFirst) + 92 " colLast : " + EndianConverter.readShort(colLast) + 93 " colDX : " + EndianConverter.readShort(colDX) + 94 " ixfe : " + EndianConverter.readShort(ixfe) + 95 " grbit : " + grbit); 96 97 return numOfBytesRead; 98 } 99 100 /** 101 * Get the hex code for this particular <code>BIFFRecord</code> 102 * 103 * @return the hex code for <code>ColInfo</code> 104 */ getBiffType()105 public short getBiffType() { 106 return PocketExcelConstants.COLINFO; 107 } 108 /** 109 * Get the width of this column 110 * 111 * @return the width of this column 112 */ getColWidth()113 public short getColWidth() { 114 return EndianConverter.readShort(colDX); 115 } 116 117 /** 118 * Get the hex code for this particular <code>BIFFRecord</code> 119 * 120 * @return the hex code for <code>ColInfo</code> 121 */ getFirst()122 public short getFirst() { 123 return EndianConverter.readShort(colFirst); 124 } 125 126 /** 127 * Get the hex code for this particular <code>BIFFRecord</code> 128 * 129 * @return the hex code for <code>ColInfo</code> 130 */ getLast()131 public short getLast() { 132 return EndianConverter.readShort(colLast); 133 } 134 135 /** 136 * Writes a ColInfo to the specified <code>Outputstream</code> 137 * 138 * @param output the <code>OutputStream</code> to write to 139 */ write(OutputStream output)140 public void write(OutputStream output) throws IOException { 141 142 output.write(getBiffType()); 143 output.write(colFirst); 144 output.write(colLast); 145 output.write(colDX); 146 output.write(ixfe); 147 output.write(grbit); 148 149 Debug.log(Debug.TRACE,"Writing ColInfo record"); 150 151 } 152 153 } 154