SizeF stringSize, strSize(1000,1000);
if (m_bStatic)
{
/// <静止,居中>
fmt.SetAlignment(StringAlignmentCenter);
fmt.SetLineAlignment(StringAlignmentCenter);
graph.MeasureString(m_wstrText.c_str(), m_wstrText.length(), &font, strSize, &fmt, &stringSize);
RectF rectf(m_rect.GetLeft(), m_rect.GetTop(), m_rect.Width, min(m_rect.Height, stringSize.Height));
DrawString(graph, m_wstrText, font, solidBrush, rectf, fmt);
}
else
{
/// <左移,左对齐>
fmt.SetAlignment(StringAlignmentNear);
fmt.SetLineAlignment(StringAlignmentNear);
/// <测量输出字符串所需要的矩形空间>
std::wstring wstr = m_wstrText;
graph.MeasureString(wstr.c_str(), wstr.length(), &font, strSize, &fmt, &stringSize);
double fProgress = m_timeInfo.GetProgress();
//REAL fOffsetX = max(m_rect.Width, stringSize.Width) * fProgress;
REAL fOffsetX = (stringSize.Width + m_rect.Width) * fProgress;
REAL fDiffx = fOffsetX - m_rect.Width;
if (fDiffx > 0.000001)
{
int nLength = 1;
std::wstring wstrTmp = L"";
do
{
wstrTmp = wstr.substr(0, nLength++);
graph.MeasureString(wstrTmp.c_str(), wstrTmp.length(), &font, strSize, &fmt, &stringSize);
}while(stringSize.Width < abs(fDiffx));
--nLength;
wstr = wstr.substr(nLength, wstr.length() - nLength);
}
graph.MeasureString(L"1", 2, &font, strSize, &fmt, &stringSize);
fOffsetX = max(m_rect.GetLeft(), m_rect.GetRight() - fOffsetX);
RectF rect(fOffsetX, m_rect.GetTop(), min(m_rect.Width, max(1, m_rect.GetRight() - fOffsetX)), min(m_rect.Height, stringSize.Height));
DrawString(graph, wstr, font, solidBrush, rect, fmt);
}