如何设置正确的字体大小?
同样的TFontSpec分别在N95、N73、E50上字体大小不一样
于是用下列代码进行测试:
TInt typefaceCount = dev->NumTypefaces();
TBuf<5000> sTypeface;
sTypeface.AppendFormat(_L("TypeFace Count: %d\n"), typefaceCount);
for (TInt i = 0; i < typefaceCount; i++)
{
TTypefaceSupport typefaceSupport;
dev->TypefaceSupport(typefaceSupport, i);
sTypeface.Append(typefaceSupport.iTypeface.iName);
sTypeface.Append(_L("\n"));
sTypeface.AppendFormat(_L("Height Count(%d)=%d\n"), i, typefaceSupport.iNumHeights);
for (TInt j = 0; j < typefaceSupport.iNumHeights; j++)
{
TFontSpec fontSpec;
fontSpec.iTypeface = typefaceSupport.iTypeface;
fontSpec.iHeight = dev->FontHeightInTwips(i, j);
fontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
CFont* pFont = NULL;
CEikonEnv::Static()->ScreenDevice()->GetNearestFontInTwips(pFont, fontSpec);
sTypeface.AppendFormat(_L("Height(%d)=%d Width=%d\n"), j, dev->FontHeightInTwips(i, j), pFont->TextWidthInPixels(szBuf));
CEikonEnv::Static()->ReleaseScreenFont(pFont);
}
}
发现各个手机同样的typeface都有同样的FontHeightInTwips列表,但是字体宽度都是不一样的
例如N95上TypeFace.iName为Sans MT 936_S60的字体
Height(0)=80 Width=73
Height(1)=100 Width=99
Height(2)=120 Width=117
.....
在E50上的数据则为
Height(0)=80 Width=108
Height(1)=100 Width=135
Height(2)=120 Width=153
.....
据以上数据,也就是说通过如下方法创建的字体在各个手机上都是不一样大的
TFontSpec fontSpec = CEikonEnv::Static()->NormalFont()->FontSpecInTwips();
fontSpec.iHeight = 120;
fontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
CEikonEnv::Static()->ScreenDevice()->GetNearestFontInTwips(pFont, fontSpec);
请教各位达人,有没有什么方法可以在各个手机上创建出同样大小的字体