Symbian 创建字体的实现
2010-04-20 15:57:00 来源:WEB开发网//Symbian创建字体
CFont* CMyView::MyCreateFont(TInt aSystemFontIndex,TInt aFontHeightInPixels)const
{
TBuf<100> fontName;
CFont* fontToUse;
TTypefaceSupport TypefaceSupport ;
iCoeEnv->ScreenDevice()->TypefaceSupport( TypefaceSupport , aSystemFontIndex ) ;
fontName = TypefaceSupport.iTypeface.iName.Des();
//测试代码显示 fontName 的内容
//CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote ;
//informationNote->ExecuteLD( fontName );
//
//显示结果为: Sans MT UniT_HKSCS_S60
//
// 创建字体 FontHeightInPixels
MGraphicsDeviceMap *DeviceMap = iCoeEnv->ScreenDevice();
TFontSpec fontSpec(fontName, DeviceMap->VerticalPixelsToTwips(aFontHeightInPixels));
fontToUse = iCoeEnv->CreateScreenFontL(fontSpec);
return fontToUse;
}
//Symbian删除字体
void CMyView::MyReleaseFont(CFont* aFont)const
{
iCoeEnv->ScreenDevice()->ReleaseFont(aFont);
}
//Symbian使用字体
void CMyView::DrawSummary(CWindowGc& gc, const TRect& aRect )const
{
CFont *useFont = MyCreateFont();
gc.UseFont(useFont);
gc.DrawText(_L(“Helloworld!”),TPoint(0,useFont->FontMaxHeight()*1));
gc.DiscardFont();
MyReleaseFont(useFont);
}
更多精彩
赞助商链接