if (c == _T('\t'))
nActualLength += (nTabSize - nActualLength % nTabSize);
else
- nActualLength += GetCharWidthFromChar(c);
+ nActualLength += GetCharCellCountFromChar(c);
}
}
else
{
line += pszChars[i];
- nCurPos += GetCharWidthFromChar(pszChars[i]) / GetCharWidth();
+ nCurPos += GetCharCellCountFromChar(pszChars[i]);
}
}
}
for (int i1=0; i1<nLength; ++i1)
{
line += pszChars[i1];
- nCurPos += GetCharWidthFromChar(pszChars[i1]) / GetCharWidth();
+ nCurPos += GetCharCellCountFromChar(pszChars[i1]);
}
}
return nCurPos;
}
-/**
- * @brief Return width of specified character
- */
-int CCrystalTextView::GetCharWidthFromChar(TCHAR ch)
-{
- if (ch >= _T('\x00') && ch <= _T('\x1F') && ch != '\t')
- return GetCharWidth() * 3;
- // This assumes a fixed width font
- // But the UNICODE case handles double-wide glyphs (primarily Chinese characters)
-#ifdef _UNICODE
- return GetCharWidthUnicodeChar(ch);
-#else
- return GetCharWidth();
-#endif
-}
-/**
- * @brief Return width of specified string
- */
-int CCrystalTextView::GetCharWidthFromString(LPCTSTR lpsz)
-{
- // This assumes a fixed width font
- // But the UNICODE case handles double-wide glyphs (primarily Chinese characters)
-#ifdef _UNICODE
- int n=0;
- for (LPCTSTR p = lpsz; *p; ++p)
- n += GetCharWidthUnicodeChar(*p);
- return n;
-#else
- return strlen(lpsz) * GetCharWidth();
-#endif
-}
-
-/**
- * @brief Return width of displayable version of character
- *
- * Differs from GetCharWidthFromChar when viewable whitespace is involved
- */
-int CCrystalTextView::GetCharWidthFromDisplayableChar(const ViewableWhitespaceChars * lpspc, TCHAR ch)
-{
- if (ch == ' ')
- {
- if (m_bViewTabs)
- return GetCharWidthFromString(lpspc->c_space);
- }
- return GetCharWidthFromChar(ch);
-}
/**
* @brief Draw a chunk of text (one color, one line, full or part of line)
const int clipLeft = rcClip.left - nCharWidth * 2;
for ( ; i < lineLen; i++)
{
- int pnWidthsCurrent = GetCharWidthFromChar(line[i]);
+ int pnWidthsCurrent = GetCharCellCountFromChar(line[i]) * nCharWidth;
#ifndef _UNICODE
if (_ismbblead(line[i]))
pnWidthsCurrent *= 2;
}
else
{
- nSumWidth += nWidths[i - ibegin] = GetCharWidthFromChar(line[i]);
+ nSumWidth += nWidths[i - ibegin] = GetCharCellCountFromChar(line[i]) * nCharWidth;
}
}
// Update the final position after the right clipped characters
for ( ; i < lineLen; i++)
{
- ptOrigin.x += GetCharWidthFromChar(line[i]);
+ ptOrigin.x += GetCharCellCountFromChar(line[i]) * nCharWidth;
}
}
}
int CCrystalTextView::CursorPointToCharPos( int nLineIndex, const CPoint &curPoint )
{
- const ViewableWhitespaceChars * lpspc = GetViewableWhitespaceChars(GetACP());
// calculate char pos out of point
const int nLength = GetLineLength( nLineIndex );
const int nScreenChars = GetScreenChars();
if (szLine[nIndex] == _T('\t'))
nOffset = nTabSize - nCurPos % nTabSize;
else
- nOffset = GetCharWidthFromDisplayableChar(lpspc, szLine[nIndex]) / GetCharWidth();
+ nOffset = GetCharCellCountFromChar(szLine[nIndex]);
nXPos += nOffset;
nCurPos += nOffset;
CPoint CCrystalTextView::
ClientToText (const CPoint & point)
{
- const ViewableWhitespaceChars * lpspc = GetViewableWhitespaceChars(GetACP());
//BEGIN SW
const int nSubLineCount = GetSubLineCount();
const int nLineCount = GetLineCount();
if (pszLine[nIndex] == '\t')
nOffset = nTabSize - nCurPos % nTabSize;
else
- nOffset = GetCharWidthFromDisplayableChar(lpspc, pszLine[nIndex]) / GetCharWidth();
+ nOffset = GetCharCellCountFromChar(pszLine[nIndex]);
n += nOffset;
nCurPos += nOffset;
CPoint CCrystalTextView::
TextToClient (const CPoint & point)
{
- const ViewableWhitespaceChars * lpspc = GetViewableWhitespaceChars(GetACP());
ASSERT_VALIDTEXTPOS (point);
LPCTSTR pszLine = GetLineChars (point.y);
if (pszLine[nIndex] == _T ('\t'))
pt.x += (nTabSize - pt.x % nTabSize);
else
- pt.x += GetCharWidthFromDisplayableChar(lpspc, pszLine[nIndex]) / GetCharWidth();
+ pt.x += GetCharCellCountFromChar(pszLine[nIndex]);
}
//BEGIN SW
pt.x-= nPreOffset;
int CCrystalTextView::
CalculateActualOffset (int nLineIndex, int nCharIndex, bool bAccumulate)
{
- const ViewableWhitespaceChars * lpspc = GetViewableWhitespaceChars(GetACP());
const int nLength = GetLineLength (nLineIndex);
ASSERT (nCharIndex >= 0 && nCharIndex <= nLength);
LPCTSTR pszChars = GetLineChars (nLineIndex);
if (pszChars[I] == _T ('\t'))
nOffset += (nTabSize - nOffset % nTabSize);
else
- nOffset += GetCharWidthFromDisplayableChar(lpspc, pszChars[I]) / GetCharWidth();
+ nOffset += GetCharCellCountFromChar(pszChars[I]);
}
if (bAccumulate)
return nOffset;
int CCrystalTextView::
ApproxActualOffset (int nLineIndex, int nOffset)
{
- const ViewableWhitespaceChars * lpspc = GetViewableWhitespaceChars(GetACP());
-
if (nOffset == 0)
return 0;
#ifndef _UNICODE
nCurrentOffset += bLeadByte ? 2 : 1;
#else
- nCurrentOffset += GetCharWidthFromDisplayableChar(lpspc, pszChars[I]) / GetCharWidth();
+ nCurrentOffset += GetCharCellCountFromChar(pszChars[I]);
#endif
}
if (nCurrentOffset >= nOffset)
}
#ifdef _UNICODE
-int CCrystalTextView::GetCharWidthUnicodeChar(wchar_t ch)
+int CCrystalTextView::GetCharCellCountUnicodeChar(wchar_t ch)
{
if (!m_bChWidthsCalculated[ch/256])
{
pdc->SelectObject(pOldFont);
}
if (m_iChDoubleWidthFlags[ch / 32] & (1 << (ch % 32)))
- return GetCharWidth() * 2;
+ return 2;
else
- return GetCharWidth();
+ return 1;
}
#endif
virtual void DrawMargin (CDC * pdc, const CRect & rect, int nLineIndex, int nLineNumber);
virtual void DrawBoundaryLine (CDC * pdc, int nLeft, int nRight, int y);
virtual void DrawLineCursor (CDC * pdc, int nLeft, int nRight, int y, int nHeight);
- int GetCharWidthFromChar(TCHAR ch);
- int GetCharWidthFromString(LPCTSTR lpsz);
- int GetCharWidthFromDisplayableChar(const ViewableWhitespaceChars * lpspc, TCHAR ch);
+
+ inline int GetCharCellCountFromChar(TCHAR ch)
+ {
+ if (ch >= _T('\x00') && ch <= _T('\x7F'))
+ {
+ if (ch <= _T('\x1F') && ch != '\t')
+ return 3;
+ else
+ return 1;
+ }
+ // This assumes a fixed width font
+ // But the UNICODE case handles double-wide glyphs (primarily Chinese characters)
+#ifdef _UNICODE
+ return GetCharCellCountUnicodeChar(ch);
+#else
+ return 1;
+#endif
+ }
#ifdef _UNICODE
bool m_bChWidthsCalculated[65536/256];
int m_iChDoubleWidthFlags[65536/32];
- int GetCharWidthUnicodeChar(wchar_t ch);
+ int GetCharCellCountUnicodeChar(wchar_t ch);
#endif
void ResetCharWidths();