问题描述: 1.使用CEikonEnv::Static()->NormalFont()或者其他如TitleFont等接口获得CFont实例 2.CGraphicsContext::UseFont( fontUsed )设置字体 3.使用CGraphicsContext::DrawText()绘制字体 如上情况,便会出现S60正常,UIQ3却统统变斜体的问题. 问题分析: google了半天,查到《ProgrammersGuide》中 2.1.7 Font provider and control screen fonts,“More specifically, this means that the use of the NormalFont() and the CEikonEnv's LegendFont(), TitleFont(), AnnotationFont() and DenseFont() must be removed from all code. ” 也就是说,问题出在之前S60中获得CFont实例的函数已经被废弃。 参考文档给出的解决方式,只是在CCoecontrol::Draw中作处理。代码如下: CSomeControl::Draw(const TRect& aRect) { const CCoeFontProvider& fontProvider = FindFontProvider(); const CFont& font = fontProvider.Font(TCoeFont::LegendFont(), AccumulatedZoom()); XCoeTextDrawer textDrawer = TextDrawer(); textDrawer->SetAlignment(EHCenterVCenter); textDrawer.DrawText(gc, iText, rect, font); }
但是,如果不是在这个地方,因为CCoecontrol::TextDrawer()是Protect的方法无法使用,经过验证,如下的代码可以解决这个问题,参考代码如下: .h class CWindow { ... private: CFbsBitmap* m_pBackBitmap; CFbsBitmapDevice* m_pBackDevice; CFbsBitGc* m_pBackGc; CCoeControl* m_pOwner; HBufC* m_pLCaption; ... };
.cpp ...
void CWindow::Draw( const CFbsBitGc* aGc ) const { #if defined(_UIQ3_SDK_) const CCoeFontProvider& fontProvider = m_pOwner->FindFontProvider(); const CFont& fontUsed = fontProvider.Font(TCoeFont::NormalFont(), m_pOwner->AccumulatedZoom()); m_pBackGc->UseFont( &fontUsed );
TInt baselineOffset=( rect_bar.Height() / 2 + fontUsed.AscentInPixels() / 2 ); #else const CFont* fontUsed; fontUsed = CEikonEnv::Static()->NormalFont(); m_pBackGc->UseFont( fontUsed );
TInt baselineOffset=( rect_bar.Height() / 2 + fontUsed->AscentInPixels() / 2 ); #endif if ( NULL != m_pLCaption ) { m_pBackGc->DrawText( *m_pLCaption, rect_bar, baselineOffset, CGraphicsContext::ELeft, 4 ); } ... } ... 代码在6681,N81,P990上测试通过。 |