当前位置: 首页>>代码示例>>C++>>正文


C++ Canvas::MeasureTextW方法代码示例

本文整理汇总了C++中gfx::Canvas::MeasureTextW方法的典型用法代码示例。如果您正苦于以下问题:C++ Canvas::MeasureTextW方法的具体用法?C++ Canvas::MeasureTextW怎么用?C++ Canvas::MeasureTextW使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gfx::Canvas的用法示例。


在下文中一共展示了Canvas::MeasureTextW方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DrawString

/*
** Draws the string or calculates it's size
**
*/
bool MeterString::DrawString(Gfx::Canvas& canvas, RectF* rect)
{
	if (!m_TextFormat->IsInitialized()) return false;

	LPCWSTR string = m_String.c_str();
	UINT stringLen = (UINT)m_String.length();

	canvas.SetTextAntiAliasing(m_AntiAlias);

	m_TextFormat->SetTrimming(
		m_ClipType == CLIP_ON ||
		(m_ClipType == CLIP_AUTO && (m_NeedsClipping || (m_WDefined && m_HDefined))));

	Gdiplus::Rect meterRect = GetMeterRectPadding();

	if (rect)
	{
		rect->X = (REAL)meterRect.X;
		rect->Y = (REAL)meterRect.Y;
		if (canvas.MeasureTextW(string, stringLen, *m_TextFormat, *rect) &&
			m_ClipType == CLIP_AUTO)
		{
			// Set initial clipping
			m_NeedsClipping = false;

			REAL w, h;
			bool updateSize = true;

			if (m_WDefined)
			{
				w = (REAL)meterRect.Width;
				h = rect->Height;
				m_NeedsClipping = true;
			}
			else if (m_HDefined)
			{
				if (m_ClipStringW == -1)
				{
					// Text does not fit in defined height, clip it
					if (rect->Height > (REAL)meterRect.Height)
					{
						m_NeedsClipping = true;
					}

					rect->Height = (REAL)meterRect.Height;
					updateSize = false;

				}
				else
				{
					if (rect->Width > (REAL)m_ClipStringW)
					{
						w = (REAL)m_ClipStringW;
						m_NeedsClipping = true;
					}
					else
					{
						w = rect->Width;
					}

					h = (REAL)meterRect.Height;
				}
			}
			else
			{
				if (m_ClipStringW == -1)
				{
					// Clip text if already larger than ClipStringH
					if (m_ClipStringH != -1 && rect->Height > (REAL)m_ClipStringH)
					{
						m_NeedsClipping = true;
						rect->Height = (REAL)m_ClipStringH;
					}

					updateSize = false;
				}
				else
				{
					if (rect->Width > (REAL)m_ClipStringW)
					{
						w = (REAL)m_ClipStringW;
						m_NeedsClipping = true;
					}
					else
					{
						w = rect->Width;
					}

					h = rect->Height;
				}
			}

			if (updateSize)
			{
				UINT lines = 0;
				RectF layout((REAL)meterRect.X, (REAL)meterRect.Y, w, h);
//.........这里部分代码省略.........
开发者ID:AlonTzarafi,项目名称:rainmeter,代码行数:101,代码来源:MeterString.cpp


注:本文中的gfx::Canvas::MeasureTextW方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。