1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hwpf.model;
import java.util.Arrays;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian;
/**
* FFN - Font Family Name. FFN is a data structure that stores the names of the Main
* Font and that of Alternate font as an array of characters. It has also a header
* that stores info about the whole structure and the fonts
*
* @author Praveen Mathew
*/
@Internal
public final class Ffn
{
private int _cbFfnM1;//total length of FFN - 1.
private byte _info;
private static BitField _prq = BitFieldFactory.getInstance(0x0003);// pitch request
private static BitField _fTrueType = BitFieldFactory.getInstance(0x0004);// when 1, font is a TrueType font
private static BitField _ff = BitFieldFactory.getInstance(0x0070);
private short _wWeight;// base weight of font
private byte _chs;// character set identifier
private byte _ixchSzAlt; // index into ffn.szFfn to the name of
// the alternate font
private byte [] _panose = new byte[10];//????
private byte [] _fontSig = new byte[24];//????
// zero terminated string that records name of font, cuurently not
// supporting Extended chars
private char [] _xszFfn;
// extra facilitator members
private int _xszFfnLength;
public Ffn(byte[] buf, int offset)
{
int offsetTmp = offset;
_cbFfnM1 = LittleEndian.getUnsignedByte(buf,offset);
offset += LittleEndian.BYTE_SIZE;
_info = buf[offset];
offset += LittleEndian.BYTE_SIZE;
_wWeight = LittleEndian.getShort(buf, offset);
offset += LittleEndian.SHORT_SIZE;
_chs = buf[offset];
offset += LittleEndian.BYTE_SIZE;
_ixchSzAlt = buf[offset];
offset += LittleEndian.BYTE_SIZE;
// read panose and fs so we can write them back out.
System.arraycopy(buf, offset, _panose, 0, _panose.length);
offset += _panose.length;
System.arraycopy(buf, offset, _fontSig, 0, _fontSig.length);
offset += _fontSig.length;
offsetTmp = offset - offsetTmp;
_xszFfnLength = (this.getSize() - offsetTmp)/2;
_xszFfn = new char[_xszFfnLength];
for(int i = 0; i < _xszFfnLength; i++)
{
_xszFfn[i] = (char)LittleEndian.getShort(buf, offset);
offset += LittleEndian.SHORT_SIZE;
}
}
public int get_cbFfnM1()
{
return _cbFfnM1;
}
public short getWeight()
{
return _wWeight;
}
public byte getChs()
{
return _chs;
}
public byte [] getPanose()
{
return _panose;
}
public byte [] getFontSig()
{
return _fontSig;
}
public int getSize()
{
return (_cbFfnM1 + 1);
}
public String getMainFontName()
{
int index = 0;
for (;index < _xszFfnLength; index++)
{
if (_xszFfn[index] == '\0')
{
break;
}
}
return new String(_xszFfn, 0, index);
}
public String getAltFontName()
{
int index = _ixchSzAlt;
for (;index < _xszFfnLength; index++)
{
if (_xszFfn[index] == '\0')
{
break;
}
}
return new String(_xszFfn, _ixchSzAlt, index);
}
public void set_cbFfnM1(int _cbFfnM1)
{
this._cbFfnM1 = _cbFfnM1;
}
// changed protected to public
public byte[] toByteArray()
{
int offset = 0;
byte[] buf = new byte[this.getSize()];
buf[offset] = (byte)_cbFfnM1;
offset += LittleEndian.BYTE_SIZE;
buf[offset] = _info;
offset += LittleEndian.BYTE_SIZE;
LittleEndian.putShort(buf, offset, _wWeight);
offset += LittleEndian.SHORT_SIZE;
buf[offset] = _chs;
offset += LittleEndian.BYTE_SIZE;
buf[offset] = _ixchSzAlt;
offset += LittleEndian.BYTE_SIZE;
System.arraycopy(_panose,0,buf, offset,_panose.length);
offset += _panose.length;
System.arraycopy(_fontSig,0,buf, offset, _fontSig.length);
offset += _fontSig.length;
for(int i = 0; i < _xszFfn.length; i++)
{
LittleEndian.putShort(buf, offset, (short)_xszFfn[i]);
offset += LittleEndian.SHORT_SIZE;
}
return buf;
}
@Override
public boolean equals(Object o)
{
boolean retVal = true;
if (((Ffn)o).get_cbFfnM1() == _cbFfnM1)
{
if(((Ffn)o)._info == _info)
{
if(((Ffn)o)._wWeight == _wWeight)
{
if(((Ffn)o)._chs == _chs)
{
if(((Ffn)o)._ixchSzAlt == _ixchSzAlt)
{
if(Arrays.equals(((Ffn)o)._panose,_panose))
{
if(Arrays.equals(((Ffn)o)._fontSig,_fontSig))
{
if(!(Arrays.equals(((Ffn)o)._xszFfn,_xszFfn)))
retVal = false;
}
else
retVal = false;
}
else
retVal = false;
}
else
retVal = false;
}
else
retVal = false;
}
else
retVal = false;
}
else
retVal = false;
}
else
retVal = false;
return retVal;
}
@Override
public int hashCode() {
assert false : "hashCode not designed";
return 42; // any arbitrary constant will do
}
}
|