本文整理汇总了C++中CFont::TextWidthInPixels方法的典型用法代码示例。如果您正苦于以下问题:C++ CFont::TextWidthInPixels方法的具体用法?C++ CFont::TextWidthInPixels怎么用?C++ CFont::TextWidthInPixels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFont
的用法示例。
在下文中一共展示了CFont::TextWidthInPixels方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ClipToFit
EXPORT_C void TextUtils::ClipToFit(TDes& aBuffer,const CFont& aFont,TInt aMaxWidthInPixels,TChar aAlternativeEnd)
/** Clips text to fit into a maximum width.
If the text is too wide to fit in the width when displayed in aFont,
it is truncated and the specified character (by default,
a horizontal ellipsis) is appended to it.
@param aBuffer A buffer containing the text to clip.
@param aFont The font.
@param aMaxWidthInPixels The maximum width in pixels.
@param aAlternativeEnd The Unicode character to append to the buffer if truncated.
By default, this is the horizontal ellipsis. */
{
TInt textWidth=aFont.TextWidthInPixels(aBuffer);
if (textWidth<=aMaxWidthInPixels)
return;
TBuf<1> ellipse;
ellipse.Append(aAlternativeEnd);
TInt extraWidth=aFont.TextWidthInPixels(ellipse);
TInt cutOff=aFont.TextCount(aBuffer,aMaxWidthInPixels-extraWidth);
aBuffer.SetLength(cutOff);
aBuffer.Append(ellipse);
}
示例2: TReal
CFont*
CMainMenuListContainer::FindLargestPossibleFontL(const TDesC& aTextToFit,
TInt aMaxWidthInPixels,
enum TAknLogicalFontId aPreferredLogicalFontId) const
{
TInt fontMinimizerFactorInPixels = 2;
// Get the screen device so that we can calc the twips
// per pixel
TPixelsTwipsAndRotation twips;
CWsScreenDevice* screenDev = CEikonEnv::Static()->ScreenDevice();
screenDev->GetScreenModeSizeAndRotation(screenDev->CurrentScreenMode(),
twips);
// Calc the twips per pixel
TReal twipsPerPixel = twips.iTwipsSize.iHeight /
TReal(twips.iPixelSize.iHeight);
// Get the preferred logical font from the font store
const CFont* preferredFont = AknLayoutUtils::
FontFromId(aPreferredLogicalFontId);
TFontSpec fontSpec = preferredFont->FontSpecInTwips();
// Get the font that matches the fontspec the best
CFont* fontToUse;
screenDev->
GetNearestFontToDesignHeightInTwips(fontToUse, fontSpec);
TInt fontMinimizerFactorInTwips =
TInt(fontMinimizerFactorInPixels * twipsPerPixel);
while (aMaxWidthInPixels < fontToUse->TextWidthInPixels(aTextToFit)) {
// The text didnt fit within the given space, make the font
// a bit smaller and try again
screenDev->ReleaseFont(fontToUse);
fontSpec.iHeight -= fontMinimizerFactorInTwips;
screenDev->
GetNearestFontToDesignHeightInTwips(fontToUse, fontSpec);
}
// Return the font, the caller has to release the font
// from the CWsScreenDevice
return fontToUse;
}