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