gfxtools/gditools/fontcomp/GDSFCOMP.CPP
changeset 0 f58d6ec98e88
child 6 2013ebce6d92
equal deleted inserted replaced
-1:000000000000 0:f58d6ec98e88
       
     1 /*
       
     2 * Copyright (c) 1997-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "GDSFCOMP.H"
       
    20 #include "TOOLSVER.H"
       
    21 
       
    22 int GdsFontCompiler::WriteFont()
       
    23 	{
       
    24 	int index=0;
       
    25 	index=WriteHeader();
       
    26 	if(index<0) return(index);
       
    27 	for(int ch=index;ch<iFxf->n_chars;ch++)
       
    28 		WriteCharData(ch);
       
    29 	WriteFooter();
       
    30 	return(NoError);
       
    31 	}
       
    32 
       
    33 int GdsFontCompiler::WriteHeader()
       
    34 	{
       
    35 	int mncw=0;
       
    36 	for(char letter='A';letter<='Z';letter++)
       
    37 		{
       
    38 		FcmCharHead* fChar=iFxf->chr[letter];
       
    39 		if(fChar)
       
    40 			{
       
    41 			int letterwidth=fChar->move;
       
    42 			if(letterwidth>mncw)
       
    43 				mncw=letterwidth;
       
    44 			}
       
    45 		}
       
    46 	WriteFormattedData("FontBitmap ");
       
    47 	WriteFormattedData(iFxf->name,1);
       
    48 	WriteFormattedData("Uid ");
       
    49 	WriteFormattedData(iFxf->iUid);
       
    50 	if(iFxf->iBold)
       
    51 		WriteFormattedData(" Bold");
       
    52 	if(iFxf->iItalic)
       
    53 		WriteFormattedData(" Italic");
       
    54 	if(iFxf->iProportional)
       
    55 		WriteFormattedData(" Proportional");
       
    56 	if(iFxf->iSerif)
       
    57 		WriteFormattedData(" Serif");
       
    58 	if(iFxf->iSymbol)
       
    59 		WriteFormattedData(" Symbol");
       
    60 	WriteNewLine();
       
    61 	WriteFormattedData("MaxNormalCharWidth ");
       
    62 	WriteFormattedData(mncw,1);
       
    63 	WriteFormattedData("CellHeight ");
       
    64 	WriteFormattedData(iFxf->cell_height,1);
       
    65 	WriteFormattedData("Ascent ");
       
    66 	WriteFormattedData(iFxf->nominal_ascent,1);
       
    67 //	WriteFormattedData("Uline ");
       
    68 //	WriteFormattedData(iFxf->UlinePos,0);
       
    69 //	WriteFormattedData(" ");
       
    70 //	WriteFormattedData(iFxf->UlineThickness,1);
       
    71 	int index=0;
       
    72 	while(!iFxf->chr[index])
       
    73 		index++;
       
    74 	if(index>=iFxf->n_chars)
       
    75 		return(FileFormat);
       
    76 	WriteFormattedData("CodeSection ");
       
    77 	WriteFormattedData(index,0);
       
    78 	WriteFormattedData(":");
       
    79 	WriteFormattedData(iFxf->n_chars-1,1);
       
    80 	return(index);
       
    81 	}
       
    82 
       
    83 void GdsFontCompiler::WriteFooter()
       
    84 	{
       
    85 	WriteFormattedData("EndCodeSection",1);
       
    86 	WriteFormattedData("EndFontBitmap",1);
       
    87 	WriteNewLine();
       
    88 	}
       
    89 
       
    90 void GdsFontCompiler::WriteCharData(int charnum)
       
    91 	{
       
    92 	unsigned short int* pSrc;
       
    93 	unsigned short int bit;
       
    94 	char buf[10+MAX_CHAR_WID];
       
    95 	unsigned short int srcBuf[(MAX_CHAR_WID+15)>>4];
       
    96 
       
    97 	const FcmCharHead* fChar=iFxf->chr[charnum];
       
    98 	WriteNewLine();
       
    99 	WriteFormattedData("Char ");
       
   100 	WriteFormattedData(charnum);
       
   101 	if(fChar==NULL)
       
   102 		{
       
   103 		WriteNewLine();
       
   104 		WriteFormattedData("EndChar",1);
       
   105 		return;
       
   106 		}
       
   107 	WriteFormattedData(" Adjust ");
       
   108 
       
   109 	int bitwid=fChar->move+(fChar->xOffset<0?-fChar->xOffset:0);
       
   110 	const int ohang=fChar->move-fChar->xOffset-fChar->width;
       
   111 	WriteFormattedData(fChar->xOffset);
       
   112 	WriteFormattedData(" ");
       
   113 	WriteFormattedData(ohang);
       
   114 	bitwid+=ohang;
       
   115 	if (charnum>31)
       
   116 		{
       
   117 		WriteFormattedData("  ! '");
       
   118 		WriteFormattedData((char*)&charnum);
       
   119 		WriteFormattedData("'");
       
   120 		}
       
   121 	WriteNewLine();
       
   122 	if (fChar->width!=0)
       
   123 		{
       
   124 		WriteBlankLines(iFxf->cell_height-iFxf->descent-fChar->yOffset,fChar->width);
       
   125 		for(int y=0;y<fChar->height;y++)
       
   126 			{
       
   127 			memcpy(srcBuf,iFontSpace+fChar->offset+y*fChar->ByteWid,fChar->ByteWid);
       
   128 			pSrc=&srcBuf[0];
       
   129 			bit=1;
       
   130 			int pb=0;
       
   131 			for(int i=0;i<fChar->width;i++)
       
   132 				{
       
   133 				buf[pb++]=((*pSrc)&bit)?SetPixel:BlankPixel;
       
   134 				bit<<=1;
       
   135 				if(!bit)
       
   136 					{
       
   137 					bit=1;
       
   138 					pSrc++;
       
   139 					}
       
   140 				}
       
   141 			buf[pb]=0;
       
   142 			WriteFormattedData(buf,1);
       
   143 			}
       
   144 		WriteBlankLines(iFxf->descent+fChar->yOffset-fChar->height,fChar->width);
       
   145 		}
       
   146 	WriteFormattedData("EndChar",1);
       
   147 	}
       
   148 
       
   149 void GdsFontCompiler::WriteBlankLines(int num,int width)
       
   150 	{
       
   151 	char buf[2+MAX_CHAR_WID+20];
       
   152 	memset(&buf[0],BlankPixel,width);
       
   153 	buf[width] ='\0';
       
   154 	for(int i=0;i<num;i++)
       
   155 		WriteFormattedData(buf,1);
       
   156 	}
       
   157 
       
   158 void GdsFontCompiler::WriteFormattedData(char* aData,int aNewLine)
       
   159 	{
       
   160 	if(aData)
       
   161 		iOutputFile << aData;
       
   162 	if(aNewLine)
       
   163 		WriteNewLine();
       
   164 	}
       
   165 
       
   166 void GdsFontCompiler::WriteFormattedData(int aNum,int aNewLine)
       
   167 	{
       
   168 	char numbuf[16];
       
   169 	_itoa(aNum,numbuf,10);
       
   170 	WriteFormattedData(numbuf,aNewLine);
       
   171 	}
       
   172 
       
   173 void GdsFontCompiler::WriteNewLine()
       
   174 	{
       
   175 	iOutputFile << "\n";
       
   176 	}
       
   177 
       
   178 int main(int argc,char *argv[])
       
   179     {
       
   180 	if(argc<3 || argc>5)
       
   181 		{
       
   182 		cout << "\n";
       
   183 		cout << "FONTCOMP Version 0.01(" << version << ")\n";
       
   184 		cout << "\n";
       
   185 		cout << "USAGE: FONTCOMP srcfile destfile [/e [mapfile]|/f]\n";
       
   186 		cout << "Where srcfile is the file to be processed,\n";
       
   187 		cout << "destfile is the file to be created,\n";
       
   188 		cout << "/e specifies EFF format (default) and /f\n";
       
   189 		cout << "specifies FSC format.  If the format is EFF then\n";
       
   190 		cout << "the optional mapfile may be used for altenative\n";
       
   191 		cout << "character sets.\n\n";
       
   192 		return(0);
       
   193 		}
       
   194 	FontType type=EFontTypeEff;
       
   195 	if(argc==4)
       
   196 		if(argv[3][1]=='f' || argv[3][1]=='F')
       
   197 			type=EFontTypeFsc;
       
   198 	char* mapfile=NULL;
       
   199 	if(argc==5) mapfile=argv[4];
       
   200 	GdsFontCompiler fontcomp;
       
   201 	int ret=fontcomp.Init(argv[1],argv[2],mapfile);
       
   202 	if(ret==NoError)
       
   203 		ret=fontcomp.Read(type);
       
   204 	if(ret==NoError)
       
   205 		fontcomp.RemoveBlankSpace();
       
   206 	if(ret==NoError)
       
   207 		ret=fontcomp.WriteFont();
       
   208 	switch(ret)
       
   209 		{
       
   210 		case NoError:
       
   211 			cout << "Success\n\n";
       
   212 			break;
       
   213 		case NoMemory:
       
   214 			cout << "Out of memory\n\n";
       
   215 			break;
       
   216 		case NoFile:
       
   217 			cout << "File does not exist\n\n";
       
   218 			break;
       
   219 		case FileRead:
       
   220 			cout << "File read error\n\n";
       
   221 			break;
       
   222 		case FileWrite:
       
   223 			cout << "File write error\n\n";
       
   224 			break;
       
   225 		case FileFormat:
       
   226 			cout << "File has wrong format\n\n";
       
   227 			break;
       
   228 		case Parameter:
       
   229 			cout << "Bad parameter\n\n";
       
   230 			break;
       
   231 		}
       
   232 	return(ret);
       
   233     }
       
   234