1 2 17 18 19 package org.apache.poi.hwpf.model; 20 21 import java.io.IOException ; 22 import org.apache.poi.hwpf.model.io.HWPFFileSystem; 23 import org.apache.poi.hwpf.model.io.HWPFOutputStream; 24 import org.apache.poi.util.LittleEndian; 25 26 34 public class FontTable 35 { 36 private short _stringCount; private short _extraDataSz; 39 private int lcbSttbfffn; private int fcSttbfffn; 43 private Ffn[] _fontNames = null; 45 46 47 public FontTable(byte[] buf, int offset, int lcbSttbfffn) 48 { 49 this.lcbSttbfffn = lcbSttbfffn; 50 this.fcSttbfffn = offset; 51 52 _stringCount = LittleEndian.getShort(buf, offset); 53 offset += LittleEndian.SHORT_SIZE; 54 _extraDataSz = LittleEndian.getShort(buf, offset); 55 offset += LittleEndian.SHORT_SIZE; 56 57 _fontNames = new Ffn[_stringCount]; 59 for(int i = 0;i<_stringCount; i++) 60 { 61 _fontNames[i] = new Ffn(buf,offset); 62 offset += _fontNames[i].getSize(); 63 } 64 } 65 66 public short getStringCount() 67 { 68 return _stringCount; 69 } 70 71 public short getExtraDataSz() 72 { 73 return _extraDataSz; 74 } 75 76 public Ffn[] getFontNames() 77 { 78 return _fontNames; 79 } 80 81 public int getSize() 82 { 83 return lcbSttbfffn; 84 } 85 86 public String getMainFont(int chpFtc ) 87 { 88 if(chpFtc >= _stringCount) 89 { 90 System.out.println("Mismatch in chpFtc with stringCount"); 91 return null; 92 } 93 94 return _fontNames[chpFtc].getMainFontName(); 95 } 96 97 public String getAltFont(int chpFtc ) 98 { 99 if(chpFtc >= _stringCount) 100 { 101 System.out.println("Mismatch in chpFtc with stringCount"); 102 return null; 103 } 104 105 return _fontNames[chpFtc].getAltFontName(); 106 } 107 108 public void setStringCount(short stringCount) 109 { 110 this._stringCount = stringCount; 111 } 112 113 public void writeTo(HWPFFileSystem sys) 114 throws IOException 115 { 116 HWPFOutputStream tableStream = sys.getStream("1Table"); 117 118 byte[] buf = new byte[LittleEndian.SHORT_SIZE]; 119 LittleEndian.putShort(buf, _stringCount); 120 tableStream.write(buf); 121 LittleEndian.putShort(buf, _extraDataSz); 122 tableStream.write(buf); 123 124 for(int i = 0; i < _fontNames.length; i++) 125 { 126 tableStream.write(_fontNames[i].toByteArray()); 127 } 128 129 } 130 131 public boolean equals(Object o) 132 { 133 boolean retVal = true; 134 135 if(((FontTable)o).getStringCount() == _stringCount) 136 { 137 if(((FontTable)o).getExtraDataSz() == _extraDataSz) 138 { 139 Ffn[] fontNamesNew = ((FontTable)o).getFontNames(); 140 for(int i = 0;i<_stringCount; i++) 141 { 142 if(!(_fontNames[i].equals(fontNamesNew[i]))) 143 retVal = false; 144 } 145 } 146 else 147 retVal = false; 148 } 149 else 150 retVal = false; 151 152 153 return retVal; 154 } 155 156 157 158 } 159 160 161 | Popular Tags |