KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hwpf > model > Ffn


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

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 JavaDoc;
24
25 /**
26  * FFN - Font Family Name. FFN is a data structure that stores the names of the Main
27  * Font and that of Alternate font as an array of characters. It has also a header
28  * that stores info about the whole structure and the fonts
29  *
30  * @author Praveen Mathew
31  */

32 public class Ffn
33 {
34   private int _cbFfnM1;//total length of FFN - 1.
35
private byte _info;
36     private static BitField _prq = new BitField(0x0003);// pitch request
37
private static BitField _fTrueType = new BitField(0x0004);// when 1, font is a TrueType font
38
private static BitField _ff = new BitField(0x0070);
39   private short _wWeight;// base weight of font
40
private byte _chs;// character set identifier
41
private byte _ixchSzAlt; // index into ffn.szFfn to the name of
42
// the alternate font
43
private byte [] _panose = new byte[10];//????
44
private byte [] _fontSig = new byte[24];//????
45

46   // zero terminated string that records name of font, cuurently not
47
// supporting Extended chars
48
private char [] _xszFfn;
49
50   // extra facilitator members
51
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     // read panose and fs so we can write them back out.
69
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 JavaDoc 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 JavaDoc(_xszFfn, 0, index);
128   }
129
130   public String JavaDoc 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 JavaDoc(_xszFfn, _ixchSzAlt, index);
141
142   }
143
144   public void set_cbFfnM1(int _cbFfnM1)
145   {
146     this._cbFfnM1 = _cbFfnM1;
147   }
148
149   // changed protected to public
150
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 JavaDoc 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