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 FontCompiler::FontCompiler():
30 int FontCompiler::Init(char* infile,char* outfile,char* mapfile)
34 iMapSpace=new short int[256];
35 if(!iMapSpace) return(NoMemory);
38 fstream tempfile(mapfile, ios::in | ios::binary);
39 #else //!__MSVCDOTNET__
40 fstream tempfile(mapfile, ios::in | ios::binary | ios::nocreate);
41 #endif //__MSVCDOTNET__
43 if(!tempfile.is_open())
45 tempfile.read((char*)iMapSpace,512);
48 iOutputFile.open(outfile, ios::out);
51 iInputFile.open(infile, ios::in | ios::binary);
52 #else //!__MSVCDOTNET__
53 iInputFile.open(infile, ios::in | ios::binary | ios::nocreate);
54 #endif //__MSVCDOTNET__
56 if(!(iOutputFile.is_open() && iInputFile.is_open()))
59 if(!iFxf) return(NoMemory);
62 iFxf->iProportional=0;
66 iFontSpace=new char[0x100000];
67 if(!iFontSpace) return(NoMemory);
71 char* FontCompiler::FontStore() const
76 int FontCompiler::Read(FontType aInputType)
82 read=new FscRead(iInputFile,*this,iFxf);
85 read=new EffRead(iInputFile,*this,iFxf,iMapSpace);
92 int error=read->ReadFont();
97 void FontCompiler::RemoveBlankSpace()
100 const int maxbytewidth=(MAX_CHAR_WID+15)>>3;
101 unsigned char buf[maxbytewidth];
102 unsigned char zbuf[maxbytewidth];
104 for(count=0;count<maxbytewidth;count++)
106 for(int chNum=iFxf->FirstChr;chNum<iFxf->n_chars;chNum++)
108 FcmCharHead *fChar=iFxf->chr[chNum];
113 int MinLeftBlank=fChar->width;
116 // DEF102183: Graphics tools fail to build using MS VC8.
119 for(row=0;row<fChar->height;)
121 memcpy(buf,iFontSpace+fChar->offset+fChar->ByteWid*row,fChar->ByteWid);
123 unsigned char* pb=buf;
124 for(x=0;x<MinLeftBlank;x++)
138 bit=(unsigned char)(1<<((fChar->width-1)%8));
139 pb=&buf[((fChar->width-1)>>3)];
140 for(x=fChar->width;x>MinRightBlank;x--)
150 bit=unsigned char(0x80);
155 if(memcmp(zbuf,buf,fChar->ByteWid))
158 TopCount=row; /* Count of blank rows at the top */
172 fChar->height=LastNonBlank-TopCount;
173 fChar->width=MinRightBlank-MinLeftBlank;
174 fChar->yOffset-=TopCount;
175 fChar->offset+=TopCount*fChar->ByteWid;
176 fChar->xOffset+=MinLeftBlank;
179 int byte_step=MinLeftBlank/8;
180 int bit_shift=MinLeftBlank%8;
181 unsigned char mask=(unsigned char)(0xFF>>(7-((fChar->width-1)%8)));
182 for(row=0;row<fChar->height;row++)
184 memcpy(buf,iFontSpace+fChar->offset+fChar->ByteWid*row,fChar->ByteWid);
185 for(x=0;x<(fChar->ByteWid-byte_step);x++)
186 buf[x]=(unsigned char)((buf[x+byte_step]>>bit_shift)+
187 (buf[x+byte_step+1]<<(8-bit_shift)));
189 memcpy(iFontSpace+fChar->offset+fChar->ByteWid*row,buf,fChar->ByteWid);