sl@0: // Copyright (c) 1997-2010 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 "GDSFCOMP.H" sl@0: #include "TOOLSVER.H" sl@0: sl@0: int GdsFontCompiler::WriteFont() sl@0: { sl@0: int index=0; sl@0: index=WriteHeader(); sl@0: if(index<0) return(index); sl@0: for(int ch=index;chn_chars;ch++) sl@0: WriteCharData(ch); sl@0: WriteFooter(); sl@0: return(NoError); sl@0: } sl@0: sl@0: int GdsFontCompiler::WriteHeader() sl@0: { sl@0: int mncw=0; sl@0: for(char letter='A';letter<='Z';letter++) sl@0: { sl@0: FcmCharHead* fChar=iFxf->chr[letter]; sl@0: if(fChar) sl@0: { sl@0: int letterwidth=fChar->move; sl@0: if(letterwidth>mncw) sl@0: mncw=letterwidth; sl@0: } sl@0: } sl@0: WriteFormattedData("FontBitmap "); sl@0: WriteFormattedData(iFxf->name,1); sl@0: WriteFormattedData("Uid "); sl@0: WriteFormattedData(iFxf->iUid); sl@0: if(iFxf->iBold) sl@0: WriteFormattedData(" Bold"); sl@0: if(iFxf->iItalic) sl@0: WriteFormattedData(" Italic"); sl@0: if(iFxf->iProportional) sl@0: WriteFormattedData(" Proportional"); sl@0: if(iFxf->iSerif) sl@0: WriteFormattedData(" Serif"); sl@0: if(iFxf->iSymbol) sl@0: WriteFormattedData(" Symbol"); sl@0: WriteNewLine(); sl@0: WriteFormattedData("MaxNormalCharWidth "); sl@0: WriteFormattedData(mncw,1); sl@0: WriteFormattedData("CellHeight "); sl@0: WriteFormattedData(iFxf->cell_height,1); sl@0: WriteFormattedData("Ascent "); sl@0: WriteFormattedData(iFxf->nominal_ascent,1); sl@0: // WriteFormattedData("Uline "); sl@0: // WriteFormattedData(iFxf->UlinePos,0); sl@0: // WriteFormattedData(" "); sl@0: // WriteFormattedData(iFxf->UlineThickness,1); sl@0: int index=0; sl@0: while(!iFxf->chr[index]) sl@0: index++; sl@0: if(index>=iFxf->n_chars) sl@0: return(FileFormat); sl@0: WriteFormattedData("CodeSection "); sl@0: WriteFormattedData(index,0); sl@0: WriteFormattedData(":"); sl@0: WriteFormattedData(iFxf->n_chars-1,1); sl@0: return(index); sl@0: } sl@0: sl@0: void GdsFontCompiler::WriteFooter() sl@0: { sl@0: WriteFormattedData("EndCodeSection",1); sl@0: WriteFormattedData("EndFontBitmap",1); sl@0: WriteNewLine(); sl@0: } sl@0: sl@0: void GdsFontCompiler::WriteCharData(int charnum) sl@0: { sl@0: unsigned short int* pSrc; sl@0: unsigned short int bit; sl@0: char buf[10+MAX_CHAR_WID]; sl@0: unsigned short int srcBuf[(MAX_CHAR_WID+15)>>4]; sl@0: sl@0: const FcmCharHead* fChar=iFxf->chr[charnum]; sl@0: WriteNewLine(); sl@0: WriteFormattedData("Char "); sl@0: WriteFormattedData(charnum); sl@0: if(fChar==NULL) sl@0: { sl@0: WriteNewLine(); sl@0: WriteFormattedData("EndChar",1); sl@0: return; sl@0: } sl@0: WriteFormattedData(" Adjust "); sl@0: sl@0: int bitwid=fChar->move+(fChar->xOffset<0?-fChar->xOffset:0); sl@0: const int ohang=fChar->move-fChar->xOffset-fChar->width; sl@0: WriteFormattedData(fChar->xOffset); sl@0: WriteFormattedData(" "); sl@0: WriteFormattedData(ohang); sl@0: bitwid+=ohang; sl@0: if (charnum>31) sl@0: { sl@0: WriteFormattedData(" ! '"); sl@0: WriteFormattedData((char*)&charnum); sl@0: WriteFormattedData("'"); sl@0: } sl@0: WriteNewLine(); sl@0: if (fChar->width!=0) sl@0: { sl@0: WriteBlankLines(iFxf->cell_height-iFxf->descent-fChar->yOffset,fChar->width); sl@0: for(int y=0;yheight;y++) sl@0: { sl@0: memcpy(srcBuf,iFontSpace+fChar->offset+y*fChar->ByteWid,fChar->ByteWid); sl@0: pSrc=&srcBuf[0]; sl@0: bit=1; sl@0: int pb=0; sl@0: for(int i=0;iwidth;i++) sl@0: { sl@0: buf[pb++]=((*pSrc)&bit)?SetPixel:BlankPixel; sl@0: bit<<=1; sl@0: if(!bit) sl@0: { sl@0: bit=1; sl@0: pSrc++; sl@0: } sl@0: } sl@0: buf[pb]=0; sl@0: WriteFormattedData(buf,1); sl@0: } sl@0: WriteBlankLines(iFxf->descent+fChar->yOffset-fChar->height,fChar->width); sl@0: } sl@0: WriteFormattedData("EndChar",1); sl@0: } sl@0: sl@0: void GdsFontCompiler::WriteBlankLines(int num,int width) sl@0: { sl@0: char buf[2+MAX_CHAR_WID+20]; sl@0: memset(&buf[0],BlankPixel,width); sl@0: buf[width] ='\0'; sl@0: for(int i=0;i5) sl@0: { sl@0: cout << "\n"; sl@0: cout << "FONTCOMP Version 0.01(" << version << ")\n"; sl@0: cout << "\n"; sl@0: cout << "USAGE: FONTCOMP srcfile destfile [/e [mapfile]|/f]\n"; sl@0: cout << "Where srcfile is the file to be processed,\n"; sl@0: cout << "destfile is the file to be created,\n"; sl@0: cout << "/e specifies EFF format (default) and /f\n"; sl@0: cout << "specifies FSC format. If the format is EFF then\n"; sl@0: cout << "the optional mapfile may be used for altenative\n"; sl@0: cout << "character sets.\n\n"; sl@0: return(0); sl@0: } sl@0: FontType type=EFontTypeEff; sl@0: if(argc==4) sl@0: if(argv[3][1]=='f' || argv[3][1]=='F') sl@0: type=EFontTypeFsc; sl@0: char* mapfile=NULL; sl@0: if(argc==5) mapfile=argv[4]; sl@0: GdsFontCompiler fontcomp; sl@0: int ret=fontcomp.Init(argv[1],argv[2],mapfile); sl@0: if(ret==NoError) sl@0: ret=fontcomp.Read(type); sl@0: if(ret==NoError) sl@0: fontcomp.RemoveBlankSpace(); sl@0: if(ret==NoError) sl@0: ret=fontcomp.WriteFont(); sl@0: switch(ret) sl@0: { sl@0: case NoError: sl@0: cout << "Success\n\n"; sl@0: break; sl@0: case NoMemory: sl@0: cout << "Out of memory\n\n"; sl@0: break; sl@0: case NoFile: sl@0: cout << "File does not exist\n\n"; sl@0: break; sl@0: case FileRead: sl@0: cout << "File read error\n\n"; sl@0: break; sl@0: case FileWrite: sl@0: cout << "File write error\n\n"; sl@0: break; sl@0: case FileFormat: sl@0: cout << "File has wrong format\n\n"; sl@0: break; sl@0: case Parameter: sl@0: cout << "Bad parameter\n\n"; sl@0: break; sl@0: } sl@0: return(ret); sl@0: } sl@0: