www.pudn.com > Example2D.rar > CFont.cpp


/* 
* ============================================================================ 
*  Name     : CFont from CFont.h 
*  Part of  : 2DExample 
*  Created  : 01/01/2005 by Forum Nokia 
*  Version  : 1.0 
*  Copyright: Nokia Corporation 
* ============================================================================ 
*/ 
 
// INCLUDE FILES 
#include "CFont.h" 
#include "CBitmap.h" 
 
 
 
CBmFont* CBmFont::NewL( CBitmap* aBitmap, MSystem* aSystem ) 
	{ 
	CBmFont* self = new( ELeave )CBmFont( aBitmap, aSystem ); 
	CleanupStack::PushL( self ); 
	self->ConstructL( aBitmap ); 
	CleanupStack::Pop( self ); 
	return self; 
	} 
 
 
 
void CBmFont::ConstructL( CBitmap* aBitmap ) 
	{ 
	TUint16* s; 
	TInt tr = 0; 
	TBool in = EFalse; 
 
	s =aBitmap->Data(); 
	 
	for ( TInt i = 0; i < 255; i++ ) 
		{ 
		iRects[i] = TRect( 0, 0, 0, 0 ); 
		} 
 
	for ( TInt x = 0; x Size().iWidth; x++ ) 
		{ 
		if ( s[x] != 0 ) 
			{ 
			in = !in; 
			if( in ) 
				{ 
				iRects[tr].iTl = TPoint( x,1 ); 
				} 
			else 
				{ 
				iRects[tr].iBr = TPoint( x, aBitmap->Size().iHeight ); 
				tr++; 
				} 
			} 
		} 
	} 
 
 
 
CBmFont::CBmFont( CBitmap* aBitmap, MSystem* aSystem ) : iBitmap( aBitmap ), iSystem( aSystem ) 
	{ 
 
	} 
 
 
 
CBmFont::~CBmFont() 
	{ 
	} 
 
 
void CBmFont::DrawText( CBitmap& aTarget,  const TDesC8& aString, const TPoint& aPosition ) 
	{ 
	TRect cur ( 0, 0, 0, 0 ); 
	TPoint pos( aPosition ); 
 
	for( TInt i=0;i < aString.Length(); i++ ) 
		{ 
		TInt t = aString[i]; 
		pos.iX += cur.Width(); 
 
		if( t == ' ' ) 
			{ 
			cur = iRects[ '@' - '0' + 1 ]; 
			continue; 
			} 
 
		t -= '0'; 
		cur = iRects[t]; 
 
		iBitmap->SetDrawRect( iRects[ t ] ); 
		iBitmap->Draw( aTarget, pos ); 
		} 
	} 
 
 
 
void CBmFont::DrawNumber( CBitmap& aTarget, const TInt aNumber, const TPoint& aPosition ) 
	{ 
	TBuf8<16> txt; 
	txt.AppendNum( aNumber ); 
	DrawText( aTarget, txt, aPosition ); 
	} 
 
// End of file