sl@0
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "FONTCOMP.H"
|
sl@0
|
17 |
|
sl@0
|
18 |
FscRead::FscRead(fstream& aFile,FontCompiler& aFontCompiler,Fxf* aFxf):
|
sl@0
|
19 |
FontRead(aFile,aFontCompiler,aFxf)
|
sl@0
|
20 |
{}
|
sl@0
|
21 |
|
sl@0
|
22 |
int FscRead::DoCom(int aSecondPass)
|
sl@0
|
23 |
/*
|
sl@0
|
24 |
Takes a command and takes appropriate action
|
sl@0
|
25 |
Returns -ve if an error occured
|
sl@0
|
26 |
0 for OKAY
|
sl@0
|
27 |
+ve number for new current character number
|
sl@0
|
28 |
*/
|
sl@0
|
29 |
{
|
sl@0
|
30 |
int ret=0,num=0,neg=0;
|
sl@0
|
31 |
int i=0;
|
sl@0
|
32 |
for (;i<iInputBufLen;i++)
|
sl@0
|
33 |
{
|
sl@0
|
34 |
char chr=iInputBuf[i];
|
sl@0
|
35 |
if (num==0 && chr=='-')
|
sl@0
|
36 |
neg=1;
|
sl@0
|
37 |
else if (chr>='0' && chr<='9')
|
sl@0
|
38 |
num=num*10+chr-'0';
|
sl@0
|
39 |
}
|
sl@0
|
40 |
if (neg)
|
sl@0
|
41 |
num= -num;
|
sl@0
|
42 |
if (iInputBuf[1]=='c')
|
sl@0
|
43 |
return(num);
|
sl@0
|
44 |
if (aSecondPass)
|
sl@0
|
45 |
ret=0;
|
sl@0
|
46 |
else switch(iInputBuf[1])
|
sl@0
|
47 |
{
|
sl@0
|
48 |
case 'd':
|
sl@0
|
49 |
iFxf->descent=num;
|
sl@0
|
50 |
break;
|
sl@0
|
51 |
case 'a':
|
sl@0
|
52 |
iFxf->nominal_ascent=num;
|
sl@0
|
53 |
break;
|
sl@0
|
54 |
case 'm':
|
sl@0
|
55 |
iFxf->max_info_width=num;
|
sl@0
|
56 |
break;
|
sl@0
|
57 |
case 'h':
|
sl@0
|
58 |
if ((iFxf->cell_height=num)>MAX_HEIGHT)
|
sl@0
|
59 |
ret=Parameter;
|
sl@0
|
60 |
if (iFxf->nominal_ascent==0)
|
sl@0
|
61 |
iFxf->nominal_ascent=iFxf->cell_height-iFxf->descent;
|
sl@0
|
62 |
break;
|
sl@0
|
63 |
case 'n': /* Font data label name */
|
sl@0
|
64 |
{
|
sl@0
|
65 |
int pos=0;
|
sl@0
|
66 |
while(iInputBuf[pos]!=' ')
|
sl@0
|
67 |
pos++;
|
sl@0
|
68 |
while(iInputBuf[pos]==' ')
|
sl@0
|
69 |
pos++;
|
sl@0
|
70 |
if(iInputBufLen-pos>FONT_NAME_LEN)
|
sl@0
|
71 |
return(FileFormat);
|
sl@0
|
72 |
memcpy(iFxf->name,&iInputBuf[pos],iInputBufLen-pos);
|
sl@0
|
73 |
(iFxf->name)[iInputBufLen-pos]=0;
|
sl@0
|
74 |
}
|
sl@0
|
75 |
break;
|
sl@0
|
76 |
case 't': /* Font data typeface */
|
sl@0
|
77 |
{
|
sl@0
|
78 |
int pos=0;
|
sl@0
|
79 |
while(iInputBuf[pos]!=' ')
|
sl@0
|
80 |
pos++;
|
sl@0
|
81 |
while(iInputBuf[pos]==' ')
|
sl@0
|
82 |
pos++;
|
sl@0
|
83 |
if(iInputBufLen-pos>FONT_NAME_LEN)
|
sl@0
|
84 |
return(FileFormat);
|
sl@0
|
85 |
memcpy(iFxf->typeface,&iInputBuf[pos],iInputBufLen-pos);
|
sl@0
|
86 |
(iFxf->typeface)[iInputBufLen-pos]=0;
|
sl@0
|
87 |
}
|
sl@0
|
88 |
break;
|
sl@0
|
89 |
case 'b':
|
sl@0
|
90 |
iFxf->iBold=1;
|
sl@0
|
91 |
break;
|
sl@0
|
92 |
case 'i':
|
sl@0
|
93 |
iFxf->iItalic=1;
|
sl@0
|
94 |
break;
|
sl@0
|
95 |
case 'f':
|
sl@0
|
96 |
// not a lot
|
sl@0
|
97 |
break;
|
sl@0
|
98 |
case 'v':
|
sl@0
|
99 |
iFxf->iUid=num;
|
sl@0
|
100 |
break;
|
sl@0
|
101 |
case 'o':
|
sl@0
|
102 |
iOverHang=num;
|
sl@0
|
103 |
break;
|
sl@0
|
104 |
case 'u':
|
sl@0
|
105 |
iUnderHang=num;
|
sl@0
|
106 |
break;
|
sl@0
|
107 |
default:
|
sl@0
|
108 |
ret=FileFormat;
|
sl@0
|
109 |
break;
|
sl@0
|
110 |
}
|
sl@0
|
111 |
return(ret);
|
sl@0
|
112 |
}
|
sl@0
|
113 |
|
sl@0
|
114 |
char* FscRead::ScanLine(int& aLen)
|
sl@0
|
115 |
/* Scan the input line for the first '0' or '1' character and return a descriptor pointing to it,
|
sl@0
|
116 |
returns a zero length descriptor if not found.
|
sl@0
|
117 |
*/
|
sl@0
|
118 |
{
|
sl@0
|
119 |
aLen=0;
|
sl@0
|
120 |
if((iInputBuf[0]!='0' && iInputBuf[0]!='1') || iInputBufLen==0)
|
sl@0
|
121 |
return(NULL);
|
sl@0
|
122 |
while(iInputBuf[aLen]=='0' || iInputBuf[aLen]=='1')
|
sl@0
|
123 |
aLen++;
|
sl@0
|
124 |
return(iInputBuf);
|
sl@0
|
125 |
}
|
sl@0
|
126 |
|
sl@0
|
127 |
|
sl@0
|
128 |
int FscRead::ReadLine()
|
sl@0
|
129 |
{
|
sl@0
|
130 |
int pos=0;
|
sl@0
|
131 |
while(iFileBuf[iFileBufPos+pos]!='\n' && iFileBufPos+pos<iFileBufLen)
|
sl@0
|
132 |
pos++;
|
sl@0
|
133 |
if(iFileBufPos+pos==iFileBufLen) return(1);
|
sl@0
|
134 |
memcpy(iInputBuf,&iFileBuf[iFileBufPos],pos);
|
sl@0
|
135 |
iInputBufLen=pos-1;
|
sl@0
|
136 |
iFileBufPos+=pos+1;
|
sl@0
|
137 |
if(iFileBufPos>=iFileBufLen) return(1);
|
sl@0
|
138 |
return(0);
|
sl@0
|
139 |
}
|
sl@0
|
140 |
|
sl@0
|
141 |
FontRead::FontRead(fstream& aFile,FontCompiler& aFontCompiler,Fxf* aFxf):
|
sl@0
|
142 |
iInputFile(aFile),
|
sl@0
|
143 |
iFontCompiler(&aFontCompiler),
|
sl@0
|
144 |
iFxf(aFxf)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
}
|
sl@0
|
147 |
|
sl@0
|
148 |
int FscRead::ReadFont()
|
sl@0
|
149 |
{
|
sl@0
|
150 |
iInputFile.seekg(0,ios::end);
|
sl@0
|
151 |
iFileBufLen=iInputFile.tellg();
|
sl@0
|
152 |
iInputFile.seekg(0);
|
sl@0
|
153 |
iFileBufPos=0;
|
sl@0
|
154 |
iFileBuf=new char[iFileBufLen];
|
sl@0
|
155 |
iInputFile.read(iFileBuf,iFileBufLen);
|
sl@0
|
156 |
int ret=Pass1();
|
sl@0
|
157 |
if(ret) return(ret);
|
sl@0
|
158 |
return(Pass2());
|
sl@0
|
159 |
}
|
sl@0
|
160 |
|
sl@0
|
161 |
int FscRead::Pass1()
|
sl@0
|
162 |
{
|
sl@0
|
163 |
int n_row=0; // counts row in character picture
|
sl@0
|
164 |
int ret=0;
|
sl@0
|
165 |
int specChr=0;
|
sl@0
|
166 |
int isCharBody=0;
|
sl@0
|
167 |
int lastLine=0;
|
sl@0
|
168 |
int widthofi=0;
|
sl@0
|
169 |
int widthofM=0;
|
sl@0
|
170 |
|
sl@0
|
171 |
iFxf->MaxChrWidth=0;
|
sl@0
|
172 |
iFxf->cell_height=0;
|
sl@0
|
173 |
iFxf->UlinePos=0;
|
sl@0
|
174 |
iFxf->UlineThickness=0;
|
sl@0
|
175 |
iFxf->nominal_ascent=0;
|
sl@0
|
176 |
iFxf->descent=0;
|
sl@0
|
177 |
iFxf->chr_seg=0;
|
sl@0
|
178 |
iFxf->FirstChr=0;
|
sl@0
|
179 |
iFxf->n_chars=0;
|
sl@0
|
180 |
iFxf->max_info_width=0;
|
sl@0
|
181 |
iFxf->flags=0;
|
sl@0
|
182 |
iFxf->special=0;
|
sl@0
|
183 |
iFxf->ByteWid=0;
|
sl@0
|
184 |
iFxf->UseWords=0;
|
sl@0
|
185 |
iFxf->iBold=0;
|
sl@0
|
186 |
iFxf->iItalic=0;
|
sl@0
|
187 |
iFxf->iProportional=0;
|
sl@0
|
188 |
iFxf->iSerif=0;
|
sl@0
|
189 |
iFxf->iSymbol=0;
|
sl@0
|
190 |
iFxf->iUid=0;
|
sl@0
|
191 |
|
sl@0
|
192 |
iUnderHang=0;
|
sl@0
|
193 |
iOverHang=0;
|
sl@0
|
194 |
iChar=new FcmCharHead[MAX_CHARS];
|
sl@0
|
195 |
for(int letter=0;letter<MAX_CHARS;letter++)
|
sl@0
|
196 |
iFxf->chr[letter]=NULL;
|
sl@0
|
197 |
//**************************************************
|
sl@0
|
198 |
// First pass. Read header info & character widths *
|
sl@0
|
199 |
//**************************************************
|
sl@0
|
200 |
do
|
sl@0
|
201 |
{
|
sl@0
|
202 |
int width=0; // width of current character picture
|
sl@0
|
203 |
|
sl@0
|
204 |
lastLine=ReadLine();
|
sl@0
|
205 |
isCharBody=0;
|
sl@0
|
206 |
if (iInputBufLen>0 && iInputBuf[0]=='*')
|
sl@0
|
207 |
{
|
sl@0
|
208 |
if ((ret=DoCom(0))<0)
|
sl@0
|
209 |
return(FileFormat);
|
sl@0
|
210 |
else if (ret)
|
sl@0
|
211 |
{
|
sl@0
|
212 |
for(;iFxf->n_chars<ret;iFxf->n_chars++)
|
sl@0
|
213 |
iFxf->chr[iFxf->n_chars]=NULL;
|
sl@0
|
214 |
specChr=iFxf->n_chars;
|
sl@0
|
215 |
}
|
sl@0
|
216 |
}
|
sl@0
|
217 |
else
|
sl@0
|
218 |
{
|
sl@0
|
219 |
int len=0;
|
sl@0
|
220 |
char* ptr=ScanLine(len);
|
sl@0
|
221 |
if (len)
|
sl@0
|
222 |
{
|
sl@0
|
223 |
isCharBody=1;
|
sl@0
|
224 |
if (iFxf->FirstChr<0)
|
sl@0
|
225 |
iFxf->FirstChr=iFxf->n_chars;
|
sl@0
|
226 |
if (n_row==0)
|
sl@0
|
227 |
{
|
sl@0
|
228 |
for (width=0;width<len && (ptr[width]=='0' || ptr[width]=='1');width++);
|
sl@0
|
229 |
if (iFxf->n_chars>255)
|
sl@0
|
230 |
return(FileFormat);
|
sl@0
|
231 |
iFxf->chr[iFxf->n_chars]=iChar;
|
sl@0
|
232 |
iFxf->n_chars++;
|
sl@0
|
233 |
iChar->xOffset= -iUnderHang;
|
sl@0
|
234 |
iChar->width=width;
|
sl@0
|
235 |
iChar->ByteWid=((iChar->width+15)>>3)&(~1);
|
sl@0
|
236 |
iChar->move=width-iUnderHang-iOverHang;
|
sl@0
|
237 |
if(iFxf->n_chars=='i')
|
sl@0
|
238 |
widthofi=iChar->move;
|
sl@0
|
239 |
else if(iFxf->n_chars=='M')
|
sl@0
|
240 |
widthofM=iChar->move;
|
sl@0
|
241 |
iUnderHang=0;
|
sl@0
|
242 |
iOverHang=0;
|
sl@0
|
243 |
if (width>iFxf->MaxChrWidth)
|
sl@0
|
244 |
iFxf->MaxChrWidth=width;
|
sl@0
|
245 |
}
|
sl@0
|
246 |
n_row++;
|
sl@0
|
247 |
}
|
sl@0
|
248 |
}
|
sl@0
|
249 |
if ((n_row!=0 && !isCharBody) || (lastLine && isCharBody))
|
sl@0
|
250 |
{
|
sl@0
|
251 |
if (n_row>iFxf->cell_height)
|
sl@0
|
252 |
return(FileFormat);
|
sl@0
|
253 |
iChar->height=n_row;
|
sl@0
|
254 |
iChar->yOffset=iFxf->cell_height-iFxf->descent;
|
sl@0
|
255 |
specChr++;
|
sl@0
|
256 |
n_row=0;
|
sl@0
|
257 |
width=0;
|
sl@0
|
258 |
iChar++;
|
sl@0
|
259 |
}
|
sl@0
|
260 |
} while(!lastLine);
|
sl@0
|
261 |
if (iFxf->cell_height==0)
|
sl@0
|
262 |
return(FileFormat);
|
sl@0
|
263 |
if(widthofi && widthofM)
|
sl@0
|
264 |
iFxf->iProportional=(widthofi!=widthofM);
|
sl@0
|
265 |
return(NoError);
|
sl@0
|
266 |
}
|
sl@0
|
267 |
|
sl@0
|
268 |
int FscRead::Pass2()
|
sl@0
|
269 |
/******************************************************/
|
sl@0
|
270 |
/* Second pass. Read in actual picture data this time */
|
sl@0
|
271 |
/******************************************************/
|
sl@0
|
272 |
{
|
sl@0
|
273 |
unsigned int bit; // Used to set bits in pic
|
sl@0
|
274 |
int ret,chNum;
|
sl@0
|
275 |
int n_row; // counts row in character picture
|
sl@0
|
276 |
int offset=0;
|
sl@0
|
277 |
int isCharBody;
|
sl@0
|
278 |
int lastLine;
|
sl@0
|
279 |
|
sl@0
|
280 |
iFileBufPos=0;
|
sl@0
|
281 |
n_row=0;
|
sl@0
|
282 |
chNum=0;
|
sl@0
|
283 |
do {
|
sl@0
|
284 |
lastLine=ReadLine();
|
sl@0
|
285 |
isCharBody=0;
|
sl@0
|
286 |
if (iInputBufLen>0 && iInputBuf[0]=='*')
|
sl@0
|
287 |
{
|
sl@0
|
288 |
if ((ret=DoCom(1))>0)
|
sl@0
|
289 |
{
|
sl@0
|
290 |
if (ret<chNum)
|
sl@0
|
291 |
return(FileFormat);
|
sl@0
|
292 |
chNum=ret;
|
sl@0
|
293 |
}
|
sl@0
|
294 |
}
|
sl@0
|
295 |
else
|
sl@0
|
296 |
{
|
sl@0
|
297 |
int len=0;
|
sl@0
|
298 |
char* ptr=ScanLine(len);
|
sl@0
|
299 |
if (len)
|
sl@0
|
300 |
{
|
sl@0
|
301 |
isCharBody=1;
|
sl@0
|
302 |
if (n_row==0)
|
sl@0
|
303 |
{
|
sl@0
|
304 |
iChar=iFxf->chr[chNum];
|
sl@0
|
305 |
chNum++;
|
sl@0
|
306 |
}
|
sl@0
|
307 |
unsigned short int* pDest=(unsigned short int*)(iFontCompiler->FontStore()+offset+iChar->ByteWid*n_row);
|
sl@0
|
308 |
bit=1;
|
sl@0
|
309 |
*pDest=0;
|
sl@0
|
310 |
for (int width=0;width<len && (ptr[width]=='0' || ptr[width]=='1');width++)
|
sl@0
|
311 |
{
|
sl@0
|
312 |
if (ptr[width]=='1')
|
sl@0
|
313 |
*pDest|=bit;
|
sl@0
|
314 |
if (bit==0x8000)
|
sl@0
|
315 |
{
|
sl@0
|
316 |
bit=1;
|
sl@0
|
317 |
pDest++;
|
sl@0
|
318 |
*pDest=0;
|
sl@0
|
319 |
}
|
sl@0
|
320 |
else
|
sl@0
|
321 |
bit<<=1;
|
sl@0
|
322 |
}
|
sl@0
|
323 |
n_row++;
|
sl@0
|
324 |
}
|
sl@0
|
325 |
}
|
sl@0
|
326 |
if ((n_row!=0 && !isCharBody) || (lastLine && isCharBody))
|
sl@0
|
327 |
{
|
sl@0
|
328 |
iChar->offset=offset;
|
sl@0
|
329 |
offset+=iChar->ByteWid*n_row;
|
sl@0
|
330 |
n_row=0;
|
sl@0
|
331 |
}
|
sl@0
|
332 |
} while(!lastLine);
|
sl@0
|
333 |
return(NoError);
|
sl@0
|
334 |
}
|