1.
//首先查找机器支持的字体个数.
TInt iNumTypefaces = iCoeEnv->ScreenDevice()->NumTypefaces();
//然后就可以查找所有的字体
for(TInt i = 0; i < iNumTypefaces; i++)
{
TTypefaceSupport myTypefaceSupport;
iCoeEnv->ScreenDevice()->TypefaceSupport(myTypefaceSupport,i);
TBuf<KMaxTypefaceNameLength> aTemp;
aTemp.Copy(myTypefaceSupport.iTypeface.iName.Des());
}//这样就可以得到所有的aTypefaceName.
//设置指定的字体
TFontSpec fontSpec;
fontSpec.iTypeface.iName= aTemp;
fontSpec.iHeight = 40;
(这个地方也可以使用相对于别的字体的高度如下:
const CFont* font = CEikonEnv::Static()->SymbolFont();
fontSpec.iHeight = font->FontSpecInTwips().iHeight + 10;
)
//生成新的字体
CEikonEnv::Static()->ScreenDevice()->GetNearestFontInTwips(newFont, fontSpec);
//最后使用字体
CWindowGc::UseFont(newFont);
2.
字体大小样式,全套的(注释掉的代码也是有效的)
const CFont* font = iEikonEnv->SymbolFont();
iOffScreenBitmapGc->UseFont( font );
iOffScreenBitmapGc->DrawText(_L("hello world"),TPoint(0,20) );
iOffScreenBitmapGc->DiscardFont();
CFont* fontNew = NULL;
TFontSpec fontSpec;
fontSpec.iTypeface.iName=font->FontSpecInTwips().iTypeface.iName;// KFontName;
//if (text->Bold())
//{
// // Set Bold
// fontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
//}
//if (text->Italic())
//{
// // Set Italic
// fontSpec.iFontStyle.SetPosture(EPostureItalic);
//}
//fontSpec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
//fontSpec.iHeight=text->Height();
Set Underline
//if (text->Underline())
//{
// iGc->SetUnderlineStyle(EUnderlineOn);
//}
fontSpec.iHeight = font->FontSpecInTwips().iHeight + 40;
iOffScreenBitmapDevice->GetNearestFontInTwips(fontNew,fontSpec);
if (fontNew != NULL)
{
iOffScreenBitmapGc->UseFont( fontNew );
iOffScreenBitmapGc->DrawText(_L("hello world"),TPoint(0,100) );
iOffScreenBitmapGc->DiscardFont();
iOffScreenBitmapDevice->ReleaseFont(fontNew);
}
3。
CFont* normalFont = 0;
// Create font specification.
TFontSpec fontSpec = iEikonEnv->NormalFont()->FontSpecInTwips();
//set font's size
fontSpec.iHeight -= fontSpec.iHeight/2;
//apply font
iCoeEnv->ScreenDevice()->GetNearestFontInTwips(normalFont, fontSpec);
if (( 0 != normalFont ))
gc.UseFont(normalFont);