本文整理汇总了C++中gdiplus::StringFormat类的典型用法代码示例。如果您正苦于以下问题:C++ StringFormat类的具体用法?C++ StringFormat怎么用?C++ StringFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw_label
//
// draw_label
//
int Component_Decorator_Impl::draw_label (Gdiplus::Graphics * g)
{
float height = (float)this->location_.height ();
float px = static_cast <float> (this->location_.x_) + (this->location_.width () / 2.0f);
float py = static_cast <float> (this->location_.y_) + (height + 15.0f);
static const Gdiplus::Font font (L"Arial", 10);
static const Gdiplus::SolidBrush brush (Gdiplus::Color (0, 0, 0));
Gdiplus::StringFormat format;
format.SetAlignment (Gdiplus::StringAlignmentCenter);
format.SetLineAlignment (Gdiplus::StringAlignmentCenter);
CComBSTR bstr (this->label_.length (), this->label_.c_str ());
// Draw the label for the element.
g->DrawString (bstr,
this->label_.length (),
&font,
Gdiplus::PointF (px, py),
&format,
&brush);
return 0;
}
示例2: OnPaint
/**
* Event: OnPaint
*
* Render the Notification Window
*/
LRESULT NotificationWindow::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
PAINTSTRUCT ps;
BeginPaint(&ps);
{
MyGdiplusHelper gdi_plus_autostart;
{
// get draw area
RECT clientRect;
::GetClientRect(m_hWnd, &clientRect);
// create Gdiplus Graphics object
Gdiplus::Graphics graphics(m_hWnd, FALSE);
graphics.SetClip(Gdiplus::Rect(clientRect.left, clientRect.top, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top));
// draw a background
Gdiplus::SolidBrush backgroundBrush(Gdiplus::Color(DEFAULT_ALPHA, 255, 255, 255));
graphics.FillRectangle(&backgroundBrush, clientRect.left, clientRect.top, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top);
// shrink draw area
int inset = 4;
clientRect.left += inset;
clientRect.top += inset;
clientRect.right -= inset;
clientRect.bottom -= inset;
// whack a logo TODO
//Bitmap* bitmap = new Bitmap(m_icon.c_str(), FALSE);
int bitmapWidth = 0;//bitmap->GetWidth();
int bitmapHeight = 15;//bitmap->GetHeight();
//graphics->DrawImage(bitmap, clientRect.left, clientRect.top,
//bitmapWidth, bitmapHeight);
// draw a separator
Gdiplus::Pen blackPen(Gdiplus::Color(0, 0, 0), 1.0f);
graphics.DrawLine(&blackPen, clientRect.left, clientRect.top + bitmapHeight + inset, clientRect.right, clientRect.top + bitmapHeight + inset);
// setup text properties
Gdiplus::Font titleFont(L"Verdana", 10, Gdiplus::FontStyleBold);
Gdiplus::Font textFont(L"Verdana", 10, Gdiplus::FontStyleRegular);
Gdiplus::RectF titleRect((float)clientRect.left + inset + bitmapWidth, (float)clientRect.top, (float)clientRect.right, 20.0f);
Gdiplus::RectF textRect((float)clientRect.left,
(float)clientRect.top + bitmapHeight + (inset * 2),
(float)clientRect.right,
(float)clientRect.bottom - bitmapHeight - (inset * 2));
Gdiplus::StringFormat format;
format.SetTrimming(Gdiplus::StringTrimmingEllipsisCharacter);
format.SetFormatFlags(Gdiplus::StringFormatFlagsLineLimit);
Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0));
// draw the message
graphics.DrawString(m_title.c_str(), (int)m_title.length(), &titleFont, titleRect, &format, &blackBrush);
graphics.DrawString(m_message.c_str(), (int)m_message.length(), &textFont, textRect, &format, &blackBrush);
}
}
EndPaint(&ps);
bHandled = TRUE;
return 0;
}
示例3: MeasureTextLinesW
bool CanvasGDIP::MeasureTextLinesW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect, UINT& lines)
{
Gdiplus::StringFormat& stringFormat = ((TextFormatGDIP&)format).m_StringFormat;
Gdiplus::StringFormat tStringFormat = Gdiplus::StringFormat::GenericTypographic();
// Set trimming and format temporarily.
const Gdiplus::StringTrimming stringTrimming = stringFormat.GetTrimming();
stringFormat.SetTrimming(Gdiplus::StringTrimmingNone);
const INT stringFormatFlags = stringFormat.GetFormatFlags();
stringFormat.SetFormatFlags(Gdiplus::StringFormatFlagsNoClip);
if (m_AccurateText)
{
tStringFormat.SetTrimming(stringFormat.GetTrimming());
tStringFormat.SetFormatFlags(stringFormat.GetFormatFlags());
tStringFormat.SetAlignment(stringFormat.GetAlignment());
tStringFormat.SetLineAlignment(stringFormat.GetLineAlignment());
}
INT linesFilled = 0;
const Gdiplus::Status status = m_Graphics->MeasureString(
str, (INT)strLen, ((TextFormatGDIP&)format).m_Font.get(), rect,
m_AccurateText ? &tStringFormat : &stringFormat, &rect, nullptr, &linesFilled);
lines = linesFilled;
// Restore old options.
stringFormat.SetTrimming(stringTrimming);
stringFormat.SetFormatFlags(stringFormatFlags);
return status == Gdiplus::Ok;
}
示例4: draw_text_lines
void winbox::draw_text_lines()
{
if (m_lines.empty())
return;
Gdiplus::SolidBrush brush(m_log_back_color);
m_graphics->FillRectangle(&brush, m_log_box);
Gdiplus::Font font(L"宋体", 12);
Gdiplus::StringFormat format;
format.SetAlignment(Gdiplus::StringAlignment::StringAlignmentNear);
format.SetLineAlignment(Gdiplus::StringAlignment::StringAlignmentCenter);
float line_pos = m_log_box.GetBottom();
float fontHeight = font.GetHeight(m_graphics) + 3;
m_graphics->SetClip(m_log_box);
for (auto it = m_lines.begin(); it != m_lines.end(); ++it)
{
if (line_pos < m_log_box.Y)
{
m_lines.erase(it, m_lines.end());
break;
}
Gdiplus::RectF rect(m_log_box.X, line_pos - fontHeight, m_log_box.Width, fontHeight);
brush.SetColor(it->tp == log_type::err ? m_log_err_color : m_log_txt_color);
m_graphics->DrawString(it->ws.c_str(), (int)it->ws.size(), &font, rect, &format, &brush);
line_pos -= fontHeight;
}
m_graphics->ResetClip();
Gdiplus::Pen pen(m_log_edge_color);
m_graphics->DrawRectangle(&pen, m_log_box);
}
示例5: calcExtents
// sets the line's mWidth, mHeight, mAscent, mDescent, mLeading
void Line::calcExtents()
{
#if defined( CINDER_MAC )
CFMutableAttributedStringRef attrStr = ::CFAttributedStringCreateMutable( kCFAllocatorDefault, 0 );
// Defer internal consistency-checking and coalescing until we're done building this thing
::CFAttributedStringBeginEditing( attrStr );
for( vector<Run>::const_iterator runIt = mRuns.begin(); runIt != mRuns.end(); ++runIt ) {
// create and append this run's CFAttributedString
::CFAttributedStringRef runStr = cocoa::createCfAttributedString( runIt->mText, runIt->mFont, runIt->mColor );
::CFAttributedStringReplaceAttributedString( attrStr, ::CFRangeMake( ::CFAttributedStringGetLength( attrStr ), 0 ), runStr );
::CFRelease( runStr );
}
// all done - coalesce
::CFAttributedStringEndEditing( attrStr );
mCTLineRef = ::CTLineCreateWithAttributedString( attrStr );
::CFRelease( attrStr );
CGFloat ascentCG, descentCG, leadingCG;
mWidth = ::CTLineGetTypographicBounds( mCTLineRef, &ascentCG, &descentCG, &leadingCG );
mAscent = ascentCG;
mDescent = descentCG;
mLeading = leadingCG;
mHeight = 0;
#elif defined( CINDER_MSW )
mHeight = mWidth = mAscent = mDescent = mLeading = 0;
for( vector<Run>::iterator runIt = mRuns.begin(); runIt != mRuns.end(); ++runIt ) {
Gdiplus::StringFormat format;
format.SetAlignment( Gdiplus::StringAlignmentNear ); format.SetLineAlignment( Gdiplus::StringAlignmentNear );
Gdiplus::RectF sizeRect;
const Gdiplus::Font *font = runIt->mFont.getGdiplusFont();;
TextManager::instance()->getGraphics()->MeasureString( &runIt->mWideText[0], -1, font, Gdiplus::PointF( 0, 0 ), &format, &sizeRect );
runIt->mWidth = sizeRect.Width;
runIt->mAscent = runIt->mFont.getAscent();
runIt->mDescent = runIt->mFont.getDescent();
runIt->mLeading = runIt->mFont.getLeading();
mWidth += sizeRect.Width;
mAscent = std::max( runIt->mFont.getAscent(), mAscent );
mDescent = std::max( runIt->mFont.getDescent(), mDescent );
mLeading = std::max( runIt->mFont.getLeading(), mLeading );
mHeight = std::max( mHeight, sizeRect.Height );
}
#endif
mHeight = std::max( mHeight, mAscent + mDescent + mLeading );
}
示例6: SetLineAlignment
void StringFormat::SetLineAlignment(StringAlignment sa) {
Gdiplus::StringFormat* sf = reinterpret_cast<Gdiplus::StringFormat*>(_private);
switch(sa) {
case StringAlignmentNear:
sf->SetLineAlignment(Gdiplus::StringAlignmentNear);
break;
case StringAlignmentFar:
sf->SetLineAlignment(Gdiplus::StringAlignmentFar);
break;
case StringAlignmentCenter:
sf->SetLineAlignment(Gdiplus::StringAlignmentCenter);
break;
}
}
示例7: DrawTextW
void CanvasGDIP::DrawTextW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect, const Gdiplus::SolidBrush& brush)
{
Gdiplus::StringFormat& stringFormat = ((TextFormatGDIP&)format).m_StringFormat;
Gdiplus::StringFormat tStringFormat = Gdiplus::StringFormat::GenericTypographic();
if (m_AccurateText)
{
tStringFormat.SetTrimming(stringFormat.GetTrimming());
tStringFormat.SetFormatFlags(stringFormat.GetFormatFlags());
tStringFormat.SetAlignment(stringFormat.GetAlignment());
tStringFormat.SetLineAlignment(stringFormat.GetLineAlignment());
}
m_Graphics->DrawString(
str, (INT)strLen, ((TextFormatGDIP&)format).m_Font.get(), rect,
m_AccurateText ? &tStringFormat : &stringFormat, &brush);
}
示例8: DrawUIText
void cgGdiplusRender::DrawUIText( LPCTSTR lpctText, int nTextLen,
const cgRectF& rect, cgID font, int space , cgColor color, int style )
{
Gdiplus::RectF kDrawRect (rect.x, rect.y, rect.w, rect.h);
Gdiplus::StringFormat kFormat;
if (style&DT_CENTER)
kFormat.SetAlignment(Gdiplus::StringAlignmentCenter);
if (style&DT_VCENTER)
kFormat.SetLineAlignment(Gdiplus::StringAlignmentCenter);
Gdiplus::Font * pkFont = FindFont(font);
Gdiplus::SolidBrush brush(Gdiplus::Color((Gdiplus::ARGB)color));
m_pkGraphics->DrawString(lpctText, nTextLen, pkFont, kDrawRect,
&kFormat, &brush);
}
示例9: SetTrimming
void StringFormat::SetTrimming(StringTrimming st) {
Gdiplus::StringFormat* sf = reinterpret_cast<Gdiplus::StringFormat*>(_private);
switch(st) {
case StringTrimmingNone:
sf->SetTrimming(Gdiplus::StringTrimmingNone);
break;
case StringTrimmingCharacter:
sf->SetTrimming(Gdiplus::StringTrimmingCharacter);
break;
case StringTrimmingWord:
sf->SetTrimming(Gdiplus::StringTrimmingWord);
break;
case StringTrimmingEllipsisCharacter:
sf->SetTrimming(Gdiplus::StringTrimmingEllipsisCharacter);
break;
case StringTrimmingEllipsisWord:
sf->SetTrimming(Gdiplus::StringTrimmingEllipsisWord);
break;
case StringTrimmingEllipsisPath:
sf->SetTrimming(Gdiplus::StringTrimmingEllipsisPath);
break;
}
}
示例10: MeasureTextW
bool CanvasGDIP::MeasureTextW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect)
{
Gdiplus::StringFormat& stringFormat = ((TextFormatGDIP&)format).m_StringFormat;
Gdiplus::StringFormat tStringFormat = Gdiplus::StringFormat::GenericTypographic();
if (m_AccurateText)
{
tStringFormat.SetTrimming(stringFormat.GetTrimming());
tStringFormat.SetFormatFlags(stringFormat.GetFormatFlags());
tStringFormat.SetAlignment(stringFormat.GetAlignment());
tStringFormat.SetLineAlignment(stringFormat.GetLineAlignment());
}
const Gdiplus::Status status = m_Graphics->MeasureString(
str, (INT)strLen, ((TextFormatGDIP&)format).m_Font.get(), rect,
m_AccurateText ? &tStringFormat : &stringFormat, &rect);
return status == Gdiplus::Ok;
}
示例11: DrawTextVector
void TextElement::DrawTextVector(RenderContext& ctx)
{
Gdiplus::RectF textrect;
if (!RectFFromStyle(GetStyle(), textrect) || !m_font || m_text.empty())
return;
ctx.pGraphics->SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);
Gdiplus::FontFamily family(L"Tahoma");
Gdiplus::StringFormat format;
format.SetFormatFlags(Gdiplus::StringFormatFlagsLineLimit);
format.SetTrimming(Gdiplus::StringTrimmingEllipsisCharacter);
Gdiplus::GraphicsPath path;
path.AddString(m_text.c_str(), -1, &family, Gdiplus::FontStyleBold, 12, textrect, &format);
Gdiplus::Pen pen(Gdiplus::Color(192, 0, 0, 0), 0.0);
Gdiplus::SolidBrush brush(Gdiplus::Color(255, 255, 255, 255));
ctx.pGraphics->FillPath(&brush, &path);
ctx.pGraphics->DrawPath(&pen, &path);
}
示例12: GetBitmapImage
/*!
@brief イメージの取得
@param [in] pSelectItem 選択データ
@param [out] bitmap イメージ
*/
BOOL CImageFontDlg::GetBitmapImage(LPVOID pSelectItem, CImage &bitmap)
{
CRect rect;
GetClientRect(&rect);
bitmap.Create(rect.Width(), rect.Height(), 32);
HDC hDC = bitmap.GetDC();
Gdiplus::Graphics graphics(hDC);
graphics.Clear((Gdiplus::ARGB)Gdiplus::Color::White);
CString strMessage;
strMessage = _T("1234567890\n");
strMessage += _T("abcdefghijklmnopqrstuvwxyz\n");
strMessage += _T("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n");
strMessage += _T("あいおえおかきくけこさしすせそたちつてとなにぬねの\n");
strMessage += _T("はひふへほまみむめもやゆよらりるれろわをん\n");
LOGFONT *pLogfont = (LOGFONT *) pSelectItem;
Gdiplus::Font font(hDC, pLogfont);
Gdiplus::RectF drawLayout(0, 0, (Gdiplus::REAL)rect.Width(), (Gdiplus::REAL)rect.Height());
Gdiplus::StringFormat stringFormat;
stringFormat.SetAlignment(Gdiplus::StringAlignmentCenter);
stringFormat.SetLineAlignment(Gdiplus::StringAlignmentCenter);
stringFormat.SetTrimming(Gdiplus::StringTrimmingNone);
Gdiplus::SolidBrush brush((Gdiplus::ARGB)Gdiplus::Color::Black);
graphics.SetTextRenderingHint((Gdiplus::TextRenderingHint) (GetSpaceKeyDownCount() % (int)Gdiplus::TextRenderingHintClearTypeGridFit));
graphics.DrawString(strMessage, -1, &font, drawLayout, &stringFormat,&brush);
bitmap.ReleaseDC();
return TRUE;
}
示例13: Measure
CSize CXTextGdiPlus::Measure( HDC dc, INT nWidthLimit )
{
Gdiplus::Graphics graph(dc);
graph.SetTextRenderingHint(m_Rendering);
Gdiplus::FontFamily fontFamily(XLibST2W(m_strFontName));
Gdiplus::Font font(&fontFamily, m_nSize, m_FontStyle, Gdiplus::UnitPixel);
Gdiplus::StringFormat stringformat;
stringformat.SetAlignment(m_AlignmentH);
stringformat.SetLineAlignment(m_AlignmentV == Gdiplus::StringAlignmentCenter ?
Gdiplus::StringAlignmentNear : m_AlignmentV);
stringformat.SetFormatFlags(m_FormatFlags);
stringformat.SetTrimming(Gdiplus::StringTrimmingEllipsisWord);
Gdiplus::SolidBrush brush(Gdiplus::Color(m_cAlpha, m_ColorR, m_ColorG, m_ColorB));
Gdiplus::RectF rfTargetRect(0, 0, nWidthLimit > 0 ? nWidthLimit : INFINITY, INFINITY);
CStringW strTextToDraw(XLibST2W(m_strText));
Gdiplus::RectF rfBoundRect(0, 0, 0, 0);
graph.MeasureString(strTextToDraw, -1, &font, rfTargetRect, &stringformat, &rfBoundRect);
return CSize(ceil(rfBoundRect.Width), ceil(rfBoundRect.Height));
}
示例14: DrawTextOutline
BOOL GdiplusUtilities::DrawTextOutline(Gdiplus::Graphics& graphics,
LPCTSTR lpchText, int cchText, const RECT* lprc, UINT format,
const LOGFONT& lf, COLORREF fill, COLORREF outline, INT outlineWidth,
BOOL bCalcOnly /*= FALSE*/, RECT* rcCalc/* = NULL*/)
{
HDC hdc = graphics.GetHDC();
Gdiplus::Font font(hdc, &lf);
graphics.ReleaseHDC(hdc);
Gdiplus::StringFormat sFormat;
if (format & DT_VCENTER)
sFormat.SetLineAlignment(Gdiplus::StringAlignmentCenter);
else if (format & DT_BOTTOM)
sFormat.SetLineAlignment(Gdiplus::StringAlignmentFar);
else
sFormat.SetLineAlignment(Gdiplus::StringAlignmentNear);
if (format & DT_CENTER)
sFormat.SetAlignment(Gdiplus::StringAlignmentCenter);
else if (format & DT_RIGHT)
sFormat.SetAlignment(Gdiplus::StringAlignmentFar);
else
sFormat.SetAlignment(Gdiplus::StringAlignmentNear);
Gdiplus::Rect rcForCalc;
Gdiplus::Rect* pRCForCalc = &rcForCalc;
if (rcCalc == NULL)
pRCForCalc = NULL;
if (DrawTextOutline(graphics, lpchText, cchText, RECT2GdiplusRect(*lprc), sFormat, font,
COLORREF2Color(fill), COLORREF2Color(outline), outlineWidth, bCalcOnly, pRCForCalc))
{
if (pRCForCalc != NULL)
*rcCalc = GdiplusRect2RECT(*pRCForCalc);
return TRUE;
}
return FALSE;
}
示例15: DrawTextNormal
void TextElement::DrawTextNormal(RenderContext& ctx)
{
Gdiplus::RectF textrect;
if (!RectFFromStyle(GetStyle(), textrect) || !m_font || m_text.empty())
return;
m_rect.X = textrect.X;
m_rect.Y = textrect.Y;
m_rect.Width = textrect.Width;
m_rect.Height = textrect.Height;
Gdiplus::Bitmap bmpTemp(textrect.Width, textrect.Height, PixelFormat32bppARGB);
Gdiplus::Graphics gfxTemp(&bmpTemp);
gfxTemp.Clear(Gdiplus::Color(255, 0, 0, 0));
Gdiplus::SolidBrush brush(Gdiplus::Color(255, 255, 255, 255));
Gdiplus::StringFormat format;
format.SetFormatFlags(Gdiplus::StringFormatFlagsLineLimit);
InitTextStyles(gfxTemp, format, GetStyle());
Gdiplus::RectF rect2(0, 0, textrect.Width, textrect.Height);
gfxTemp.DrawString(m_text.c_str(), m_text.length(), m_font.get(), rect2, &format, &brush);
Gdiplus::BitmapData bmpdataTemp;
Gdiplus::Rect textrect2(0, 0, textrect.Width, textrect.Height);
bmpTemp.LockBits(&textrect2, Gdiplus::ImageLockModeRead, bmpTemp.GetPixelFormat(), &bmpdataTemp);
Gdiplus::PixelFormat pform = ctx.pBitmap->GetPixelFormat();
Gdiplus::BitmapData bmpdataCtx;
Gdiplus::Rect textrect3(textrect.X, textrect.Y, textrect.Width, textrect.Height);
ctx.pBitmap->LockBits(&textrect3, Gdiplus::ImageLockModeWrite | Gdiplus::ImageLockModeRead, ctx.pBitmap->GetPixelFormat(), &bmpdataCtx);
// HACKHACK: blend the alpha channel manually (!!!)
{
#pragma pack(1)
struct Pixel
{
unsigned char Blue;
unsigned char Green;
unsigned char Red;
unsigned char Alpha;
};
#pragma pack()
Pixel* pBackground = (Pixel*)bmpdataCtx.Scan0;
Pixel* pText = (Pixel*)bmpdataTemp.Scan0;
for (UINT y = 0; y < bmpdataTemp.Height; y++)
{
for (UINT x = 0; x < bmpdataTemp.Width; x++)
{
UINT indexBG = y * (bmpdataCtx.Stride / sizeof(UINT)) + x;
UINT indexText = y * (bmpdataTemp.Stride / sizeof(UINT)) + x;
// if (pText[indexText].Red = 0xFF && pText[indexText].Blue == 0xFF && pText[indexText].Green == 0xFF)
// pBackground[indexBG].Alpha = 255;
pBackground[indexBG].Red = min(255, (UINT)pBackground[indexBG].Red + (UINT)pText[indexText].Red);
pBackground[indexBG].Blue = min(255, (UINT)pBackground[indexBG].Blue + (UINT)pText[indexText].Blue);
pBackground[indexBG].Green = min(255, (UINT)pBackground[indexBG].Green + (UINT)pText[indexText].Green);
}
}
}
ctx.pBitmap->UnlockBits(&bmpdataCtx);
bmpTemp.UnlockBits(&bmpdataTemp);
}