在使用gc. DrawText时需要注意,设置字体:
在h中定义:
CFont* iFont;
在CPP的ConstructL中声明:
_LIT(KFontName, "Arial"); // 字体名称
const TInt KFontSize = 120; // 字号
TFontSpec fontSpec(KFontName, KFontSize);
// 创建字体
CGraphicsDevice* screenDevice = CEikonEnv::Static()->ScreenDevice();
screenDevice->GetNearestFontInTwips(iFont, fontSpec);
定义后才能使用:
gc.DrawText(_L("No Picture!"),TPoint(80,80));
使用字体后一定要释放:
aGc.Device()->GetNearestFontInTwips(font,fontSpec);
aGc.SetPenColor(KRgbBlack);
aGc.SetPenStyle(CGraphicsContext::ESolidPen);
aGc.UseFont(font);
aGc.DrawText(text,TPoint(0,font->HeightInPixels()));
aGc.DiscardFont();
aGc.Device()->ReleaseFont(font);
上面的代码里面如果没有调用最后一句ReleaseFont就会产生该错误CTypefaceStore -14
GetNearestFontInTwips和ReleaseFont必须成对出现,
使用CGraphicsDevice及其集成类的GetNearestFontInTwips 等方法创建自定义字体的时候,
使用完字体要调用一下ReleaseFont 释放 该字体。
类似函数还有GetNearestFontToDesignHeightInTwips(), GetNearestFontToMaxHeightInTwips(),
如果是CFbsDevice等,还有这些函数
GetFontById()
GetNearestFontToMaxHeightInPixels()
GetNearestFontInPixels()
GetNearestFontToDesignHeightInPixels()
GetNearestFontToMaxHeightInPixels()也需要relesefont