xhtmlstatic.cpp
来自「管理项目进度工具的原代码」· C++ 代码 · 共 1,326 行 · 第 1/3 页
CPP
1,326 行
m_bSuperscript++;// = TRUE;
continue;
}
///////////////////////////////////////////////////////////////////////
else if (_tcsnicmp(strText, _T("</SUP>"), 6) == 0) // check for </SUP>
{
n -= 6;
index = strText.Find(_T('>'));
if (index != -1)
strText = strText.Mid(index+1);
if (m_bSuperscript)
m_bSuperscript--;// = FALSE;
continue;
}
///////////////////////////////////////////////////////////////////////
else if (_tcsnicmp(strText, _T("<FONT"), 5) == 0) // check for <FONT
{
index = strText.Find(_T('>'));
if (index != -1)
{
CString strAttributes = strText.Mid(5, index-5);
int m = strAttributes.GetLength();
strText = strText.Mid(index+1);
// loop to parse FONT attributes
while (m > 0)
{
// trim left whitespace
if ((strAttributes.GetLength() > 0) &&
(strAttributes[0] == _T(' ')))
{
m--;
strAttributes = strAttributes.Mid(1);
continue;
}
///////////////////////////////////////////////////////////
if (_tcsnicmp(strAttributes, _T("COLOR"), 5) == 0)
{
int index2 = strAttributes.Find(_T('"'));
if (index2 != -1)
{
m -= index2 + 1;
strAttributes = strAttributes.Mid(index2+1);
index2 = strAttributes.Find(_T('"'));
if (index2 != -1)
{
CString strColor = strAttributes.Left(index2);
CXNamedColors nc(strColor);
crText = nc.GetRGB();
strAttributes = strAttributes.Mid(index2+1);
m = strAttributes.GetLength();
}
}
else
break;
}
///////////////////////////////////////////////////////////
else if (_tcsnicmp(strAttributes, _T("BGCOLOR"), 7) == 0)
{
int index2 = strAttributes.Find(_T('"'));
if (index2 != -1)
{
m -= index2 + 1;
strAttributes = strAttributes.Mid(index2+1);
index2 = strAttributes.Find(_T('"'));
if (index2 != -1)
{
CString strBgColor = strAttributes.Left(index2);
CXNamedColors nc(strBgColor);
crBackground = nc.GetRGB();
strAttributes = strAttributes.Mid(index2+1);
m = strAttributes.GetLength();
}
}
else
break;
}
///////////////////////////////////////////////////////////
else if (_tcsnicmp(strAttributes, _T("FACE"), 4) == 0)
{
int index2 = strAttributes.Find(_T('"'));
if (index2 != -1)
{
m -= index2 + 1;
strAttributes = strAttributes.Mid(index2+1);
index2 = strAttributes.Find(_T('"'));
if (index2 != -1)
{
memset(lf.lfFaceName, 0, sizeof(lf.lfFaceName));
//fabio_2005
#if _MSC_VER >= 1400
_tcsncpy_s(lf.lfFaceName, strAttributes, index2);
#else
_tcsncpy(lf.lfFaceName, strAttributes, index2);
#endif
m -= index2 + 1;
if (m > 0)
strAttributes = strAttributes.Mid(index2+1);
else
strAttributes = _T("");
m = strAttributes.GetLength();
}
}
else
break;
}
///////////////////////////////////////////////////////////
else if (_tcsnicmp(strAttributes, _T("SIZE"), 4) == 0)
{
int index2 = strAttributes.Find(_T('"'));
if (index2 != -1)
{
m -= index2 + 1;
strAttributes = strAttributes.Mid(index2+1);
index2 = strAttributes.Find(_T('"'));
if (index2 != -1)
{
int nSize = 0;
nSize = _ttoi(strAttributes);
lf.lfHeight -= nSize;
bSizeChange = TRUE;
m -= index2 + 1;
if (m > 0)
strAttributes = strAttributes.Mid(index2+1);
else
strAttributes = _T("");
m = strAttributes.GetLength();
}
}
else
break;
}
else
{
while ((strAttributes.GetLength() > 0) &&
(strAttributes[0] != _T(' ')))
{
m--;
strAttributes = strAttributes.Mid(1);
}
}
}
n -= index + 1;
}
continue;
}
///////////////////////////////////////////////////////////////////////
else if (_tcsnicmp(strText, _T("</FONT>"), 7) == 0) // check for </FONT>
{
n -= 7;
index = strText.Find(_T('>'));
if (index != -1)
strText = strText.Mid(index+1);
crText = prev_crText;
crBackground = prev_crBackground;
memcpy(&lf, &prev_lf, sizeof(lf));
if (bSizeChange)
m_yStart += tm.tmDescent;
bSizeChange = FALSE;
continue;
}
///////////////////////////////////////////////////////////////////////
else if (_tcsnicmp(strText, _T("<CODE>"), 6) == 0) // check for <CODE>
{
n -= 6;
index = strText.Find(_T('>'));
if (index != -1)
strText = strText.Mid(index+1);
//fabio_2005
#if _MSC_VER >= 1400
_tcscpy_s(lf.lfFaceName, _T("Courier New"));
#else
_tcscpy(lf.lfFaceName, _T("Courier New"));
#endif
continue;
}
///////////////////////////////////////////////////////////////////////
else if (_tcsnicmp(strText, _T("</CODE>"), 7) == 0) // check for </CODE>
{
n -= 7;
index = strText.Find(_T('>'));
if (index != -1)
strText = strText.Mid(index+1);
memcpy(&lf, &prev_lf, sizeof(lf));
continue;
}
///////////////////////////////////////////////////////////////////////
// <a href=www.xyz.com>XYZ Web Site</a>
else if (_tcsnicmp(strText, _T("<A HREF="), 8) == 0) // check for <A HREF=
{
index = strText.Find(_T('>'));
if (index != -1)
{
strAnchorText = strText.Mid(8, index-8);
strText = strText.Mid(index+1);
n = strText.GetLength();
m_bInAnchor = TRUE;
continue;
}
}
///////////////////////////////////////////////////////////////////////
else if (_tcsnicmp(strText, _T("</A>"), 4) == 0) // check for </A>
{
strText = strText.Mid(4);
n -= 4;
m_bInAnchor = FALSE;
continue;
}
///////////////////////////////////////////////////////////////////////
else if (_tcsnicmp(strText, _T("<HR"), 3) == 0) // check for <HR>
{
index = strText.Find(_T('>'));
if (index != -1)
{
CString strAttributes = strText.Mid(3); //, index-3);
int m = strAttributes.GetLength();
strText = strText.Mid(index+1);
// loop to parse attributes
while (m > 0)
{
// trim left whitespace
if ((strAttributes.GetLength() > 0) &&
(strAttributes[0] == _T(' ')))
{
m--;
strAttributes = strAttributes.Mid(1);
continue;
}
///////////////////////////////////////////////////////////
if (_tcsnicmp(strAttributes, _T("SIZE"), 4) == 0)
{
int index2 = strAttributes.Find(_T('='));
if (index2 != -1)
{
m -= index2 + 1;
strAttributes = strAttributes.Mid(index2+1);
index2 = strAttributes.Find(_T('>'));
if (index2 != -1)
{
CString strSize = strAttributes.Left(index2);
m_nHorizontalRuleSize = _ttoi(strSize);
strAttributes = strAttributes.Mid(index2+1);
m = strAttributes.GetLength();
}
}
else
break;
}
else
{
while ((strAttributes.GetLength() > 0) &&
(strAttributes[0] != _T(' ')))
{
m--;
strAttributes = strAttributes.Mid(1);
}
}
}
n -= index + 1;
}
m_bHorizontalRule++;// = TRUE;
str1 = _T("\r\n");
m_bGeneratedText = TRUE;
}
///////////////////////////////////////////////////////////////////////
// <br> or \r\n or plain text
else
{
str1 = strText;
index = str1.Find(_T('<'));
if (index != -1)
{
if (_tcsnicmp(strText, _T("<BR>"), 4) == 0) // check for <BR>
{
n -= 4;
str1 = _T("\r\n");
m_bGeneratedText = TRUE;
strText = strText.Mid(4);
}
else
{
str1 = strText.Left(index);
if (str1.GetLength() <= 0)
{
if (strText.GetLength() != 0)
{
str1 = strText[0];
index = 1;
n -= 1;
}
}
strText = strText.Mid(index);
}
}
else
{
str1 = strText;
strText = _T("");
}
}
lf.lfWeight = m_bBold ? FW_BOLD : FW_NORMAL;
lf.lfUnderline = (BYTE) m_bUnderline;
lf.lfItalic = (BYTE) m_bItalic;
lf.lfStrikeOut = (BYTE) m_bStrikeThrough;
m_font.DeleteObject();
VERIFY(m_font.CreateFontIndirect(&lf));
dc.SetTextColor(crText);
dc.SetBkColor(crBackground);
dc.SelectObject(&m_font);
dc.GetTextMetrics(&tm);
int nBaselineAdjust = tm.tmAscent / 2;
if (m_bSubscript)
{
rect.top += nBaselineAdjust;
rect.bottom += nBaselineAdjust;
m_yStart += nBaselineAdjust;
}
if (m_bSuperscript)
{
rect.top -= nBaselineAdjust;
rect.bottom -= nBaselineAdjust;
m_yStart -= nBaselineAdjust;
}
nInitialXOffset = FormatText(dc.m_hDC, str1, &rect, nInitialXOffset);
if (str1 == _T("\r\n"))
{
nInitialXOffset = 0;
}
if (m_bSubscript)
{
rect.top -= nBaselineAdjust;
rect.bottom -= nBaselineAdjust;
m_yStart -= nBaselineAdjust;
}
if (m_bSuperscript)
{
rect.top += nBaselineAdjust;
rect.bottom += nBaselineAdjust;
m_yStart += nBaselineAdjust;
}
if (m_bInAnchor)
{
SIZE size;
GetTextExtentPoint32(dc.m_hDC, str1, str1.GetLength(), &size);
CRect rectDraw = rect;
rectDraw.bottom = rectDraw.top + size.cy;
rectDraw.left = nInitialXOffset - size.cx;
rectDraw.right = nInitialXOffset;
// save rect for this text - save in window coordinates
CRect *pRect = new CRect(rectDraw);
m_AnchorRectPtrs.Add(pRect);
m_AnchorUrls.Add(strAnchorText);
TRACE(_T("added anchor: <%s>\n"), strAnchorText);
//TRACERECT(*pRect);
if (!m_bHyperlinkTimer)
{
m_bHyperlinkTimer = TRUE;
SetTimer(1, 80, NULL);
}
}
// draw horizontal rule
if (m_bHorizontalRule)
{
int nPenWidth = m_nHorizontalRuleSize;
CPen pen(PS_SOLID, nPenWidth, crText);
CPen *pOldPen = dc.SelectObject(&pen);
dc.MoveTo(rect.left-m_nLeftMargin, rect.top);
dc.LineTo(rect.right+m_nRightMargin, rect.top);
if (pOldPen)
dc.SelectObject(pOldPen);
m_yStart += nPenWidth;
rect.top += nPenWidth;
rect.bottom += nPenWidth;
nInitialXOffset = 0;
m_bHorizontalRule--;
}
if (!m_bGeneratedText)
n -= str1.GetLength();
m_bGeneratedText = FALSE;
}
// Restore DC's State
dc.SelectObject(pOldFont);
// Do not call CStatic::OnPaint() for painting messages
}
///////////////////////////////////////////////////////////////////////////////
// IsBlank
BOOL CXHTMLStatic::IsBlank(LPCTSTR lpszText)
{
TCHAR c;
while ((c = *lpszText++) != _T('\0'))
if (c != _T(' ') && c != _T('\t'))
return FALSE;
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// FormatText
int CXHTMLStatic::FormatText(HDC hdc,
LPCTSTR lpszText,
RECT * pRect,
int nInitialXOffset)
{
TRACE(_T("in CXHTMLStatic::FormatText: nInitialXOffset=%d <%-20.20s>\n"),
nInitialXOffset, lpszText);
//TRACERECT(*pRect);
int xStart, /*yStart,*/ nWord, xNext, xLast, nLeftMargin;
TCHAR *pText = (TCHAR *) lpszText;
SIZE size;
xNext = nInitialXOffset;
nLeftMargin = nInitialXOffset;
xLast = 0;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?