自定义字体
文章信息
详细描述
下列步骤讲述了如何在Symbian第二版及第三版上使用自定义字体。
- 第一下载你想要在手机上显示的ttf字体文件,你可以也可以使用Windows操作系统自带的字体,可以通过“控制面板”-“字体”或者直接到"C:\Windows\Fonts"目录下寻找你需要字体。
- 从 www.symbian-freak.com找到Easy GDR creator软件,然后将您的ttf字体转换为gdr格式
- 在生成gdr文件后,你可以将其拷贝到手机中(如c:\system\myfolder\abc.gdr这样的位置)
- 在Draw()函数中加载这个字体文件
CGraphicsDevice* iDevice = iCoeEnv->ScreenDevice();
TFileName iFileName;
iFileName.Copy(_L("c:\\system\\myfolder\\abc.gdr"));
CWsScreenDevice* iScrDevice =iCoeEnv->ScreenDevice();
TInt aid =10001;//use any value
iScrDevice->AddFile(iFileName,aid);
TFontSpec myFontSpec;
iDevice->GetNearestFontInTwips(myFont,myFontSpec);
gc.UseFont(myFont);
gc.SetPenColor(KRgbBlack);
gc.DrawText(_L("hello"),TPoint(5,20));
步骤5: 卸载这个字体
iScrDevice->ReleaseFont(myFont);
iScrDevice->RemoveFile(aid);
如何在Symbian 3rd editon中使用字体
#include <aknutils.h>
LIBRARY gdi.lib
LIBRARY fbscli.lib
CFont* iFont;
TInt iFontUid;
CEikonEnv::Static()->ScreenDevice()->AddFile(_L("c:\\system\\fonts\\GARABD.gdr"),
iFontUid);
const CFont* logical_font =
AknLayoutUtils::FontFromId(EAknLogicalFontSecondaryFont);
//Using those two lines will loose everything but the height from the system font
//So you would end up with no anti-alias on your custom font for instance
//TFontSpec font_spec = logical_font->FontSpecInTwips();
//TFontSpec myFontSpec(_L("Garamond"),font_spec.iHeight);
//Only customize the typeface, keep things like anti-alias settings for instance
TFontSpec myFontSpec = logical_font->FontSpecInTwips();
myFontSpec.iTypeface.iName=_L("Garamond");
CEikonEnv::Static()->ScreenDevice()->GetNearestFontToDesignHeightInTwips(iFont,
myFontSpec);
- 卸载字体
CEikonEnv::Static()->ScreenDevice()->ReleaseFont(iFont);
CEikonEnv::Static()->ScreenDevice()->RemoveFile(iFontUid);


(no comments yet)