1 2 17 18 19 package org.apache.poi.hwpf.model; 20 21 import org.apache.poi.util.BitField; 22 import org.apache.poi.util.LittleEndian; 23 import java.util.Arrays ; 24 25 32 public class Ffn 33 { 34 private int _cbFfnM1; private byte _info; 36 private static BitField _prq = new BitField(0x0003); private static BitField _fTrueType = new BitField(0x0004); private static BitField _ff = new BitField(0x0070); 39 private short _wWeight; private byte _chs; private byte _ixchSzAlt; private byte [] _panose = new byte[10]; private byte [] _fontSig = new byte[24]; 46 private char [] _xszFfn; 49 50 private int _xszFfnLength; 52 53 public Ffn(byte[] buf, int offset) 54 { 55 int offsetTmp = offset; 56 57 _cbFfnM1 = LittleEndian.getUnsignedByte(buf,offset); 58 offset += LittleEndian.BYTE_SIZE; 59 _info = buf[offset]; 60 offset += LittleEndian.BYTE_SIZE; 61 _wWeight = LittleEndian.getShort(buf, offset); 62 offset += LittleEndian.SHORT_SIZE; 63 _chs = buf[offset]; 64 offset += LittleEndian.BYTE_SIZE; 65 _ixchSzAlt = buf[offset]; 66 offset += LittleEndian.BYTE_SIZE; 67 68 System.arraycopy(buf, offset, _panose, 0, _panose.length); 70 offset += _panose.length; 71 System.arraycopy(buf, offset, _fontSig, 0, _fontSig.length); 72 offset += _fontSig.length; 73 74 offsetTmp = offset - offsetTmp; 75 _xszFfnLength = (this.getSize() - offsetTmp)/2; 76 _xszFfn = new char[_xszFfnLength]; 77 78 for(int i = 0; i < _xszFfnLength; i++) 79 { 80 _xszFfn[i] = (char)LittleEndian.getShort(buf, offset); 81 offset += LittleEndian.SHORT_SIZE; 82 } 83 84 85 } 86 87 public int get_cbFfnM1() 88 { 89 return _cbFfnM1; 90 } 91 92 public short getWeight() 93 { 94 return _wWeight; 95 } 96 97 public byte getChs() 98 { 99 return _chs; 100 } 101 102 public byte [] getPanose() 103 { 104 return _panose; 105 } 106 107 public byte [] getFontSig() 108 { 109 return _fontSig; 110 } 111 112 public int getSize() 113 { 114 return (_cbFfnM1 + 1); 115 } 116 117 public String getMainFontName() 118 { 119 int index = 0; 120 for (;index < _xszFfnLength; index++) 121 { 122 if (_xszFfn[index] == '\0') 123 { 124 break; 125 } 126 } 127 return new String (_xszFfn, 0, index); 128 } 129 130 public String getAltFontName() 131 { 132 int index = _ixchSzAlt; 133 for (;index < _xszFfnLength; index++) 134 { 135 if (_xszFfn[index] == '\0') 136 { 137 break; 138 } 139 } 140 return new String (_xszFfn, _ixchSzAlt, index); 141 142 } 143 144 public void set_cbFfnM1(int _cbFfnM1) 145 { 146 this._cbFfnM1 = _cbFfnM1; 147 } 148 149 public byte[] toByteArray() 151 { 152 int offset = 0; 153 byte[] buf = new byte[this.getSize()]; 154 155 buf[offset] = (byte)_cbFfnM1; 156 offset += LittleEndian.BYTE_SIZE; 157 buf[offset] = _info; 158 offset += LittleEndian.BYTE_SIZE; 159 LittleEndian.putShort(buf, offset, _wWeight); 160 offset += LittleEndian.SHORT_SIZE; 161 buf[offset] = _chs; 162 offset += LittleEndian.BYTE_SIZE; 163 buf[offset] = _ixchSzAlt; 164 offset += LittleEndian.BYTE_SIZE; 165 166 System.arraycopy(_panose,0,buf, offset,_panose.length); 167 offset += _panose.length; 168 System.arraycopy(_fontSig,0,buf, offset, _fontSig.length); 169 offset += _fontSig.length; 170 171 for(int i = 0; i < _xszFfn.length; i++) 172 { 173 LittleEndian.putShort(buf, offset, (short)_xszFfn[i]); 174 offset += LittleEndian.SHORT_SIZE; 175 } 176 177 return buf; 178 179 } 180 181 public boolean equals(Object o) 182 { 183 boolean retVal = true; 184 185 if (((Ffn)o).get_cbFfnM1() == _cbFfnM1) 186 { 187 if(((Ffn)o)._info == _info) 188 { 189 if(((Ffn)o)._wWeight == _wWeight) 190 { 191 if(((Ffn)o)._chs == _chs) 192 { 193 if(((Ffn)o)._ixchSzAlt == _ixchSzAlt) 194 { 195 if(Arrays.equals(((Ffn)o)._panose,_panose)) 196 { 197 if(Arrays.equals(((Ffn)o)._fontSig,_fontSig)) 198 { 199 if(!(Arrays.equals(((Ffn)o)._xszFfn,_xszFfn))) 200 retVal = false; 201 } 202 else 203 retVal = false; 204 } 205 else 206 retVal = false; 207 } 208 else 209 retVal = false; 210 } 211 else 212 retVal = false; 213 } 214 else 215 retVal = false; 216 } 217 else 218 retVal = false; 219 } 220 else 221 retVal = false; 222 223 return retVal; 224 } 225 226 227 } 228 229 230 | Popular Tags |