os/graphics/graphicstools/gdi_tools/fontcomp/FONTCOMP.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicstools/gdi_tools/fontcomp/FONTCOMP.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,196 @@
     1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "FONTCOMP.H"
    1.20 +
    1.21 +FontCompiler::FontCompiler():
    1.22 +	iInputFile(),
    1.23 +	iOutputFile(),
    1.24 +	iFxf(NULL),
    1.25 +	iFontSpace(NULL),
    1.26 +	iWorkSpace(NULL),
    1.27 +	iMapSpace(NULL),
    1.28 +	iWorkSpaceSize(0),
    1.29 +	iHeaderDataLen(0),
    1.30 +	iHeaderData()
    1.31 +	{}
    1.32 +
    1.33 +int FontCompiler::Init(char* infile,char* outfile,char* mapfile)
    1.34 +	{
    1.35 +	if(mapfile)
    1.36 +		{
    1.37 +		iMapSpace=new short int[256];
    1.38 +		if(!iMapSpace) return(NoMemory);
    1.39 +
    1.40 +#ifdef __MSVCDOTNET__
    1.41 +		fstream tempfile(mapfile, ios::in | ios::binary);
    1.42 +#else //!__MSVCDOTNET__
    1.43 +		fstream tempfile(mapfile, ios::in | ios::binary | ios::nocreate);
    1.44 +#endif //__MSVCDOTNET__
    1.45 +
    1.46 +		if(!tempfile.is_open())
    1.47 +			return(NoFile);
    1.48 +		tempfile.read((char*)iMapSpace,512);
    1.49 +		tempfile.close();
    1.50 +		}
    1.51 +	iOutputFile.open(outfile, ios::out);
    1.52 +
    1.53 +#ifdef __MSVCDOTNET__
    1.54 +	iInputFile.open(infile, ios::in | ios::binary);
    1.55 +#else //!__MSVCDOTNET__
    1.56 +	iInputFile.open(infile, ios::in | ios::binary | ios::nocreate);
    1.57 +#endif //__MSVCDOTNET__
    1.58 +
    1.59 +	if(!(iOutputFile.is_open() && iInputFile.is_open()))
    1.60 +		return(NoFile);
    1.61 +	iFxf=new Fxf;
    1.62 +	if(!iFxf) return(NoMemory);
    1.63 +	iFxf->iBold=0;
    1.64 +	iFxf->iItalic=0;
    1.65 +	iFxf->iProportional=0;
    1.66 +	iFxf->iSerif=0;
    1.67 +	iFxf->iSymbol=0;
    1.68 +	iFxf->iUid=0;
    1.69 +	iFontSpace=new char[0x100000];
    1.70 +	if(!iFontSpace) return(NoMemory);
    1.71 +	return(NoError);
    1.72 +	}
    1.73 +
    1.74 +char* FontCompiler::FontStore() const
    1.75 +	{
    1.76 +	return(iFontSpace);
    1.77 +	}
    1.78 +
    1.79 +int FontCompiler::Read(FontType aInputType)
    1.80 +	{
    1.81 +	FontRead *read=NULL;
    1.82 +	switch(aInputType)
    1.83 +		{
    1.84 +		case EFontTypeFsc:
    1.85 +			read=new FscRead(iInputFile,*this,iFxf);
    1.86 +			break;
    1.87 +		case EFontTypeEff:
    1.88 +			read=new EffRead(iInputFile,*this,iFxf,iMapSpace);
    1.89 +			break;
    1.90 +		default:
    1.91 +			return(Parameter);
    1.92 +		}
    1.93 +	if(!read)
    1.94 +		return(NoMemory);
    1.95 +	int error=read->ReadFont();
    1.96 +	delete read;
    1.97 +	return(error);
    1.98 +	}
    1.99 +
   1.100 +void FontCompiler::RemoveBlankSpace()
   1.101 +	{
   1.102 +	int count=0;
   1.103 +	const int maxbytewidth=(MAX_CHAR_WID+15)>>3;
   1.104 +	unsigned char buf[maxbytewidth];
   1.105 +	unsigned char zbuf[maxbytewidth];
   1.106 +
   1.107 +	for(count=0;count<maxbytewidth;count++)
   1.108 +			zbuf[count]=0;
   1.109 +	for(int chNum=iFxf->FirstChr;chNum<iFxf->n_chars;chNum++)
   1.110 +		{
   1.111 +		FcmCharHead *fChar=iFxf->chr[chNum];
   1.112 +		if(fChar)
   1.113 +		    {
   1.114 +		    int LastNonBlank=0;
   1.115 +		    int TopCount=0;
   1.116 +		    int MinLeftBlank=fChar->width;
   1.117 +		    int MinRightBlank=0;
   1.118 +		    
   1.119 +       	    // DEF102183: Graphics tools fail to build using MS VC8.
   1.120 +		    int row;
   1.121 +		    int x;
   1.122 +		    for(row=0;row<fChar->height;)
   1.123 +			{
   1.124 +				memcpy(buf,iFontSpace+fChar->offset+fChar->ByteWid*row,fChar->ByteWid);
   1.125 +			unsigned char bit=1;
   1.126 +			unsigned char* pb=buf;
   1.127 +			for(x=0;x<MinLeftBlank;x++)
   1.128 +			    {
   1.129 +			    if ((*pb)&bit)
   1.130 +				{
   1.131 +				MinLeftBlank=x;
   1.132 +				break;
   1.133 +				}
   1.134 +			    bit<<=1;
   1.135 +			    if (bit==0)
   1.136 +				{
   1.137 +				bit=1;
   1.138 +				pb++;
   1.139 +				}
   1.140 +			    }
   1.141 +			bit=(unsigned char)(1<<((fChar->width-1)%8));
   1.142 +			pb=&buf[((fChar->width-1)>>3)];
   1.143 +			for(x=fChar->width;x>MinRightBlank;x--)
   1.144 +			    {
   1.145 +			    if ((*pb)&bit)
   1.146 +				{
   1.147 +				MinRightBlank=x;
   1.148 +				break;
   1.149 +				}
   1.150 +			    bit>>=1;
   1.151 +			    if (bit==0)
   1.152 +				{
   1.153 +				bit=unsigned char(0x80);
   1.154 +				pb--;
   1.155 +				}
   1.156 +			    }
   1.157 +			row++;
   1.158 +				if(memcmp(zbuf,buf,fChar->ByteWid))
   1.159 +			    {
   1.160 +			    if (TopCount==0)
   1.161 +				TopCount=row;   /* Count of blank rows at the top */
   1.162 +			    LastNonBlank=row;
   1.163 +			    }
   1.164 +			}
   1.165 +		    if (TopCount==0)
   1.166 +			{
   1.167 +			fChar->height=0;
   1.168 +			fChar->width=0;
   1.169 +			fChar->xOffset=0;
   1.170 +			fChar->yOffset=0;
   1.171 +			}
   1.172 +		    else
   1.173 +			{
   1.174 +			TopCount--;
   1.175 +			fChar->height=LastNonBlank-TopCount;
   1.176 +			fChar->width=MinRightBlank-MinLeftBlank;
   1.177 +			fChar->yOffset-=TopCount;
   1.178 +			fChar->offset+=TopCount*fChar->ByteWid;
   1.179 +			fChar->xOffset+=MinLeftBlank;
   1.180 +			if (MinLeftBlank)
   1.181 +			    {
   1.182 +			    int byte_step=MinLeftBlank/8;
   1.183 +			    int bit_shift=MinLeftBlank%8;
   1.184 +			    unsigned char mask=(unsigned char)(0xFF>>(7-((fChar->width-1)%8)));
   1.185 +			    for(row=0;row<fChar->height;row++)
   1.186 +						{
   1.187 +						memcpy(buf,iFontSpace+fChar->offset+fChar->ByteWid*row,fChar->ByteWid);
   1.188 +						for(x=0;x<(fChar->ByteWid-byte_step);x++)
   1.189 +							buf[x]=(unsigned char)((buf[x+byte_step]>>bit_shift)+
   1.190 +								(buf[x+byte_step+1]<<(8-bit_shift)));
   1.191 +						buf[x-1]&=mask;
   1.192 +						memcpy(iFontSpace+fChar->offset+fChar->ByteWid*row,buf,fChar->ByteWid);
   1.193 +						}
   1.194 +			    }
   1.195 +			}
   1.196 +		    }
   1.197 +		}
   1.198 +	}
   1.199 +