[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'.
This commit is contained in:
Hermès Bélusca-Maïto 2019-05-05 01:10:39 +02:00
parent fa63416d87
commit 2ebda0e3d0
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
5 changed files with 59 additions and 47 deletions

View file

@ -228,25 +228,20 @@ InitApplet(HANDLE hSectionOrWnd)
} }
/* Initialize the font support */ /* Initialize the font support */
hCurrentFont = CreateConsoleFont(ConInfo); FontPreview.hFont = CreateConsoleFont(ConInfo);
if (hCurrentFont == NULL) if (FontPreview.hFont == NULL)
DPRINT1("InitApplet: CreateConsoleFont failed\n"); DPRINT1("InitApplet: CreateConsoleFont() failed\n");
GetFontCellSize(NULL, FontPreview.hFont, &FontPreview.CharHeight, &FontPreview.CharWidth);
/* Initialize the property sheet structure */ /* Initialize the property sheet structure */
ZeroMemory(&psh, sizeof(psh)); ZeroMemory(&psh, sizeof(psh));
psh.dwSize = 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) if (ConInfo->ConsoleTitle[0] != UNICODE_NULL)
{ StringCchPrintfW(szTitle, ARRAYSIZE(szTitle), L"\"%s\"", ConInfo->ConsoleTitle);
wcsncpy(szTitle, L"\"", MAX_PATH);
wcsncat(szTitle, ConInfo->ConsoleTitle, MAX_PATH - wcslen(szTitle));
wcsncat(szTitle, L"\"", MAX_PATH - wcslen(szTitle));
}
else else
{ StringCchCopyW(szTitle, ARRAYSIZE(szTitle), L"ReactOS Console");
wcscpy(szTitle, L"ReactOS Console");
}
psh.pszCaption = szTitle; psh.pszCaption = szTitle;
if (pSharedInfo != NULL) if (pSharedInfo != NULL)
@ -278,9 +273,9 @@ InitApplet(HANDLE hSectionOrWnd)
Result = PropertySheetW(&psh); Result = PropertySheetW(&psh);
UnRegisterWinPrevClass(hApplet); UnRegisterWinPrevClass(hApplet);
/* First cleanup */ /* Clear the font support */
if (hCurrentFont) DeleteObject(hCurrentFont); if (FontPreview.hFont) DeleteObject(FontPreview.hFont);
hCurrentFont = NULL; FontPreview.hFont = NULL;
/* Save the console settings */ /* Save the console settings */
if (SetConsoleInfo) if (SetConsoleInfo)

View file

@ -35,10 +35,17 @@ typedef enum _TEXT_TYPE
Popup Popup
} TEXT_TYPE; } TEXT_TYPE;
typedef struct _FONT_PREVIEW
{
HFONT hFont;
UINT CharWidth;
UINT CharHeight;
} FONT_PREVIEW;
/* Globals */ /* Globals */
extern HINSTANCE hApplet; extern HINSTANCE hApplet;
extern PCONSOLE_STATE_INFO ConInfo; extern PCONSOLE_STATE_INFO ConInfo;
extern HFONT hCurrentFont; extern FONT_PREVIEW FontPreview;
VOID ApplyConsoleInfo(HWND hwndDlg); VOID ApplyConsoleInfo(HWND hwndDlg);

View file

@ -18,7 +18,7 @@
* Current active font, corresponding to the active console font, * Current active font, corresponding to the active console font,
* and used for painting the text samples. * 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 PFONTSIZE_LIST_CTL SizeList,
IN OUT PCONSOLE_STATE_INFO pConInfo) IN OUT PCONSOLE_STATE_INFO pConInfo)
{ {
HDC hDC; LONG FontSize, CharWidth, CharHeight;
LONG CharWidth, CharHeight, FontSize;
WCHAR szFontSize[100]; WCHAR szFontSize[100];
/* /*
@ -614,33 +613,32 @@ FontSizeChange(
CharHeight = (SizeList->UseRasterOrTTList ? (LONG)HIWORD(FontSize) : FontSize); CharHeight = (SizeList->UseRasterOrTTList ? (LONG)HIWORD(FontSize) : FontSize);
CharWidth = (SizeList->UseRasterOrTTList ? (LONG)LOWORD(FontSize) : 0); CharWidth = (SizeList->UseRasterOrTTList ? (LONG)LOWORD(FontSize) : 0);
if (hCurrentFont) DeleteObject(hCurrentFont); if (FontPreview.hFont) DeleteObject(FontPreview.hFont);
hCurrentFont = CreateConsoleFont2(CharHeight, CharWidth, pConInfo); FontPreview.hFont = CreateConsoleFont2(CharHeight, CharWidth, pConInfo);
if (hCurrentFont == NULL) if (FontPreview.hFont == NULL)
DPRINT1("FontSizeChange: CreateConsoleFont2 failed\n"); DPRINT1("FontSizeChange: CreateConsoleFont2() failed\n");
/* Retrieve the real character size in pixels */ /* Retrieve the real character size in pixels */
hDC = GetDC(NULL); GetFontCellSize(NULL, FontPreview.hFont, &FontPreview.CharHeight, &FontPreview.CharWidth);
GetFontCellSize(hDC, hCurrentFont, (PUINT)&CharHeight, (PUINT)&CharWidth);
ReleaseDC(NULL, hDC);
/* /*
* Format: * Format:
* Width = FontSize.X = LOWORD(FontSize); * Width = FontSize.X = LOWORD(FontSize);
* Height = FontSize.Y = HIWORD(FontSize); * Height = FontSize.Y = HIWORD(FontSize);
*/ */
pConInfo->FontSize.X = (SHORT)(SizeList->UseRasterOrTTList ? CharWidth : 0); pConInfo->FontSize.X = (SHORT)(SizeList->UseRasterOrTTList ? FontPreview.CharWidth : 0);
pConInfo->FontSize.Y = (SHORT)CharHeight; pConInfo->FontSize.Y = (SHORT)FontPreview.CharHeight;
DPRINT1("pConInfo->FontSize = (%d x %d) ; (CharWidth x CharHeight) = (%d x %d)\n", 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_FONT_WINDOW_PREVIEW), NULL, TRUE);
InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_SELECT_FONT_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); 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); SetDlgItemText(hDlg, IDC_FONT_SIZE_Y, szFontSize);
return TRUE; return TRUE;

View file

@ -205,8 +205,8 @@ WinPrev_OnDraw(
/* We start with the console client area, rescaled for the preview */ /* We start with the console client area, rescaled for the preview */
SetRect(&rcWin, 0, 0, SetRect(&rcWin, 0, 0,
pConInfo->WindowSize.X * pConInfo->FontSize.X, pConInfo->WindowSize.X * FontPreview.CharWidth,
pConInfo->WindowSize.Y * pConInfo->FontSize.Y); pConInfo->WindowSize.Y * FontPreview.CharHeight);
RescaleRect(pData, rcWin); RescaleRect(pData, rcWin);
/* Add the scrollbars if needed (does not account for any frame) */ /* Add the scrollbars if needed (does not account for any frame) */
@ -489,7 +489,7 @@ PaintText(
hBrush = CreateSolidBrush(nbkColor); hBrush = CreateSolidBrush(nbkColor);
if (!hBrush) return; if (!hBrush) return;
hOldFont = SelectObject(drawItem->hDC, hCurrentFont); hOldFont = SelectObject(drawItem->hDC, FontPreview.hFont);
//if (hOldFont == NULL) //if (hOldFont == NULL)
//{ //{
// DeleteObject(hBrush); // DeleteObject(hBrush);

View file

@ -120,7 +120,7 @@ ConCfgOpenUserSettings(
Status = RtlOpenCurrentUser(/*samDesired*/MAXIMUM_ALLOWED, (PHANDLE)&/*CurrentUserKeyHandle*/hKey); Status = RtlOpenCurrentUser(/*samDesired*/MAXIMUM_ALLOWED, (PHANDLE)&/*CurrentUserKeyHandle*/hKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("RtlOpenCurrentUser failed, Status = 0x%08lx\n", Status); DPRINT1("RtlOpenCurrentUser() failed, Status = 0x%08lx\n", Status);
SetLastError(RtlNtStatusToDosError(Status)); SetLastError(RtlNtStatusToDosError(Status));
return FALSE; return FALSE;
} }
@ -170,7 +170,7 @@ ConCfgReadUserSettings(
{ {
BOOLEAN Success = FALSE; BOOLEAN Success = FALSE;
HKEY hKey; HKEY hKey;
DWORD dwNumSubKeys = 0; DWORD dwNumValues = 0;
DWORD dwIndex; DWORD dwIndex;
DWORD dwColorIndex = 0; DWORD dwColorIndex = 0;
DWORD dwType; DWORD dwType;
@ -183,21 +183,21 @@ ConCfgReadUserSettings(
if (!ConCfgOpenUserSettings(DefaultSettings ? L"" : ConsoleInfo->ConsoleTitle, if (!ConCfgOpenUserSettings(DefaultSettings ? L"" : ConsoleInfo->ConsoleTitle,
&hKey, KEY_READ, FALSE)) &hKey, KEY_READ, FALSE))
{ {
DPRINT("ConCfgOpenUserSettings failed\n"); DPRINT("ConCfgOpenUserSettings() failed\n");
return FALSE; return FALSE;
} }
if (RegQueryInfoKeyW(hKey, NULL, NULL, NULL, NULL, NULL, NULL, 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); RegCloseKey(hKey);
return FALSE; 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); dwValue = sizeof(Value);
dwValueName = ARRAYSIZE(szValueName); dwValueName = ARRAYSIZE(szValueName);
@ -238,24 +238,36 @@ ConCfgReadUserSettings(
} }
else if (!wcscmp(szValueName, L"FaceName")) else if (!wcscmp(szValueName, L"FaceName"))
{ {
StringCchCopyNW(ConsoleInfo->FaceName, ARRAYSIZE(ConsoleInfo->FaceName), /* A NULL value means that the defaults should be used instead */
szValue, ARRAYSIZE(szValue)); if (*szValue)
{
StringCchCopyNW(ConsoleInfo->FaceName, ARRAYSIZE(ConsoleInfo->FaceName),
szValue, ARRAYSIZE(szValue));
}
Success = TRUE; Success = TRUE;
} }
else if (!wcscmp(szValueName, L"FontFamily")) 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; Success = TRUE;
} }
else if (!wcscmp(szValueName, L"FontSize")) else if (!wcscmp(szValueName, L"FontSize"))
{ {
ConsoleInfo->FontSize.X = LOWORD(Value); // Width /* A zero value means that the defaults should be used instead */
ConsoleInfo->FontSize.Y = HIWORD(Value); // Height if (Value)
{
ConsoleInfo->FontSize.X = LOWORD(Value); // Width
ConsoleInfo->FontSize.Y = HIWORD(Value); // Height
}
Success = TRUE; Success = TRUE;
} }
else if (!wcscmp(szValueName, L"FontWeight")) 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; Success = TRUE;
} }
else if (!wcscmp(szValueName, L"HistoryBufferSize")) else if (!wcscmp(szValueName, L"HistoryBufferSize"))