(1)改变屏幕字体显示的大小:
首先,设置一个CFbsBitGc的指针和CFbsScreenDevice的指针:
CFbsBitGc *iFbsBitGc;
CFbsScreenDevice* iFbsScreenDevice;
然后,再二段构造中对这两个指针进行NewL()处理,如下:
iFbsBitGc = CFbsBitGc::NewL();
iFbsScreenDevice=CFbsScreenDevice::NewL(0, EColor256);
其中0表示使用系统自带的字体Lib库,而EColor256是显示模式,系统支持的模式有
|
注:EColor4K模式效果最好,颜色多样
设置完成后激活它iFbsBitGc->Activate(iFbsScreenDevice);
最后,在Draw()函数中:
_LIT(KMyFontName,"Swiss");
TFontSpec myFontSpec1(KMyFontName,200);
CFont* myFont1;
//加粗
myFontSpec1.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
//斜体
myFontSpec1.iFontStyle.SetPosture(EPostureItalic);
//阳文
myFontSpec1.iFontStyle.SetEffects(FontEffect::EEmbossed,ETrue);
//获取字体
iFbsScreenDevice->GetNearestFontToMaxHeightInTwips(myFont1, myFontSpec1, 220);
//选择字体
iFbsBitGc->UseFont(myFont1);
//设置画笔颜色为红色
iFbsBitGc->SetPenColor(KRgbRed);
_LIT(KText, "This is a Test!");
TBufC<20> text (KText);
iFbsBitGc ->DrawText(KText, TPoint(120, 120));
iFbsScreenDevice->Update();
// Discard and destroy the font
iFbsScreenDevice->ReleaseFont(myFont1);
(2)不通过资源直接使用汉字及其他字体格式
myFont=ApacPlain16();
gc.UseFont( myFont );
baseH+=myFont->HeightInPixels()+1;
gc.DrawText(_L("/x671D/x5916/x5927/x8857"),TPoint(x,baseH));
gc.DiscardFont();
myFont=ApacPlain12();
gc.UseFont( myFont );
baseH+=myFont->HeightInPixels()+1;
gc.DrawText(_L("/x671D/x5916/x5927/x8857"),TPoint(x,baseH));
gc.DiscardFont();
其中/x671D/x5916/x5927/x8857为自己手动转化成UTF8得到,转化工具自己找很小,