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