/** * @brief Set default font values. */ void CMergeApp::SetFontDefaults() { USES_CONVERSION; LOGFONT lfDefault; ZeroMemory(&lfDefault, sizeof(LOGFONT)); MIMECPINFO cpi = {0}; cpi.bGDICharset = ANSI_CHARSET; wcscpy(cpi.wszFixedWidthFont, L"Courier New"); IMultiLanguage *pMLang = NULL; HRESULT hr = CoCreateInstance(CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER, IID_IMultiLanguage, (void **)&pMLang); if (SUCCEEDED(hr)) { hr = pMLang->GetCodePageInfo(GetACP(), &cpi); pMLang->Release(); } m_pOptions->InitOption(OPT_FONT_FILECMP_CHARSET, (int) cpi.bGDICharset); m_pOptions->InitOption(OPT_FONT_FILECMP_FACENAME, W2T(cpi.wszFixedWidthFont)); m_pOptions->InitOption(OPT_FONT_DIRCMP_CHARSET, (int) cpi.bGDICharset); m_pOptions->InitOption(OPT_FONT_DIRCMP_FACENAME, W2T(cpi.wszFixedWidthFont)); }
LanguageManager::LanguageManager() { IEnumCodePage* enumInterface; IMultiLanguage* mli = FontCache::getMultiLanguageInterface(); if (mli && S_OK == mli->EnumCodePages(MIMECONTF_BROWSER, &enumInterface)) { MIMECPINFO cpInfo; ULONG ccpInfo; while (S_OK == enumInterface->Next(1, &cpInfo, &ccpInfo) && ccpInfo) { if (!IsValidCodePage(cpInfo.uiCodePage)) continue; HashMap<UINT, CString>::iterator i = codePageCharsets().find(cpInfo.uiCodePage); CString name(String(cpInfo.wszWebCharset).latin1()); if (i == codePageCharsets().end()) { CharsetInfo info; info.m_codePage = cpInfo.uiCodePage; knownCharsets().set(name.data(), info); i = codePageCharsets().set(cpInfo.uiCodePage, name).iterator; } if (i != codePageCharsets().end()) { HashMap<String, CharsetInfo>::iterator j = knownCharsets().find(String(i->second.data(), i->second.length())); ASSERT(j != knownCharsets().end()); CharsetInfo& info = j->second; info.m_name = i->second.data(); info.m_friendlyName = cpInfo.wszDescription; info.m_aliases.append(name); info.m_aliases.append(String(cpInfo.wszHeaderCharset).latin1()); info.m_aliases.append(String(cpInfo.wszBodyCharset).latin1()); String cpName = "cp" + String::number(cpInfo.uiCodePage); info.m_aliases.append(cpName.latin1()); supportedCharsets().add(i->second.data()); } } enumInterface->Release(); } }
unsigned char* web_page::load_utf8_file( LPCWSTR path, bool is_html, LPCWSTR defEncoding ) { unsigned char* ret = NULL; HANDLE fl = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if(fl != INVALID_HANDLE_VALUE) { DWORD size = GetFileSize(fl, NULL); ret = new unsigned char[size + 1]; DWORD cbRead = 0; if(size >= 3) { ReadFile(fl, ret, 3, &cbRead, NULL); if(ret[0] == '\xEF' && ret[1] == '\xBB' && ret[2] == '\xBF') { ReadFile(fl, ret, size - 3, &cbRead, NULL); ret[cbRead] = 0; } else { ReadFile(fl, ret + 3, size - 3, &cbRead, NULL); ret[cbRead + 3] = 0; } } CloseHandle(fl); } // try to convert encoding if(is_html) { std::wstring encoding; char* begin = StrStrIA((LPSTR) ret, "<meta"); while(begin && encoding.empty()) { char* end = StrStrIA(begin, ">"); char* s1 = StrStrIA(begin, "Content-Type"); if(s1 && s1 < end) { s1 = StrStrIA(begin, "charset"); if(s1) { s1 += strlen("charset"); while(!isalnum(s1[0]) && s1 < end) { s1++; } while((isalnum(s1[0]) || s1[0] == '-') && s1 < end) { encoding += s1[0]; s1++; } } } if(encoding.empty()) { begin = StrStrIA(begin + strlen("<meta"), "<meta"); } } if(encoding.empty() && defEncoding) { encoding = defEncoding; } if(!encoding.empty()) { if(!StrCmpI(encoding.c_str(), L"UTF-8")) { encoding.clear(); } } if(!encoding.empty()) { CoInitialize(NULL); IMultiLanguage* ml = NULL; HRESULT hr = CoCreateInstance(CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER, IID_IMultiLanguage, (LPVOID*) &ml); MIMECSETINFO charset_src = {0}; MIMECSETINFO charset_dst = {0}; BSTR bstrCharSet = SysAllocString(encoding.c_str()); ml->GetCharsetInfo(bstrCharSet, &charset_src); SysFreeString(bstrCharSet); bstrCharSet = SysAllocString(L"utf-8"); ml->GetCharsetInfo(bstrCharSet, &charset_dst); SysFreeString(bstrCharSet); DWORD dwMode = 0; UINT szDst = (UINT) strlen((LPSTR) ret) * 4; LPSTR dst = new char[szDst]; if(ml->ConvertString(&dwMode, charset_src.uiInternetEncoding, charset_dst.uiInternetEncoding, (LPBYTE) ret, NULL, (LPBYTE) dst, &szDst) == S_OK) { dst[szDst] = 0; delete ret; ret = (unsigned char*) dst; } else { delete dst; } CoUninitialize(); } } return ret; }
const vmime::charset windowsHandler::getLocalCharset() const { #if VMIME_HAVE_MLANG char szCharset[256]; CoInitialize(NULL); { IMultiLanguage* pMultiLanguage; CoCreateInstance( CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER, IID_IMultiLanguage, (void**)&pMultiLanguage); UINT codePage = GetACP(); MIMECPINFO cpInfo; pMultiLanguage->GetCodePageInfo(codePage, &cpInfo); int nLengthW = lstrlenW(cpInfo.wszBodyCharset) + 1; WideCharToMultiByte(codePage, 0, cpInfo.wszBodyCharset, nLengthW, szCharset, sizeof(szCharset), NULL, NULL ); pMultiLanguage->Release(); } CoUninitialize(); return vmime::charset(szCharset); #else // VMIME_HAVE_MLANG vmime::string ch = vmime::charsets::ISO8859_1; // default switch (GetACP()) { case 437: ch = vmime::charsets::CP_437; break; case 737: ch = vmime::charsets::CP_737; break; case 775: ch = vmime::charsets::CP_775; break; case 850: ch = vmime::charsets::CP_850; break; case 852: ch = vmime::charsets::CP_852; break; case 853: ch = vmime::charsets::CP_853; break; case 855: ch = vmime::charsets::CP_855; break; case 857: ch = vmime::charsets::CP_857; break; case 858: ch = vmime::charsets::CP_858; break; case 860: ch = vmime::charsets::CP_860; break; case 861: ch = vmime::charsets::CP_861; break; case 862: ch = vmime::charsets::CP_862; break; case 863: ch = vmime::charsets::CP_863; break; case 864: ch = vmime::charsets::CP_864; break; case 865: ch = vmime::charsets::CP_865; break; case 866: ch = vmime::charsets::CP_866; break; case 869: ch = vmime::charsets::CP_869; break; case 874: ch = vmime::charsets::CP_874; break; case 1125: ch = vmime::charsets::CP_1125; break; case 1250: ch = vmime::charsets::CP_1250; break; case 1251: ch = vmime::charsets::CP_1251; break; case 1252: ch = vmime::charsets::CP_1252; break; case 1253: ch = vmime::charsets::CP_1253; break; case 1254: ch = vmime::charsets::CP_1254; break; case 1255: ch = vmime::charsets::CP_1255; break; case 1256: ch = vmime::charsets::CP_1256; break; case 1257: ch = vmime::charsets::CP_1257; break; case 28591: ch = vmime::charsets::ISO8859_1; break; case 28592: ch = vmime::charsets::ISO8859_2; break; case 28593: ch = vmime::charsets::ISO8859_3; break; case 28594: ch = vmime::charsets::ISO8859_4; break; case 28595: ch = vmime::charsets::ISO8859_5; break; case 28596: ch = vmime::charsets::ISO8859_6; break; case 28597: ch = vmime::charsets::ISO8859_7; break; case 28598: ch = vmime::charsets::ISO8859_8; break; case 28599: ch = vmime::charsets::ISO8859_9; break; case 28605: ch = vmime::charsets::ISO8859_15; break; case 65000: ch = vmime::charsets::UTF_7; break; case 65001: ch = vmime::charsets::UTF_8; break; } return (vmime::charset(ch)); #endif }