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: FontCompiler::FontCompiler(): sl@0: iInputFile(), sl@0: iOutputFile(), sl@0: iFxf(NULL), sl@0: iFontSpace(NULL), sl@0: iWorkSpace(NULL), sl@0: iMapSpace(NULL), sl@0: iWorkSpaceSize(0), sl@0: iHeaderDataLen(0), sl@0: iHeaderData() sl@0: {} sl@0: sl@0: int FontCompiler::Init(char* infile,char* outfile,char* mapfile) sl@0: { sl@0: if(mapfile) sl@0: { sl@0: iMapSpace=new short int[256]; sl@0: if(!iMapSpace) return(NoMemory); sl@0: sl@0: #ifdef __MSVCDOTNET__ sl@0: fstream tempfile(mapfile, ios::in | ios::binary); sl@0: #else //!__MSVCDOTNET__ sl@0: fstream tempfile(mapfile, ios::in | ios::binary | ios::nocreate); sl@0: #endif //__MSVCDOTNET__ sl@0: sl@0: if(!tempfile.is_open()) sl@0: return(NoFile); sl@0: tempfile.read((char*)iMapSpace,512); sl@0: tempfile.close(); sl@0: } sl@0: iOutputFile.open(outfile, ios::out); sl@0: sl@0: #ifdef __MSVCDOTNET__ sl@0: iInputFile.open(infile, ios::in | ios::binary); sl@0: #else //!__MSVCDOTNET__ sl@0: iInputFile.open(infile, ios::in | ios::binary | ios::nocreate); sl@0: #endif //__MSVCDOTNET__ sl@0: sl@0: if(!(iOutputFile.is_open() && iInputFile.is_open())) sl@0: return(NoFile); sl@0: iFxf=new Fxf; sl@0: if(!iFxf) return(NoMemory); 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: iFontSpace=new char[0x100000]; sl@0: if(!iFontSpace) return(NoMemory); sl@0: return(NoError); sl@0: } sl@0: sl@0: char* FontCompiler::FontStore() const sl@0: { sl@0: return(iFontSpace); sl@0: } sl@0: sl@0: int FontCompiler::Read(FontType aInputType) sl@0: { sl@0: FontRead *read=NULL; sl@0: switch(aInputType) sl@0: { sl@0: case EFontTypeFsc: sl@0: read=new FscRead(iInputFile,*this,iFxf); sl@0: break; sl@0: case EFontTypeEff: sl@0: read=new EffRead(iInputFile,*this,iFxf,iMapSpace); sl@0: break; sl@0: default: sl@0: return(Parameter); sl@0: } sl@0: if(!read) sl@0: return(NoMemory); sl@0: int error=read->ReadFont(); sl@0: delete read; sl@0: return(error); sl@0: } sl@0: sl@0: void FontCompiler::RemoveBlankSpace() sl@0: { sl@0: int count=0; sl@0: const int maxbytewidth=(MAX_CHAR_WID+15)>>3; sl@0: unsigned char buf[maxbytewidth]; sl@0: unsigned char zbuf[maxbytewidth]; sl@0: sl@0: for(count=0;countFirstChr;chNumn_chars;chNum++) sl@0: { sl@0: FcmCharHead *fChar=iFxf->chr[chNum]; sl@0: if(fChar) sl@0: { sl@0: int LastNonBlank=0; sl@0: int TopCount=0; sl@0: int MinLeftBlank=fChar->width; sl@0: int MinRightBlank=0; sl@0: sl@0: // DEF102183: Graphics tools fail to build using MS VC8. sl@0: int row; sl@0: int x; sl@0: for(row=0;rowheight;) sl@0: { sl@0: memcpy(buf,iFontSpace+fChar->offset+fChar->ByteWid*row,fChar->ByteWid); sl@0: unsigned char bit=1; sl@0: unsigned char* pb=buf; sl@0: for(x=0;xwidth-1)%8)); sl@0: pb=&buf[((fChar->width-1)>>3)]; sl@0: for(x=fChar->width;x>MinRightBlank;x--) sl@0: { sl@0: if ((*pb)&bit) sl@0: { sl@0: MinRightBlank=x; sl@0: break; sl@0: } sl@0: bit>>=1; sl@0: if (bit==0) sl@0: { sl@0: bit=unsigned char(0x80); sl@0: pb--; sl@0: } sl@0: } sl@0: row++; sl@0: if(memcmp(zbuf,buf,fChar->ByteWid)) sl@0: { sl@0: if (TopCount==0) sl@0: TopCount=row; /* Count of blank rows at the top */ sl@0: LastNonBlank=row; sl@0: } sl@0: } sl@0: if (TopCount==0) sl@0: { sl@0: fChar->height=0; sl@0: fChar->width=0; sl@0: fChar->xOffset=0; sl@0: fChar->yOffset=0; sl@0: } sl@0: else sl@0: { sl@0: TopCount--; sl@0: fChar->height=LastNonBlank-TopCount; sl@0: fChar->width=MinRightBlank-MinLeftBlank; sl@0: fChar->yOffset-=TopCount; sl@0: fChar->offset+=TopCount*fChar->ByteWid; sl@0: fChar->xOffset+=MinLeftBlank; sl@0: if (MinLeftBlank) sl@0: { sl@0: int byte_step=MinLeftBlank/8; sl@0: int bit_shift=MinLeftBlank%8; sl@0: unsigned char mask=(unsigned char)(0xFF>>(7-((fChar->width-1)%8))); sl@0: for(row=0;rowheight;row++) sl@0: { sl@0: memcpy(buf,iFontSpace+fChar->offset+fChar->ByteWid*row,fChar->ByteWid); sl@0: for(x=0;x<(fChar->ByteWid-byte_step);x++) sl@0: buf[x]=(unsigned char)((buf[x+byte_step]>>bit_shift)+ sl@0: (buf[x+byte_step+1]<<(8-bit_shift))); sl@0: buf[x-1]&=mask; sl@0: memcpy(iFontSpace+fChar->offset+fChar->ByteWid*row,buf,fChar->ByteWid); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: } sl@0: } sl@0: