本文整理汇总了C++中GraphicsPath::GetBounds方法的典型用法代码示例。如果您正苦于以下问题:C++ GraphicsPath::GetBounds方法的具体用法?C++ GraphicsPath::GetBounds怎么用?C++ GraphicsPath::GetBounds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphicsPath
的用法示例。
在下文中一共展示了GraphicsPath::GetBounds方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetTextBounds
SizeF GDIPluseExt::GetTextBounds(const Font& font,const StringFormat& strFormat,CString szText)
{
#ifndef _UNICODE
//字符转换
int str_len = szText.GetLength();
WCHAR* pstr_w = new WCHAR[str_len];
MultiByteToWideChar(CP_ACP,0,szText.GetBuffer(),-1,pstr_w,str_len);
szText.ReleaseBuffer();
GraphicsPath graphicsPathObj;
FontFamily fontfamily;
font.GetFamily(&fontfamily);
graphicsPathObj.AddString(pstr_w,-1,&fontfamily,font.GetStyle(),font.GetSize(),PointF(0,0),&strFormat);
DEL_P(pstr_w);
#else
GraphicsPath graphicsPathObj;
FontFamily fontfamily;
font.GetFamily(&fontfamily);
graphicsPathObj.AddString(szText,-1,&fontfamily,font.GetStyle(),font.GetSize(),PointF(0,0),&strFormat);
#endif
RectF rcBound;
// 获取边界范围
graphicsPathObj.GetBounds(&rcBound);
// 返回文本的宽高
return SizeF(rcBound.Width,rcBound.Height);
}
示例2: GetBounds
SizeF GDIPluseExt::GetBounds(CString strText,CString strFont,INT nfontsize)
{
StringFormat strformat;
GraphicsPath path;
#ifdef _UNICODE
FontFamily fontFamily(strFont);
path.AddString(strText,strText.GetLength(), &fontFamily,
FontStyleRegular,
(REAL)nfontsize,
PointF(0,0),
&strformat );
#else
//字符转换
int font_len = strFont.GetLength();
WCHAR* pfont_w = new WCHAR[font_len];
MultiByteToWideChar(CP_ACP,0,strFont.GetBuffer(),-1,pfont_w,font_len);
strFont.ReleaseBuffer();
//字符转换
int text_len = strText.GetLength();
WCHAR* ptext_w = new WCHAR[text_len];
MultiByteToWideChar(CP_ACP,0,strText.GetBuffer(),-1,ptext_w,text_len);
strText.ReleaseBuffer();
FontFamily fontFamily(pfont_w);
Font font(&fontFamily, (REAL)nfontsize, FontStyleRegular, UnitPixel);
path.AddString(ptext_w,wcsnlen_s(ptext_w,text_len), &fontFamily,
font.GetStyle(),
font.GetSize(),
PointF(0,0),
&strformat );
DEL_P(ptext_w);
DEL_P(pfont_w);
#endif
RectF rcBound;
// 获取边界范围
path.GetBounds(&rcBound);
TRACE("Round_Size:%d\r\n",rcBound.Width);
// 返回文本的宽高
return SizeF(rcBound.Width,rcBound.Height);
}
示例3: InitLineTextPath
wxGraphicsPath OOPDesktopLyric::InitLineTextPath(wxGraphicsContext *gc) {
wxASSERT(gc);
// 文本轮廓
wxGraphicsPen pen = gc->CreatePen(wxPen(wxColour(0,0,0,255), 3));
const wxString textToDraw(IsCurrLineValid() ?
(*m_currLine)->GetLyric() :
GetInteractiveOutput());
wxGraphicsPath path = gc->CreatePath();
//========================================
// 添加文本
FontFamily fontFamily(m_style.fontFace);
StringFormat stringFormat;
wxCoord winHeight;
GetSize(NULL, &winHeight);
wxASSERT(size_t(winHeight) >= m_style.pxFontSize);
GraphicsPath *nativePath = (GraphicsPath *) path.GetNativePath();
nativePath->AddString(textToDraw,
-1,
&fontFamily,
m_style.bold ? FontStyleBold : FontStyleRegular,
m_style.pxFontSize,
Point(0, (winHeight - m_style.pxFontSize) / 2),
&stringFormat);
WXGDIPlusPenData *penImpl = (WXGDIPlusPenData *) pen.GetGraphicsData();
RectF bounds;
nativePath->GetBounds(&bounds, NULL, penImpl->m_pen);
m_textPathBounds.m_x = bounds.X;
m_textPathBounds.m_y = bounds.Y;
m_textPathBounds.m_width = bounds.Width;
m_textPathBounds.m_height = bounds.Height;
path.UnGetNativePath(nativePath);
//========================================
// 添加到路径中
gc->SetPen(pen);
gc->StrokePath(path);
return path;
}
示例4: TestStringCx
int MusicUtils::TestStringCx(const wchar_t *szText)
{
//CDC tdc;
//tdc.CreateCompatibleDC(CDC::FromHandle(::GetDC(0)));
//HBITMAP hbitmap = CreateCompatibleBitmap(tdc.m_hDC,600,15);
//tdc.SelectObject(hbitmap);
//return tdc.GetOutputTextExtent(szText).cx;
GraphicsPath path;
FontFamily fontfamily;
Font font(L"宋体",14);
font.GetFamily(&fontfamily);
StringFormat strFormat;
strFormat.SetAlignment(StringAlignmentNear);
path.AddString(szText,-1,&fontfamily,font.GetStyle(),font.GetSize(),PointF(0,0),&strFormat);
RectF rcBound;
path.GetBounds(&rcBound);
return rcBound.Width;
}
示例5: GetTextBounds
// 获取文字需要的显示区域
Size GetTextBounds(const Font& font,const StringFormat& strFormat,const CString& strText)
{
GraphicsPath path;
FontFamily fontfamily;
font.GetFamily(&fontfamily);
BSTR bsText = strText.AllocSysString();
path.AddString(bsText,-1,&fontfamily,font.GetStyle(),font.GetSize(),PointF(0,0),&strFormat);
::SysFreeString(bsText);
RectF rcBound;
path.GetBounds(&rcBound);
REAL rHeight = font.GetHeight(0.0f);
return Size((int)(rcBound.Width > (int)rcBound.Width ? rcBound.Width + 1 : rcBound.Width),
(int)(rHeight > (int)rHeight ? rHeight + 4 : rHeight + 1));
//return Size((int)(rcBound.Width > (int)rcBound.Width ? rcBound.Width + 1 : rcBound.Width),
// (int)(rcBound.Height > (int)rcBound.Height ? rcBound.Height + 2 : rcBound.Height + 1));
}
示例6: drawLine
int Window::drawLine(HDC hdc, int oy, std::wstring string, TextFont* fnt)
{
using namespace Gdiplus;
int x = (showed ? 0 : leftMargin) - 5;
int y = (showed ? 0 : topMargin) + oy;
const wchar_t* text = string.c_str();
if (fnt == 0) fnt = font;
Graphics graphics(hdc);
graphics.SetSmoothingMode(SmoothingModeAntiAlias);
FontFamily fontFamily;
fnt->GetFamily(&fontFamily);
RectF boundRect = fnt->getTextBounds(hdc, clientRect, text);
x += ((clientRect.right - clientRect.left) - (int)(boundRect.GetRight() - boundRect.GetLeft()) - 2) / 2;
y -= ((int)boundRect.GetBottom()) + 5;
StringFormat strformat;
GraphicsPath path;
path.AddString(text, wcslen(text), &fontFamily,
fnt->GetStyle(), graphics.GetDpiY() * fnt->GetSize() / 72, Gdiplus::Point(x, y), &strformat );
// Outline color + size
Pen pen(Color(0, 0, 0), fnt->GetSize()/7);
pen.SetLineJoin(LineJoinRound);
graphics.DrawPath(&pen, &path);
// Text color
SolidBrush brush(Color(254, 254, 254));
graphics.FillPath(&brush, &path);
Rect bounds;
path.GetBounds(&bounds, 0, &pen);
return (int)boundRect.GetBottom();
}