[ros-diffs] [dchapyshev] 33778: - Implement parsing font.inf (Now it's possible to specify custom fonts for a language/locale!)

dchapyshev at svn.reactos.org dchapyshev at svn.reactos.org
Fri May 30 20:18:36 CEST 2008


Author: dchapyshev
Date: Fri May 30 13:18:36 2008
New Revision: 33778

URL: http://svn.reactos.org/svn/reactos?rev=33778&view=rev
Log:
- Implement parsing font.inf (Now it's possible to specify custom fonts for a language/locale!)

Modified:
    trunk/reactos/dll/cpl/intl/advanced.c
    trunk/reactos/dll/cpl/intl/generalp.c
    trunk/reactos/dll/cpl/intl/intl.h

Modified: trunk/reactos/dll/cpl/intl/advanced.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/intl/advanced.c?rev=33778&r1=33777&r2=33778&view=diff
==============================================================================
--- trunk/reactos/dll/cpl/intl/advanced.c [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/intl/advanced.c [iso-8859-1] Fri May 30 13:18:36 2008
@@ -20,6 +20,8 @@
 
 static LPCPAGE PCPage = NULL;
 static HINF hIntlInf;
+static BOOL bSpain = FALSE;
+static HWND hLangList;
 
 static BOOL
 GetSupportedCP(VOID)
@@ -29,7 +31,7 @@
     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 @@
                 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 @@
 
     lpCP = PCPage;
     uiCP = _ttol(lpStr);
+
     for (;;)
     {
         if (!lpCP) break;
@@ -96,7 +99,7 @@
 }
 
 static VOID
-InitLangList(HWND hwndDlg)
+InitCodePagesList(HWND hwndDlg)
 {
     LPCPAGE lpCPage;
     INT ItemIndex;
@@ -109,7 +112,8 @@
 
     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 @@
         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 @@
     }
 }
 
+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,9 +308,47 @@
     {
         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;
     }
 
     return FALSE;

Modified: trunk/reactos/dll/cpl/intl/generalp.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/intl/generalp.c?rev=33778&r1=33777&r2=33778&view=diff
==============================================================================
--- trunk/reactos/dll/cpl/intl/generalp.c [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/intl/generalp.c [iso-8859-1] Fri May 30 13:18:36 2008
@@ -422,6 +422,7 @@
 
                     /* Set new locale */
                     SetNewLocale(NewLcid);
+                    SetNonUnicodeLang(hwndDlg, NewLcid);
                 }
             }
             break;

Modified: trunk/reactos/dll/cpl/intl/intl.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/intl/intl.h?rev=33778&r1=33777&r2=33778&view=diff
==============================================================================
--- trunk/reactos/dll/cpl/intl/intl.h [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/intl/intl.h [iso-8859-1] Fri May 30 13:18:36 2008
@@ -32,6 +32,8 @@
 /* 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



More information about the Ros-diffs mailing list