- Implement parsing font.inf (Now it's possible to specify custom fonts for a language/locale!)

svn path=/trunk/; revision=33778
This commit is contained in:
Dmitry Chapyshev 2008-05-30 18:18:36 +00:00
parent 94ae0fcf03
commit 18eca01b10
3 changed files with 179 additions and 8 deletions

View file

@ -20,6 +20,8 @@ typedef struct CPStruct
static LPCPAGE PCPage = NULL;
static HINF hIntlInf;
static BOOL bSpain = FALSE;
static HWND hLangList;
static BOOL
GetSupportedCP(VOID)
@ -29,7 +31,7 @@ GetSupportedCP(VOID)
LPCPAGE lpCPage;
HANDLE hCPage;
CPINFOEX cpInfEx;
TCHAR Section[MAX_PATH];
//TCHAR Section[MAX_PATH];
Count = (UINT) SetupGetLineCount(hIntlInf, _T("CodePages"));
if (Count <= 0) return FALSE;
@ -58,12 +60,12 @@ GetSupportedCP(VOID)
continue;
}
_stprintf(Section, _T("%s%d"), _T("CODEPAGE_REMOVE_"), uiCPage);
/*_stprintf(Section, _T("%s%d"), _T("CODEPAGE_REMOVE_"), uiCPage);
if ((uiCPage == GetACP()) || (uiCPage == GetOEMCP()) ||
(!SetupFindFirstLine(hIntlInf, Section, _T("AddReg"), &infCont)))
{
lpCPage->Status |= (0x0001 | 0x0002);
}
}*/
lpCPage->NextItem = PCPage;
PCPage = lpCPage;
@ -81,6 +83,7 @@ InstalledCPProc(LPTSTR lpStr)
lpCP = PCPage;
uiCP = _ttol(lpStr);
for (;;)
{
if (!lpCP) break;
@ -96,7 +99,7 @@ InstalledCPProc(LPTSTR lpStr)
}
static VOID
InitLangList(HWND hwndDlg)
InitCodePagesList(HWND hwndDlg)
{
LPCPAGE lpCPage;
INT ItemIndex;
@ -109,7 +112,8 @@ InitLangList(HWND hwndDlg)
hIntlInf = SetupOpenInfFile(_T("intl.inf"), NULL, INF_STYLE_WIN4, NULL);
if (hIntlInf == INVALID_HANDLE_VALUE) return;
if (hIntlInf == INVALID_HANDLE_VALUE)
return;
if (!SetupOpenAppendInfFile(NULL, hIntlInf, NULL))
{
@ -118,11 +122,13 @@ InitLangList(HWND hwndDlg)
return;
}
if (!GetSupportedCP()) return;
if (!GetSupportedCP())
return;
SetupCloseInfFile(hIntlInf);
if (!EnumSystemCodePages(InstalledCPProc, CP_INSTALLED)) return;
if (!EnumSystemCodePages(InstalledCPProc, CP_INSTALLED))
return;
ZeroMemory(&column, sizeof(LV_COLUMN));
column.mask = LVCF_FMT|LVCF_TEXT|LVCF_WIDTH;
@ -167,6 +173,130 @@ InitLangList(HWND hwndDlg)
}
}
static BOOL CALLBACK
LocalesEnumProc(LPTSTR lpLocale)
{
LCID lcid;
TCHAR lang[255];
INT index;
BOOL bNoShow = FALSE;
lcid = _tcstoul(lpLocale, NULL, 16);
if (lcid == MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH), SORT_DEFAULT) ||
lcid == MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_MODERN), SORT_DEFAULT))
{
if (bSpain == FALSE)
{
LoadString(hApplet, IDS_SPAIN, lang, 255);
bSpain = TRUE;
}
else
{
bNoShow = TRUE;
}
}
else
{
GetLocaleInfo(lcid, LOCALE_SLANGUAGE, lang, sizeof(lang)/sizeof(TCHAR));
}
if (bNoShow == FALSE)
{
index = SendMessage(hLangList,
CB_ADDSTRING,
0,
(LPARAM)lang);
SendMessage(hLangList,
CB_SETITEMDATA,
index,
(LPARAM)lcid);
}
return TRUE;
}
static VOID
InitLanguagesList(HWND hwndDlg)
{
TCHAR langSel[255];
hLangList = GetDlgItem(hwndDlg, IDC_LANGUAGE_COMBO);
bSpain = FALSE;
EnumSystemLocales(LocalesEnumProc, LCID_SUPPORTED);
/* Select current locale */
GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SLANGUAGE, langSel, sizeof(langSel)/sizeof(TCHAR));
SendMessage(hLangList, CB_SELECTSTRING, -1, (LPARAM)langSel);
}
static VOID
GetCurrentDPI(LPTSTR szDPI)
{
DWORD dwType, dwSize, dwDPI, dwDefDPI = 0x00000060; // Default 96 DPI
HKEY hKey;
if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\FontDPI"), 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL) != ERROR_SUCCESS)
{
_tcscpy(szDPI, _T("96"));
return;
}
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
if (RegQueryValueEx(hKey, _T("LogPixels"), NULL, &dwType, (LPBYTE)&dwDPI, &dwSize) != ERROR_SUCCESS)
{
if (RegSetValueEx(hKey, _T("LogPixels"), 0, REG_DWORD, (LPBYTE)&dwDefDPI, sizeof(DWORD)) == ERROR_SUCCESS)
{
_tcscpy(szDPI, _T("96"));
RegCloseKey(hKey);
return;
}
}
else wsprintf(szDPI, _T("%d"), dwDPI);
RegCloseKey(hKey);
}
VOID
SetNonUnicodeLang(HWND hwnd, LCID lcid)
{
TCHAR szDefCP[5 + 1], szSection[MAX_PATH], szDPI[3 + 1];
HINF hFontInf;
UINT Count;
GetLocaleInfo(MAKELCID(lcid, SORT_DEFAULT), LOCALE_IDEFAULTCODEPAGE, szDefCP, sizeof(szDefCP) / sizeof(TCHAR));
GetCurrentDPI(szDPI);
wsprintf(szSection, _T("Font.CP%s.%s"), szDefCP, szDPI);
hFontInf = SetupOpenInfFile(_T("font.inf"), NULL, INF_STYLE_WIN4, NULL);
if (hFontInf == INVALID_HANDLE_VALUE)
return;
if (!SetupOpenAppendInfFile(NULL, hFontInf, NULL))
{
SetupCloseInfFile(hFontInf);
return;
}
Count = (UINT) SetupGetLineCount(hFontInf, szSection);
if (Count <= 0) return;
if (!SetupInstallFromInfSection(hwnd, hFontInf, szSection, SPINST_REGISTRY & ~SPINST_FILES,
NULL, NULL, 0, NULL, NULL, NULL, NULL))
MessageBox(hwnd, _T("Unable to install a new language for programs don't support unicode!"),
NULL, MB_ICONERROR | MB_OK);
SetupCloseInfFile(hFontInf);
}
/* Property page dialog callback */
INT_PTR CALLBACK
AdvancedPageProc(HWND hwndDlg,
@ -178,7 +308,45 @@ AdvancedPageProc(HWND hwndDlg,
{
case WM_INITDIALOG:
{
InitLangList(hwndDlg);
InitLanguagesList(hwndDlg);
InitCodePagesList(hwndDlg);
}
break;
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDC_LANGUAGE_COMBO:
{
if (HIWORD(wParam) == CBN_SELCHANGE)
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
}
break;
}
}
break;
case WM_NOTIFY:
{
LPNMHDR lpnm = (LPNMHDR)lParam;
if (lpnm->code == (UINT)PSN_APPLY)
{
LCID lcid;
INT iIndex;
iIndex = SendMessage(hLangList, CB_GETCURSEL, 0, 0);
if (iIndex == CB_ERR)
break;
lcid = SendMessage(hLangList, CB_GETITEMDATA, iIndex, 0);
if (lcid == (LCID)CB_ERR)
break;
SetNonUnicodeLang(hwndDlg, lcid);
PropSheet_UnChanged(GetParent(hwndDlg), hwndDlg);
}
}
break;
}

View file

@ -422,6 +422,7 @@ GeneralPageProc(HWND hwndDlg,
/* Set new locale */
SetNewLocale(NewLcid);
SetNonUnicodeLang(hwndDlg, NewLcid);
}
}
break;

View file

@ -32,6 +32,8 @@ LanguagesPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
/* advanced.c */
INT_PTR CALLBACK
AdvancedPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
VOID
SetNonUnicodeLang(HWND hwnd, LCID lcid);
/* currency.c */
INT_PTR CALLBACK