Font应用

来源:互联网 发布:im域名稳定吗 编辑:程序博客网 时间:2024/05/01 05:20

 

    可以通过iEikonEnv-〉***Font()来获得Cfont指针。字体有TitleFont(),DenseFont()DenseFont()AnnotationFont()Font() 5种。画下划线的方法

   font = iEikonEnv->LegendFont();

   textPoint.iY = (aRect.Height() / KMiddleTextTwoVertAlign); gc.UseFont(font);//使用legendFont

   gc.SetPenColor(colorBlue);//定义gcclor

gc.SetUnderlineStyle(EUnderlineOn);//画下划线

   gc.DrawText(text, textPoint);  gc.SetUnderlineStyle(EUnderlineOff);//下划线结束

   gc.DiscardFont();//释放内存中使用的discard

 

画删除线:

   font = iEikonEnv->SymbolFont();

   textPoint.SetXY(aRect.Width() / KMiddleTextOneHorizAlign, aRect.Height() / KMiddleTextOneVertAlign);

   gc.UseFont(font);

   gc.SetPenColor(colorGreen);

   gc.SetStrikethroughStyle(EStrikethroughOn); //开始

   gc.DrawText(text, textPoint);

   gc.SetStrikethroughStyle(EStrikethroughOff);//结束

   gc.DiscardFont();

 

gc的颜色的定义AKN_LAF_COLORTint color);可以用这宏来定义。返回的是TRgb

 

可以通过iCoeEnvCCoeEnv)中的ScreenDevice()得到CWsScreenDevice(屏幕软件装置通过这个类可以设置屏幕或询问屏幕参数)TypefaceSupport()这个方法就可以得到,手机屏幕支持的font类型。

   for (TInt i = iCurrentScrollNum; i < iNumTypefaces; i++)

       {

       // Get the i-th font on the device.

       iCoeEnv->ScreenDevice()->TypefaceSupport(*iTypefaceSupport, i);

 

       // Get the font name.

       fontName = iTypefaceSupport->iTypeface.iName.Des();

 

       // Create font specification.

       TFontSpec fontSpec(fontName, KFontSpecSize);

       iDeviceMap->GetNearestFontInTwips(fontToUse, fontSpec);

      

       // Increment baseline by two times height of font.

       textPoint.iY += (fontToUse->HeightInPixels() * KBaseLineIncrementer);

 

       // Draw text in font with graphics context.

       gc.UseFont(fontToUse);

       gc.DrawText(fontName, textPoint);

       gc.DiscardFont();

       iDeviceMap->ReleaseFont(fontToUse);

       }  

 

TFontSpec是与设备无关的字体规范(支持字高,样式),CFont是与设备有关的字体。通过TZoomFactorGetNearestFontInTwips(CFont*& aFont,const TFontSpec& aFontSpec);得到CFont

 

注意:gc(图形上下文)是没有默认字体的,如果在调用文本绘图函数之前没有调用useFont(),将会导致严重的错误。