From 44941f5440b87c56feca1f6270179e79eea0b6db Mon Sep 17 00:00:00 2001 From: "ftang%netscape.com" Date: Mon, 12 Oct 1998 12:06:53 +0000 Subject: [PATCH] fix crop problem for multibyte charset in WFE DrawTextEx --- cmd/winfe/fegui.cpp | 74 +++++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 22 deletions(-) diff --git a/cmd/winfe/fegui.cpp b/cmd/winfe/fegui.cpp index 4df4fc17411..6aad76a0e79 100755 --- a/cmd/winfe/fegui.cpp +++ b/cmd/winfe/fegui.cpp @@ -3402,6 +3402,8 @@ int WFE_DrawTextEx( int iCSID, HDC hdc, LPTSTR lpchText, int cchText, LPRECT lpr if (cchText < 0) cchText = _tcslen(lpchText); +/* + DrawTextEx does not handle DT_END_ELLIPSIS so please do not use the follwoing code to do optomization. #ifdef XP_WIN32 if ((dwMoreFormat == WFE_DT_CROPRIGHT) && sysInfo.m_bWin4) { dwDTFormat |= DT_END_ELLIPSIS; @@ -3409,12 +3411,13 @@ int WFE_DrawTextEx( int iCSID, HDC hdc, LPTSTR lpchText, int cchText, LPRECT lpr dwDTFormat, NULL); } #endif +*/ LPTSTR pString = NULL; CSize cs = CIntlWin::GetTextExtent( iCSID, hdc, lpchText, cchText); if (cs.cx > (lprc->right - lprc->left) ) { - int iNumToRemove = 0; + int iEllipsesLength = _tcslen(STRING_ELLIPSES); pString = new _TCHAR[cchText + iEllipsesLength + 2]; @@ -3423,31 +3426,58 @@ int WFE_DrawTextEx( int iCSID, HDC hdc, LPTSTR lpchText, int cchText, LPRECT lpr return 0; } _tcscpy(pString,lpchText); - while ( cs.cx > (lprc->right - lprc->left) ) { - if (++iNumToRemove >= cchText) { - delete [] pString; - return cs.cy; - } - switch (dwMoreFormat) { - case WFE_DT_CROPRIGHT: - _tcscpy(&pString[cchText - iNumToRemove], STRING_ELLIPSES); - break; - case WFE_DT_CROPCENTER: + + switch(dwMoreFormat) { + case WFE_DT_CROPRIGHT: + { + int iEnd = cchText; + while( cs.cx > (lprc->right - lprc->left) ) { - int iLeft = (cchText - iNumToRemove) / 2; - int iRight = iLeft + ((cchText - iNumToRemove)%2); - _tcscpy(&pString[iLeft], STRING_ELLIPSES); - _tcscpy(&pString[iLeft+iEllipsesLength], - &lpchText[cchText-iRight]); + int iNewEnd = INTL_PrevCharIdxInText(iCSID, (unsigned char*) lpchText, iEnd); + if ((iNewEnd == 0) || (iNewEnd == iEnd)) { + delete [] pString; + return cs.cy; + } + iEnd = iNewEnd; + _tcscpy(&pString[iNewEnd], STRING_ELLIPSES); + cs = CIntlWin::GetTextExtent( iCSID, hdc, pString, strlen(pString)); } - break; - case WFE_DT_CROPLEFT: + } + break; + case WFE_DT_CROPCENTER: + { + int iRemove = 0; + while( cs.cx > (lprc->right - lprc->left) ) + { + if (++iRemove >= cchText) { + delete [] pString; + return cs.cy; + } + INTL_MidTruncateString(iCSID, lpchText, pString, cchText-iRemove); + cs = CIntlWin::GetTextExtent( iCSID, hdc, pString, strlen(pString)); + } + } + break; + case WFE_DT_CROPLEFT: + { + int iBegin = 0; + while( cs.cx > (lprc->right - lprc->left) ) + { + int iNewBegin = INTL_NextCharIdxInText(iCSID, (unsigned char*) lpchText, iBegin); + if ((iNewBegin >= cchText) || (iNewBegin == iBegin)) { + delete [] pString; + return cs.cy; + } + iBegin = iNewBegin; _tcscpy(pString, STRING_ELLIPSES); _tcscpy(&pString[iEllipsesLength], - &lpchText[iNumToRemove]); - break; - } - cs = CIntlWin::GetTextExtent( iCSID, hdc, pString, strlen(pString)); + &lpchText[iNewBegin]); + cs = CIntlWin::GetTextExtent( iCSID, hdc, pString, strlen(pString)); + } + } + break; + + } lpchText = pString; }