зеркало из https://github.com/mozilla/pjs.git
fix crop problem for multibyte charset in WFE DrawTextEx
This commit is contained in:
Родитель
2d47e5a4fb
Коммит
44941f5440
|
@ -3402,6 +3402,8 @@ int WFE_DrawTextEx( int iCSID, HDC hdc, LPTSTR lpchText, int cchText, LPRECT lpr
|
||||||
if (cchText < 0)
|
if (cchText < 0)
|
||||||
cchText = _tcslen(lpchText);
|
cchText = _tcslen(lpchText);
|
||||||
|
|
||||||
|
/*
|
||||||
|
DrawTextEx does not handle DT_END_ELLIPSIS so please do not use the follwoing code to do optomization.
|
||||||
#ifdef XP_WIN32
|
#ifdef XP_WIN32
|
||||||
if ((dwMoreFormat == WFE_DT_CROPRIGHT) && sysInfo.m_bWin4) {
|
if ((dwMoreFormat == WFE_DT_CROPRIGHT) && sysInfo.m_bWin4) {
|
||||||
dwDTFormat |= DT_END_ELLIPSIS;
|
dwDTFormat |= DT_END_ELLIPSIS;
|
||||||
|
@ -3409,12 +3411,13 @@ int WFE_DrawTextEx( int iCSID, HDC hdc, LPTSTR lpchText, int cchText, LPRECT lpr
|
||||||
dwDTFormat, NULL);
|
dwDTFormat, NULL);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
LPTSTR pString = NULL;
|
LPTSTR pString = NULL;
|
||||||
CSize cs = CIntlWin::GetTextExtent( iCSID, hdc, lpchText, cchText);
|
CSize cs = CIntlWin::GetTextExtent( iCSID, hdc, lpchText, cchText);
|
||||||
|
|
||||||
if (cs.cx > (lprc->right - lprc->left) ) {
|
if (cs.cx > (lprc->right - lprc->left) ) {
|
||||||
int iNumToRemove = 0;
|
|
||||||
int iEllipsesLength = _tcslen(STRING_ELLIPSES);
|
int iEllipsesLength = _tcslen(STRING_ELLIPSES);
|
||||||
|
|
||||||
pString = new _TCHAR[cchText + iEllipsesLength + 2];
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
_tcscpy(pString,lpchText);
|
_tcscpy(pString,lpchText);
|
||||||
while ( cs.cx > (lprc->right - lprc->left) ) {
|
|
||||||
if (++iNumToRemove >= cchText) {
|
switch(dwMoreFormat) {
|
||||||
delete [] pString;
|
case WFE_DT_CROPRIGHT:
|
||||||
return cs.cy;
|
{
|
||||||
}
|
int iEnd = cchText;
|
||||||
switch (dwMoreFormat) {
|
while( cs.cx > (lprc->right - lprc->left) )
|
||||||
case WFE_DT_CROPRIGHT:
|
|
||||||
_tcscpy(&pString[cchText - iNumToRemove], STRING_ELLIPSES);
|
|
||||||
break;
|
|
||||||
case WFE_DT_CROPCENTER:
|
|
||||||
{
|
{
|
||||||
int iLeft = (cchText - iNumToRemove) / 2;
|
int iNewEnd = INTL_PrevCharIdxInText(iCSID, (unsigned char*) lpchText, iEnd);
|
||||||
int iRight = iLeft + ((cchText - iNumToRemove)%2);
|
if ((iNewEnd == 0) || (iNewEnd == iEnd)) {
|
||||||
_tcscpy(&pString[iLeft], STRING_ELLIPSES);
|
delete [] pString;
|
||||||
_tcscpy(&pString[iLeft+iEllipsesLength],
|
return cs.cy;
|
||||||
&lpchText[cchText-iRight]);
|
}
|
||||||
|
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, STRING_ELLIPSES);
|
||||||
_tcscpy(&pString[iEllipsesLength],
|
_tcscpy(&pString[iEllipsesLength],
|
||||||
&lpchText[iNumToRemove]);
|
&lpchText[iNewBegin]);
|
||||||
break;
|
cs = CIntlWin::GetTextExtent( iCSID, hdc, pString, strlen(pString));
|
||||||
}
|
}
|
||||||
cs = CIntlWin::GetTextExtent( iCSID, hdc, pString, strlen(pString));
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
lpchText = pString;
|
lpchText = pString;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче