sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "FONTCOMP.H" sl@0: sl@0: FscRead::FscRead(fstream& aFile,FontCompiler& aFontCompiler,Fxf* aFxf): sl@0: FontRead(aFile,aFontCompiler,aFxf) sl@0: {} sl@0: sl@0: int FscRead::DoCom(int aSecondPass) sl@0: /* sl@0: Takes a command and takes appropriate action sl@0: Returns -ve if an error occured sl@0: 0 for OKAY sl@0: +ve number for new current character number sl@0: */ sl@0: { sl@0: int ret=0,num=0,neg=0; sl@0: int i=0; sl@0: for (;i='0' && chr<='9') sl@0: num=num*10+chr-'0'; sl@0: } sl@0: if (neg) sl@0: num= -num; sl@0: if (iInputBuf[1]=='c') sl@0: return(num); sl@0: if (aSecondPass) sl@0: ret=0; sl@0: else switch(iInputBuf[1]) sl@0: { sl@0: case 'd': sl@0: iFxf->descent=num; sl@0: break; sl@0: case 'a': sl@0: iFxf->nominal_ascent=num; sl@0: break; sl@0: case 'm': sl@0: iFxf->max_info_width=num; sl@0: break; sl@0: case 'h': sl@0: if ((iFxf->cell_height=num)>MAX_HEIGHT) sl@0: ret=Parameter; sl@0: if (iFxf->nominal_ascent==0) sl@0: iFxf->nominal_ascent=iFxf->cell_height-iFxf->descent; sl@0: break; sl@0: case 'n': /* Font data label name */ sl@0: { sl@0: int pos=0; sl@0: while(iInputBuf[pos]!=' ') sl@0: pos++; sl@0: while(iInputBuf[pos]==' ') sl@0: pos++; sl@0: if(iInputBufLen-pos>FONT_NAME_LEN) sl@0: return(FileFormat); sl@0: memcpy(iFxf->name,&iInputBuf[pos],iInputBufLen-pos); sl@0: (iFxf->name)[iInputBufLen-pos]=0; sl@0: } sl@0: break; sl@0: case 't': /* Font data typeface */ sl@0: { sl@0: int pos=0; sl@0: while(iInputBuf[pos]!=' ') sl@0: pos++; sl@0: while(iInputBuf[pos]==' ') sl@0: pos++; sl@0: if(iInputBufLen-pos>FONT_NAME_LEN) sl@0: return(FileFormat); sl@0: memcpy(iFxf->typeface,&iInputBuf[pos],iInputBufLen-pos); sl@0: (iFxf->typeface)[iInputBufLen-pos]=0; sl@0: } sl@0: break; sl@0: case 'b': sl@0: iFxf->iBold=1; sl@0: break; sl@0: case 'i': sl@0: iFxf->iItalic=1; sl@0: break; sl@0: case 'f': sl@0: // not a lot sl@0: break; sl@0: case 'v': sl@0: iFxf->iUid=num; sl@0: break; sl@0: case 'o': sl@0: iOverHang=num; sl@0: break; sl@0: case 'u': sl@0: iUnderHang=num; sl@0: break; sl@0: default: sl@0: ret=FileFormat; sl@0: break; sl@0: } sl@0: return(ret); sl@0: } sl@0: sl@0: char* FscRead::ScanLine(int& aLen) sl@0: /* Scan the input line for the first '0' or '1' character and return a descriptor pointing to it, sl@0: returns a zero length descriptor if not found. sl@0: */ sl@0: { sl@0: aLen=0; sl@0: if((iInputBuf[0]!='0' && iInputBuf[0]!='1') || iInputBufLen==0) sl@0: return(NULL); sl@0: while(iInputBuf[aLen]=='0' || iInputBuf[aLen]=='1') sl@0: aLen++; sl@0: return(iInputBuf); sl@0: } sl@0: sl@0: sl@0: int FscRead::ReadLine() sl@0: { sl@0: int pos=0; sl@0: while(iFileBuf[iFileBufPos+pos]!='\n' && iFileBufPos+pos=iFileBufLen) return(1); sl@0: return(0); sl@0: } sl@0: sl@0: FontRead::FontRead(fstream& aFile,FontCompiler& aFontCompiler,Fxf* aFxf): sl@0: iInputFile(aFile), sl@0: iFontCompiler(&aFontCompiler), sl@0: iFxf(aFxf) sl@0: { sl@0: } sl@0: sl@0: int FscRead::ReadFont() sl@0: { sl@0: iInputFile.seekg(0,ios::end); sl@0: iFileBufLen=iInputFile.tellg(); sl@0: iInputFile.seekg(0); sl@0: iFileBufPos=0; sl@0: iFileBuf=new char[iFileBufLen]; sl@0: iInputFile.read(iFileBuf,iFileBufLen); sl@0: int ret=Pass1(); sl@0: if(ret) return(ret); sl@0: return(Pass2()); sl@0: } sl@0: sl@0: int FscRead::Pass1() sl@0: { sl@0: int n_row=0; // counts row in character picture sl@0: int ret=0; sl@0: int specChr=0; sl@0: int isCharBody=0; sl@0: int lastLine=0; sl@0: int widthofi=0; sl@0: int widthofM=0; sl@0: sl@0: iFxf->MaxChrWidth=0; sl@0: iFxf->cell_height=0; sl@0: iFxf->UlinePos=0; sl@0: iFxf->UlineThickness=0; sl@0: iFxf->nominal_ascent=0; sl@0: iFxf->descent=0; sl@0: iFxf->chr_seg=0; sl@0: iFxf->FirstChr=0; sl@0: iFxf->n_chars=0; sl@0: iFxf->max_info_width=0; sl@0: iFxf->flags=0; sl@0: iFxf->special=0; sl@0: iFxf->ByteWid=0; sl@0: iFxf->UseWords=0; sl@0: iFxf->iBold=0; sl@0: iFxf->iItalic=0; sl@0: iFxf->iProportional=0; sl@0: iFxf->iSerif=0; sl@0: iFxf->iSymbol=0; sl@0: iFxf->iUid=0; sl@0: sl@0: iUnderHang=0; sl@0: iOverHang=0; sl@0: iChar=new FcmCharHead[MAX_CHARS]; sl@0: for(int letter=0;letterchr[letter]=NULL; sl@0: //************************************************** sl@0: // First pass. Read header info & character widths * sl@0: //************************************************** sl@0: do sl@0: { sl@0: int width=0; // width of current character picture sl@0: sl@0: lastLine=ReadLine(); sl@0: isCharBody=0; sl@0: if (iInputBufLen>0 && iInputBuf[0]=='*') sl@0: { sl@0: if ((ret=DoCom(0))<0) sl@0: return(FileFormat); sl@0: else if (ret) sl@0: { sl@0: for(;iFxf->n_charsn_chars++) sl@0: iFxf->chr[iFxf->n_chars]=NULL; sl@0: specChr=iFxf->n_chars; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: int len=0; sl@0: char* ptr=ScanLine(len); sl@0: if (len) sl@0: { sl@0: isCharBody=1; sl@0: if (iFxf->FirstChr<0) sl@0: iFxf->FirstChr=iFxf->n_chars; sl@0: if (n_row==0) sl@0: { sl@0: for (width=0;widthn_chars>255) sl@0: return(FileFormat); sl@0: iFxf->chr[iFxf->n_chars]=iChar; sl@0: iFxf->n_chars++; sl@0: iChar->xOffset= -iUnderHang; sl@0: iChar->width=width; sl@0: iChar->ByteWid=((iChar->width+15)>>3)&(~1); sl@0: iChar->move=width-iUnderHang-iOverHang; sl@0: if(iFxf->n_chars=='i') sl@0: widthofi=iChar->move; sl@0: else if(iFxf->n_chars=='M') sl@0: widthofM=iChar->move; sl@0: iUnderHang=0; sl@0: iOverHang=0; sl@0: if (width>iFxf->MaxChrWidth) sl@0: iFxf->MaxChrWidth=width; sl@0: } sl@0: n_row++; sl@0: } sl@0: } sl@0: if ((n_row!=0 && !isCharBody) || (lastLine && isCharBody)) sl@0: { sl@0: if (n_row>iFxf->cell_height) sl@0: return(FileFormat); sl@0: iChar->height=n_row; sl@0: iChar->yOffset=iFxf->cell_height-iFxf->descent; sl@0: specChr++; sl@0: n_row=0; sl@0: width=0; sl@0: iChar++; sl@0: } sl@0: } while(!lastLine); sl@0: if (iFxf->cell_height==0) sl@0: return(FileFormat); sl@0: if(widthofi && widthofM) sl@0: iFxf->iProportional=(widthofi!=widthofM); sl@0: return(NoError); sl@0: } sl@0: sl@0: int FscRead::Pass2() sl@0: /******************************************************/ sl@0: /* Second pass. Read in actual picture data this time */ sl@0: /******************************************************/ sl@0: { sl@0: unsigned int bit; // Used to set bits in pic sl@0: int ret,chNum; sl@0: int n_row; // counts row in character picture sl@0: int offset=0; sl@0: int isCharBody; sl@0: int lastLine; sl@0: sl@0: iFileBufPos=0; sl@0: n_row=0; sl@0: chNum=0; sl@0: do { sl@0: lastLine=ReadLine(); sl@0: isCharBody=0; sl@0: if (iInputBufLen>0 && iInputBuf[0]=='*') sl@0: { sl@0: if ((ret=DoCom(1))>0) sl@0: { sl@0: if (retchr[chNum]; sl@0: chNum++; sl@0: } sl@0: unsigned short int* pDest=(unsigned short int*)(iFontCompiler->FontStore()+offset+iChar->ByteWid*n_row); sl@0: bit=1; sl@0: *pDest=0; sl@0: for (int width=0;widthoffset=offset; sl@0: offset+=iChar->ByteWid*n_row; sl@0: n_row=0; sl@0: } sl@0: } while(!lastLine); sl@0: return(NoError); sl@0: }