rtoss

Subversion Repositories:
Compare Path: Rev
With Path: Rev
/GreenPad/kilib/textfile.cpp @ 106  →  /GreenPad/kilib/textfile.cpp @ 107
/GreenPad/kilib/textfile.cpp
@@ -843,11 +843,39 @@
IMultiLanguage2 *lang = NULL;
if( S_OK == ::CoCreateInstance(CLSID_CMultiLanguage, NULL, CLSCTX_ALL, IID_IMultiLanguage2, (LPVOID*)&lang ) )
{
int detectEncCount = 1;
DetectEncodingInfo detectEnc;
lang->DetectInputCodepage(MLDETECTCP_DBCS, 0, (char *)(ptr), (INT *)(&siz), &detectEnc, &detectEncCount); // 2 ugly C-cast here
cs = detectEnc.nCodePage;
int detectEncCount = 5;
DetectEncodingInfo detectEnc[5];
lang->DetectInputCodepage(MLDETECTCP_DBCS, 0, (char *)(ptr), (INT *)(&siz), detectEnc, &detectEncCount); // 2 ugly C-cast here
 
// MLang fine tunes
if ( detectEncCount > 1 && detectEnc[0].nCodePage == 1252 ) // something it gives multiple results with 1252 in the first
{
if ( detectEncCount == 2 && detectEnc[1].nCodePage == 850 ) // seems to be wrongly detected
{
cs = defCs;
}
else
{
cs = detectEnc[detectEncCount-1].nCodePage; // always use last one
}
}
else if ( detectEncCount > 1 && detectEnc[0].nCodePage > 950 ) // non asian codepage in first
{
int highestConfidence = 0;
for(int x=0;x<detectEncCount;x++)
{
if(highestConfidence < detectEnc[x].nConfidence)
{
highestConfidence = detectEnc[x].nConfidence; // use codepage with highest Confidence
cs = detectEnc[x].nCodePage;
}
}
}
else
{
cs = detectEnc[0].nCodePage;
}
 
# ifdef MLANG_DEBUG
TCHAR tmp[10];
::wsprintf(tmp,TEXT("%d"),cs);