https://git.reactos.org/?p=reactos.git;a=commitdiff;h=2ebda0e3d0e583ee6d24b04132923aaa6a1c0e1a

commit 2ebda0e3d0e583ee6d24b04132923aaa6a1c0e1a
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Sun May 5 01:10:39 2019 +0200
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Sun May 5 01:20:19 2019 +0200

    [CONSOLE.CPL] Fix the console screen preview when selecting TrueType fonts.
    CORE-13182 CORE-13196
    
    - Use the correct character height & width.
    - Additions: use StringCch*() when initializing the dialog title.
    
    [CONSRV:CONCFG] Minor fixes.
    
    - When retrieving font characteristics in ConCfgReadUserSettings(),
      check for NULL/zero values that indicate that we should use default
      ones instead.
    - Rename 'dwNumSubKeys' into 'dwNumValues'.
---
 dll/cpl/console/console.c             | 25 +++++++++--------------
 dll/cpl/console/console.h             |  9 ++++++++-
 dll/cpl/console/font.c                | 28 ++++++++++++--------------
 dll/cpl/console/layout.c              |  6 +++---
 win32ss/user/winsrv/concfg/settings.c | 38 +++++++++++++++++++++++------------
 5 files changed, 59 insertions(+), 47 deletions(-)

diff --git a/dll/cpl/console/console.c b/dll/cpl/console/console.c
index d39253a0c6..89e9ac57fb 100644
--- a/dll/cpl/console/console.c
+++ b/dll/cpl/console/console.c
@@ -228,25 +228,20 @@ InitApplet(HANDLE hSectionOrWnd)
     }
 
     /* Initialize the font support */
-    hCurrentFont = CreateConsoleFont(ConInfo);
-    if (hCurrentFont == NULL)
-        DPRINT1("InitApplet: CreateConsoleFont failed\n");
+    FontPreview.hFont = CreateConsoleFont(ConInfo);
+    if (FontPreview.hFont == NULL)
+        DPRINT1("InitApplet: CreateConsoleFont() failed\n");
+    GetFontCellSize(NULL, FontPreview.hFont, &FontPreview.CharHeight, 
&FontPreview.CharWidth);
 
     /* Initialize the property sheet structure */
     ZeroMemory(&psh, sizeof(psh));
     psh.dwSize = sizeof(psh);
-    psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE | /* PSH_USEHICON */ 
PSH_USEICONID | PSH_NOAPPLYNOW | PSH_USECALLBACK;
+    psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE | /* PSH_USEHICON | */ 
PSH_USEICONID | PSH_NOAPPLYNOW | PSH_USECALLBACK;
 
     if (ConInfo->ConsoleTitle[0] != UNICODE_NULL)
-    {
-        wcsncpy(szTitle, L"\"", MAX_PATH);
-        wcsncat(szTitle, ConInfo->ConsoleTitle, MAX_PATH - wcslen(szTitle));
-        wcsncat(szTitle, L"\"", MAX_PATH - wcslen(szTitle));
-    }
+        StringCchPrintfW(szTitle, ARRAYSIZE(szTitle), L"\"%s\"", 
ConInfo->ConsoleTitle);
     else
-    {
-        wcscpy(szTitle, L"ReactOS Console");
-    }
+        StringCchCopyW(szTitle, ARRAYSIZE(szTitle), L"ReactOS Console");
     psh.pszCaption = szTitle;
 
     if (pSharedInfo != NULL)
@@ -278,9 +273,9 @@ InitApplet(HANDLE hSectionOrWnd)
     Result = PropertySheetW(&psh);
     UnRegisterWinPrevClass(hApplet);
 
-    /* First cleanup */
-    if (hCurrentFont) DeleteObject(hCurrentFont);
-    hCurrentFont = NULL;
+    /* Clear the font support */
+    if (FontPreview.hFont) DeleteObject(FontPreview.hFont);
+    FontPreview.hFont = NULL;
 
     /* Save the console settings */
     if (SetConsoleInfo)
diff --git a/dll/cpl/console/console.h b/dll/cpl/console/console.h
index 04508bf063..0f7b592494 100644
--- a/dll/cpl/console/console.h
+++ b/dll/cpl/console/console.h
@@ -35,10 +35,17 @@ typedef enum _TEXT_TYPE
     Popup
 } TEXT_TYPE;
 
+typedef struct _FONT_PREVIEW
+{
+    HFONT hFont;
+    UINT  CharWidth;
+    UINT  CharHeight;
+} FONT_PREVIEW;
+
 /* Globals */
 extern HINSTANCE hApplet;
 extern PCONSOLE_STATE_INFO ConInfo;
-extern HFONT hCurrentFont;
+extern FONT_PREVIEW FontPreview;
 
 VOID ApplyConsoleInfo(HWND hwndDlg);
 
diff --git a/dll/cpl/console/font.c b/dll/cpl/console/font.c
index 45a2612b39..66c9cc6a41 100644
--- a/dll/cpl/console/font.c
+++ b/dll/cpl/console/font.c
@@ -18,7 +18,7 @@
  * Current active font, corresponding to the active console font,
  * and used for painting the text samples.
  */
-HFONT hCurrentFont = NULL;
+FONT_PREVIEW FontPreview = {NULL, 0, 0};
 
 
 /*
@@ -597,8 +597,7 @@ FontSizeChange(
     IN PFONTSIZE_LIST_CTL SizeList,
     IN OUT PCONSOLE_STATE_INFO pConInfo)
 {
-    HDC hDC;
-    LONG CharWidth, CharHeight, FontSize;
+    LONG FontSize, CharWidth, CharHeight;
     WCHAR szFontSize[100];
 
     /*
@@ -614,33 +613,32 @@ FontSizeChange(
     CharHeight = (SizeList->UseRasterOrTTList ? (LONG)HIWORD(FontSize) : 
FontSize);
     CharWidth  = (SizeList->UseRasterOrTTList ? (LONG)LOWORD(FontSize) : 0);
 
-    if (hCurrentFont) DeleteObject(hCurrentFont);
-    hCurrentFont = CreateConsoleFont2(CharHeight, CharWidth, pConInfo);
-    if (hCurrentFont == NULL)
-        DPRINT1("FontSizeChange: CreateConsoleFont2 failed\n");
+    if (FontPreview.hFont) DeleteObject(FontPreview.hFont);
+    FontPreview.hFont = CreateConsoleFont2(CharHeight, CharWidth, pConInfo);
+    if (FontPreview.hFont == NULL)
+        DPRINT1("FontSizeChange: CreateConsoleFont2() failed\n");
 
     /* Retrieve the real character size in pixels */
-    hDC = GetDC(NULL);
-    GetFontCellSize(hDC, hCurrentFont, (PUINT)&CharHeight, (PUINT)&CharWidth);
-    ReleaseDC(NULL, hDC);
+    GetFontCellSize(NULL, FontPreview.hFont, &FontPreview.CharHeight, 
&FontPreview.CharWidth);
 
     /*
      * Format:
      * Width  = FontSize.X = LOWORD(FontSize);
      * Height = FontSize.Y = HIWORD(FontSize);
      */
-    pConInfo->FontSize.X = (SHORT)(SizeList->UseRasterOrTTList ? CharWidth : 
0);
-    pConInfo->FontSize.Y = (SHORT)CharHeight;
+    pConInfo->FontSize.X = (SHORT)(SizeList->UseRasterOrTTList ? 
FontPreview.CharWidth : 0);
+    pConInfo->FontSize.Y = (SHORT)FontPreview.CharHeight;
 
     DPRINT1("pConInfo->FontSize = (%d x %d) ; (CharWidth x CharHeight) = (%d x 
%d)\n",
-            pConInfo->FontSize.X, pConInfo->FontSize.Y, CharWidth, CharHeight);
+            pConInfo->FontSize.X, pConInfo->FontSize.Y,
+            FontPreview.CharWidth, FontPreview.CharHeight);
 
     InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_FONT_WINDOW_PREVIEW), NULL, 
TRUE);
     InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_SELECT_FONT_PREVIEW), NULL, 
TRUE);
 
-    StringCchPrintfW(szFontSize, ARRAYSIZE(szFontSize), L"%d", CharWidth);
+    StringCchPrintfW(szFontSize, ARRAYSIZE(szFontSize), L"%d", 
FontPreview.CharWidth);
     SetDlgItemText(hDlg, IDC_FONT_SIZE_X, szFontSize);
-    StringCchPrintfW(szFontSize, ARRAYSIZE(szFontSize), L"%d", CharHeight);
+    StringCchPrintfW(szFontSize, ARRAYSIZE(szFontSize), L"%d", 
FontPreview.CharHeight);
     SetDlgItemText(hDlg, IDC_FONT_SIZE_Y, szFontSize);
 
     return TRUE;
diff --git a/dll/cpl/console/layout.c b/dll/cpl/console/layout.c
index 9123a1fca7..f8d998625c 100644
--- a/dll/cpl/console/layout.c
+++ b/dll/cpl/console/layout.c
@@ -205,8 +205,8 @@ WinPrev_OnDraw(
 
     /* We start with the console client area, rescaled for the preview */
     SetRect(&rcWin, 0, 0,
-            pConInfo->WindowSize.X * pConInfo->FontSize.X,
-            pConInfo->WindowSize.Y * pConInfo->FontSize.Y);
+            pConInfo->WindowSize.X * FontPreview.CharWidth,
+            pConInfo->WindowSize.Y * FontPreview.CharHeight);
     RescaleRect(pData, rcWin);
 
     /* Add the scrollbars if needed (does not account for any frame) */
@@ -489,7 +489,7 @@ PaintText(
     hBrush = CreateSolidBrush(nbkColor);
     if (!hBrush) return;
 
-    hOldFont = SelectObject(drawItem->hDC, hCurrentFont);
+    hOldFont = SelectObject(drawItem->hDC, FontPreview.hFont);
     //if (hOldFont == NULL)
     //{
     //    DeleteObject(hBrush);
diff --git a/win32ss/user/winsrv/concfg/settings.c 
b/win32ss/user/winsrv/concfg/settings.c
index fcc66d82af..2c7624f74a 100644
--- a/win32ss/user/winsrv/concfg/settings.c
+++ b/win32ss/user/winsrv/concfg/settings.c
@@ -120,7 +120,7 @@ ConCfgOpenUserSettings(
     Status = RtlOpenCurrentUser(/*samDesired*/MAXIMUM_ALLOWED, 
(PHANDLE)&/*CurrentUserKeyHandle*/hKey);
     if (!NT_SUCCESS(Status))
     {
-        DPRINT1("RtlOpenCurrentUser failed, Status = 0x%08lx\n", Status);
+        DPRINT1("RtlOpenCurrentUser() failed, Status = 0x%08lx\n", Status);
         SetLastError(RtlNtStatusToDosError(Status));
         return FALSE;
     }
@@ -170,7 +170,7 @@ ConCfgReadUserSettings(
 {
     BOOLEAN Success = FALSE;
     HKEY  hKey;
-    DWORD dwNumSubKeys = 0;
+    DWORD dwNumValues = 0;
     DWORD dwIndex;
     DWORD dwColorIndex = 0;
     DWORD dwType;
@@ -183,21 +183,21 @@ ConCfgReadUserSettings(
     if (!ConCfgOpenUserSettings(DefaultSettings ? L"" : 
ConsoleInfo->ConsoleTitle,
                                 &hKey, KEY_READ, FALSE))
     {
-        DPRINT("ConCfgOpenUserSettings failed\n");
+        DPRINT("ConCfgOpenUserSettings() failed\n");
         return FALSE;
     }
 
     if (RegQueryInfoKeyW(hKey, NULL, NULL, NULL, NULL, NULL, NULL,
-                         &dwNumSubKeys, NULL, NULL, NULL, NULL) != 
ERROR_SUCCESS)
+                         &dwNumValues, NULL, NULL, NULL, NULL) != 
ERROR_SUCCESS)
     {
-        DPRINT("ConCfgReadUserSettings: RegQueryInfoKeyW failed\n");
+        DPRINT("ConCfgReadUserSettings: RegQueryInfoKeyW() failed\n");
         RegCloseKey(hKey);
         return FALSE;
     }
 
-    DPRINT("ConCfgReadUserSettings entered dwNumSubKeys %d\n", dwNumSubKeys);
+    DPRINT("ConCfgReadUserSettings() entered, dwNumValues %d\n", dwNumValues);
 
-    for (dwIndex = 0; dwIndex < dwNumSubKeys; dwIndex++)
+    for (dwIndex = 0; dwIndex < dwNumValues; dwIndex++)
     {
         dwValue = sizeof(Value);
         dwValueName = ARRAYSIZE(szValueName);
@@ -238,24 +238,36 @@ ConCfgReadUserSettings(
         }
         else if (!wcscmp(szValueName, L"FaceName"))
         {
-            StringCchCopyNW(ConsoleInfo->FaceName, 
ARRAYSIZE(ConsoleInfo->FaceName),
-                            szValue, ARRAYSIZE(szValue));
+            /* A NULL value means that the defaults should be used instead */
+            if (*szValue)
+            {
+                StringCchCopyNW(ConsoleInfo->FaceName, 
ARRAYSIZE(ConsoleInfo->FaceName),
+                                szValue, ARRAYSIZE(szValue));
+            }
             Success = TRUE;
         }
         else if (!wcscmp(szValueName, L"FontFamily"))
         {
-            ConsoleInfo->FontFamily = Value;
+            /* A zero value means that the defaults should be used instead */
+            if (Value)
+                ConsoleInfo->FontFamily = Value;
             Success = TRUE;
         }
         else if (!wcscmp(szValueName, L"FontSize"))
         {
-            ConsoleInfo->FontSize.X = LOWORD(Value); // Width
-            ConsoleInfo->FontSize.Y = HIWORD(Value); // Height
+            /* A zero value means that the defaults should be used instead */
+            if (Value)
+            {
+                ConsoleInfo->FontSize.X = LOWORD(Value); // Width
+                ConsoleInfo->FontSize.Y = HIWORD(Value); // Height
+            }
             Success = TRUE;
         }
         else if (!wcscmp(szValueName, L"FontWeight"))
         {
-            ConsoleInfo->FontWeight = Value;
+            /* A zero value means that the defaults should be used instead */
+            if (Value)
+                ConsoleInfo->FontWeight = Value;
             Success = TRUE;
         }
         else if (!wcscmp(szValueName, L"HistoryBufferSize"))

Reply via email to