本文整理汇总了C++中TFont::CharsWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ TFont::CharsWidth方法的具体用法?C++ TFont::CharsWidth怎么用?C++ TFont::CharsWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TFont
的用法示例。
在下文中一共展示了TFont::CharsWidth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rcMemWnd
CCXBitmapDC::CCXBitmapDC(const char *text, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize)
: m_pBitmap(NULL)
{
TUChar *pText = NULL;
do
{
// create font
TFont font;
CCX_BREAK_IF(! font.Create(0, (Int32)fontSize));
// text
Int32 len = strlen(text) + 1;
CCX_BREAK_IF(! (pText = new TUChar[len]));
TUString::StrGBToUnicode(pText, (Char*)text);
// calculate text size
if (CGSize::CGSizeEqualToSize(dimensions, CGSizeZero))
{
m_tSize.width = font.CharsWidth(pText,len);
m_tSize.height = font.LineHeight();
}else
{
m_tSize = dimensions;
}
Int16 width = (Int16)m_tSize.width;
Int16 height = (Int16)m_tSize.height;
// create bitmap
CCX_BREAK_IF(! (m_pBitmap = TBitmap::Create(width, height, 32)));
// create memory window
if (s_pMemWnd)
{
TRectangle rcMemWnd(0, 0, 0, 0);
s_pMemWnd->GetClientBounds(&rcMemWnd);
if (rcMemWnd.Width() < width || rcMemWnd.Height() < height)
{
s_pMemWnd->CloseWindow();
s_pMemWnd = NULL;
}
}
do
{
// if memery window is already break
CCX_BREAK_IF(s_pMemWnd);
CCX_BREAK_IF(! (s_pMemWnd = new TWindow(CCXApplication::sharedApplication())));
Coord nCurrentWidth = CCXApplication::GetCurrentApplication()->GetScreenWidth();
Coord nCurrentHeight = CCXApplication::GetCurrentApplication()->GetScreenHeight();
Coord nMemWndW = (width >= nCurrentWidth) ? width : nCurrentWidth;
Coord nMemWndH = (height >= nCurrentHeight) ? height : nCurrentHeight;
CCX_BREAK_IF(s_pMemWnd->CreateMemWindow(nMemWndW, nMemWndH,screenTransparentFormat));
delete s_pMemWnd;
s_pMemWnd = NULL;
} while (0);
CCX_BREAK_IF(! s_pMemWnd);
// create DC
TDC dc(s_pMemWnd);
// set DC styles
UInt32 styles = GUI_API_STYLE_SPECIFY_FORE_COLOR | GUI_API_STYLE_ROP_MODE_TRANSPARENT |
GUI_API_STYLE_SPECIFY_BACK_COLOR | GUI_API_STYLE_ALIGNMENT_MIDDLE | GUI_API_STYLE_SPECIFY_FONT;
switch (alignment)
{
case UITextAlignmentLeft:
styles |= GUI_API_STYLE_ALIGNMENT_LEFT;
break;
case UITextAlignmentCenter:
styles |= GUI_API_STYLE_ALIGNMENT_CENTER;
break;
case UITextAlignmentRight:
styles |= GUI_API_STYLE_ALIGNMENT_RIGHT;
break;
default:
styles |= GUI_API_STYLE_ALIGNMENT_CENTER;
break;
}
s_pMemWnd->GetMemWindowTBitmapPtr()->Fill32(RGBA(0, 0, 0, 0), 0, 0, width, height);
TRectangle rect(0, 0, width, height);
dc.DrawTextInRectangleEx(pText, 0, RGBA(255,255,255,255), RGBA(0,0,0,255), font, &rect, styles);
dc.ReadBitmap(m_pBitmap, 0, 0);
} while (0);
if (pText)
{
delete[] pText;
pText = NULL;
}
}