First public contribution.
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 FscRead::FscRead(fstream& aFile,FontCompiler& aFontCompiler,Fxf* aFxf):
19 FontRead(aFile,aFontCompiler,aFxf)
22 int FscRead::DoCom(int aSecondPass)
24 Takes a command and takes appropriate action
25 Returns -ve if an error occured
27 +ve number for new current character number
30 int ret=0,num=0,neg=0;
32 for (;i<iInputBufLen;i++)
34 char chr=iInputBuf[i];
35 if (num==0 && chr=='-')
37 else if (chr>='0' && chr<='9')
42 if (iInputBuf[1]=='c')
46 else switch(iInputBuf[1])
52 iFxf->nominal_ascent=num;
55 iFxf->max_info_width=num;
58 if ((iFxf->cell_height=num)>MAX_HEIGHT)
60 if (iFxf->nominal_ascent==0)
61 iFxf->nominal_ascent=iFxf->cell_height-iFxf->descent;
63 case 'n': /* Font data label name */
66 while(iInputBuf[pos]!=' ')
68 while(iInputBuf[pos]==' ')
70 if(iInputBufLen-pos>FONT_NAME_LEN)
72 memcpy(iFxf->name,&iInputBuf[pos],iInputBufLen-pos);
73 (iFxf->name)[iInputBufLen-pos]=0;
76 case 't': /* Font data typeface */
79 while(iInputBuf[pos]!=' ')
81 while(iInputBuf[pos]==' ')
83 if(iInputBufLen-pos>FONT_NAME_LEN)
85 memcpy(iFxf->typeface,&iInputBuf[pos],iInputBufLen-pos);
86 (iFxf->typeface)[iInputBufLen-pos]=0;
114 char* FscRead::ScanLine(int& aLen)
115 /* Scan the input line for the first '0' or '1' character and return a descriptor pointing to it,
116 returns a zero length descriptor if not found.
120 if((iInputBuf[0]!='0' && iInputBuf[0]!='1') || iInputBufLen==0)
122 while(iInputBuf[aLen]=='0' || iInputBuf[aLen]=='1')
128 int FscRead::ReadLine()
131 while(iFileBuf[iFileBufPos+pos]!='\n' && iFileBufPos+pos<iFileBufLen)
133 if(iFileBufPos+pos==iFileBufLen) return(1);
134 memcpy(iInputBuf,&iFileBuf[iFileBufPos],pos);
137 if(iFileBufPos>=iFileBufLen) return(1);
141 FontRead::FontRead(fstream& aFile,FontCompiler& aFontCompiler,Fxf* aFxf):
143 iFontCompiler(&aFontCompiler),
148 int FscRead::ReadFont()
150 iInputFile.seekg(0,ios::end);
151 iFileBufLen=iInputFile.tellg();
154 iFileBuf=new char[iFileBufLen];
155 iInputFile.read(iFileBuf,iFileBufLen);
163 int n_row=0; // counts row in character picture
174 iFxf->UlineThickness=0;
175 iFxf->nominal_ascent=0;
180 iFxf->max_info_width=0;
187 iFxf->iProportional=0;
194 iChar=new FcmCharHead[MAX_CHARS];
195 for(int letter=0;letter<MAX_CHARS;letter++)
196 iFxf->chr[letter]=NULL;
197 //**************************************************
198 // First pass. Read header info & character widths *
199 //**************************************************
202 int width=0; // width of current character picture
206 if (iInputBufLen>0 && iInputBuf[0]=='*')
208 if ((ret=DoCom(0))<0)
212 for(;iFxf->n_chars<ret;iFxf->n_chars++)
213 iFxf->chr[iFxf->n_chars]=NULL;
214 specChr=iFxf->n_chars;
220 char* ptr=ScanLine(len);
224 if (iFxf->FirstChr<0)
225 iFxf->FirstChr=iFxf->n_chars;
228 for (width=0;width<len && (ptr[width]=='0' || ptr[width]=='1');width++);
229 if (iFxf->n_chars>255)
231 iFxf->chr[iFxf->n_chars]=iChar;
233 iChar->xOffset= -iUnderHang;
235 iChar->ByteWid=((iChar->width+15)>>3)&(~1);
236 iChar->move=width-iUnderHang-iOverHang;
237 if(iFxf->n_chars=='i')
238 widthofi=iChar->move;
239 else if(iFxf->n_chars=='M')
240 widthofM=iChar->move;
243 if (width>iFxf->MaxChrWidth)
244 iFxf->MaxChrWidth=width;
249 if ((n_row!=0 && !isCharBody) || (lastLine && isCharBody))
251 if (n_row>iFxf->cell_height)
254 iChar->yOffset=iFxf->cell_height-iFxf->descent;
261 if (iFxf->cell_height==0)
263 if(widthofi && widthofM)
264 iFxf->iProportional=(widthofi!=widthofM);
269 /******************************************************/
270 /* Second pass. Read in actual picture data this time */
271 /******************************************************/
273 unsigned int bit; // Used to set bits in pic
275 int n_row; // counts row in character picture
286 if (iInputBufLen>0 && iInputBuf[0]=='*')
288 if ((ret=DoCom(1))>0)
298 char* ptr=ScanLine(len);
304 iChar=iFxf->chr[chNum];
307 unsigned short int* pDest=(unsigned short int*)(iFontCompiler->FontStore()+offset+iChar->ByteWid*n_row);
310 for (int width=0;width<len && (ptr[width]=='0' || ptr[width]=='1');width++)
326 if ((n_row!=0 && !isCharBody) || (lastLine && isCharBody))
328 iChar->offset=offset;
329 offset+=iChar->ByteWid*n_row;