通常我们在绘制文字时都是使用CEikonEnv提供的NormalFont(),AnnotationFont(),TitleFont()等字体,有的情况需要调整字体的大小,下面的代码演示了如何设置字体大小的方法:
void CEditorList3Col::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.Clear( aRect );
CFont *font = NULL;
//获取字体信息
TFontSpec fontSpec = iEikonEnv->LegendFont()->FontSpecInTwips();
fontSpec.iHeight -= fontSpec.iHeight / 6; //更改字体大小
iCoeEnv->ScreenDevice()->GetNearestFontInTwips( font, fontSpec ); //根据设置的字体信息获取合适的字体
gc.UseFont( font );
//Draw text operation
..................................
gc.DiscardFont();
iCoeEnv->ScreenDevice()->ReleaseFont( font ); //记住要调用ReleaseFont()释放字体资源.
}
说明:
由于Series60 3rd上与2nd上使用的字体形式可能不同,上面的代码可能在Series60 2nd上没有效果.
原帖来自[url]http://blog.csdn.net/Beover1984/archive/2007/08/02/1722513.aspx[/url]
第二版改变字体方法
CWindowGc& gc = SystemGc();
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbWhite );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
gc.DrawRect( aRect );
//change EAknLogicalFontPrimaryFont
const CFont* font = AknLayoutUtils::FontFromId(EAknLogicalFontPrimaryFont);
gc.UseFont(font);
TInt lineHeight = font->HeightInPixels()+1;
_LIT(KAboutString1, "Liberty Enabled Address Book.");
const TInt col = 5;
gc.DrawText(KAboutString1, TPoint(col, lineHeight));
gc.DiscardFont();
font = AknLayoutUtils::FontFromId(EAknLogicalFontTitleFont);
gc.UseFont(font);
lineHeight = font->HeightInPixels()+1;
_LIT(KAboutString2, "Liberty Enabled Address Book.");
const TInt col2 = 5;
gc.DrawText(KAboutString2, TPoint(col2, lineHeight*2));
gc.DiscardFont();