[CONSOLE.CPL]: Rewrite the way we deal with console font samples in the console properties dialog:

- Remove the font helper functions that were already moved into concfg/font.c in r74462, and use the latter instead.
- Use a double list for listing the available font sizes for a given face:
  * a ListBox for raster fonts;
  * a ComboBox for TrueType fonts, allowing the user to specify a custom size.
  The raster ListBox is wrapped using the LIST_CTL structure so that we can use
  the bisection functions on it.
- Allow the user to specify TrueType font size either in pixels or in points. Raster font sizes however are always in pixels.
- Try to remember the nearest font size across different selected face changes.
- Try to support custom-sized TrueType fonts (using the ComboBox's edit field). May need more improvements!
- Retrieve the correct character cell height & width size in pixels when selecting a font (especially when it's a TrueType one).
- We now support bold console fonts too, see CORE-13122 (thanks Katayama!).
- Remove the commented-out "temporary code for future reference".
- Use a global cached font "hCurrentFont" that gets initialized when the console properties applet is created,
  so that we now can have a correct font in the screen samples when one directly views e.g. the "Color" tab,
  without going first in the "Font" tab. This current font is of course updated whenever one changes the font settings.

Tested with success on Windows 2003, Windows 7 and on ReactOS.

CORE-13122 CORE-13182 #resolve

svn path=/trunk/; revision=74469
This commit is contained in:
Hermès Bélusca-Maïto 2017-05-03 23:56:35 +00:00
parent 2dfccd0635
commit f13d997b76
4 changed files with 681 additions and 372 deletions

View file

@ -88,7 +88,7 @@ VOID
ApplyConsoleInfo(HWND hwndDlg)
{
static BOOL ConsoleInfoAlreadySaved = FALSE;
/*
* We already applied all the console properties (and saved if needed).
* Nothing more needs to be done.
@ -210,6 +210,11 @@ InitApplet(HANDLE hSectionOrWnd)
InitDefaultConsoleInfo(ConInfo);
}
/* Initialize the font support */
hCurrentFont = CreateConsoleFont(ConInfo);
if (hCurrentFont == NULL)
DPRINT1("InitApplet: CreateConsoleFont failed\n");
/* Initialize the property sheet structure */
ZeroMemory(&psh, sizeof(psh));
psh.dwSize = sizeof(psh);
@ -250,8 +255,14 @@ InitApplet(HANDLE hSectionOrWnd)
InitPropSheetPage(&psp[i++], IDD_PROPPAGELAYOUT , LayoutProc );
InitPropSheetPage(&psp[i++], IDD_PROPPAGECOLORS , ColorsProc );
/* Display the property sheet */
Result = PropertySheetW(&psh);
/* First cleanup */
if (hCurrentFont) DeleteObject(hCurrentFont);
hCurrentFont = NULL;
/* Save the console settings */
if (SetConsoleInfo)
{
HANDLE hSection;
@ -286,9 +297,7 @@ InitApplet(HANDLE hSectionOrWnd)
UnmapViewOfFile(pSharedInfo);
/* Signal to CONSRV that it can apply the new configuration */
SendMessage(ConInfo->hWnd,
WM_SETCONSOLEINFO,
(WPARAM)hSection, 0);
SendMessageW(ConInfo->hWnd, WM_SETCONSOLEINFO, (WPARAM)hSection, 0);
/* Close the section and return */
CloseHandle(hSection);
@ -299,7 +308,7 @@ InitApplet(HANDLE hSectionOrWnd)
/* Default settings saved when ConInfo->hWnd == NULL */
ConCfgWriteUserSettings(ConInfo, ConInfo->hWnd == NULL);
}
Quit:
/* Cleanup */
HeapFree(GetProcessHeap(), 0, ConInfo);

View file

@ -2,17 +2,20 @@
#define CONSOLE_H__
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#define WIN32_NO_STATUS
#include <windef.h>
#include <winbase.h>
#include <wincon.h>
#include <wingdi.h>
#include <winnls.h>
#include <winreg.h>
#include <winuser.h>
#include <wincon.h>
#include <commctrl.h>
#include <cpl.h>
@ -24,7 +27,7 @@
EnableWindow(GetDlgItem((hDlg), (nID)), (bEnable))
/* Shared header with the GUI Terminal Front-End from consrv.dll */
#include "settings.h" // in /winsrv/concfg/
#include "concfg.h" // in /winsrv/concfg/
typedef enum _TEXT_TYPE
{
@ -33,12 +36,22 @@ typedef enum _TEXT_TYPE
} TEXT_TYPE;
/* Globals */
extern HINSTANCE hApplet;
extern PCONSOLE_STATE_INFO ConInfo;
extern HFONT hCurrentFont;
VOID ApplyConsoleInfo(HWND hwndDlg);
BYTE CodePageToCharSet(UINT CodePage);
VOID PaintConsole(LPDRAWITEMSTRUCT drawItem, PCONSOLE_STATE_INFO pConInfo);
BOOL PaintText(LPDRAWITEMSTRUCT drawItem, PCONSOLE_STATE_INFO pConInfo, TEXT_TYPE TextMode);
VOID
PaintConsole(
IN LPDRAWITEMSTRUCT drawItem,
IN PCONSOLE_STATE_INFO pConInfo);
BOOL
PaintText(
IN LPDRAWITEMSTRUCT drawItem,
IN PCONSOLE_STATE_INFO pConInfo,
IN TEXT_TYPE TextMode);
struct _LIST_CTL;

File diff suppressed because it is too large Load diff

View file

@ -105,9 +105,7 @@ PaintText(
COLORREF pbkColor, ptColor;
COLORREF nbkColor, ntColor;
HBRUSH hBrush;
HFONT Font, OldFont;
COORD FontSize = pConInfo->FontSize;
HFONT hOldFont;
if (TextMode == Screen)
CurrentAttrib = pConInfo->ScreenAttributes;
@ -122,37 +120,12 @@ PaintText(
hBrush = CreateSolidBrush(nbkColor);
if (!hBrush) return FALSE;
FontSize.Y = FontSize.Y > 0 ? -MulDiv(FontSize.Y, GetDeviceCaps(drawItem->hDC, LOGPIXELSY), 72)
: FontSize.Y;
Font = CreateFontW(FontSize.Y,
FontSize.X,
0,
TA_BASELINE,
pConInfo->FontWeight,
FALSE,
FALSE,
FALSE,
CodePageToCharSet(pConInfo->CodePage),
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
FIXED_PITCH | pConInfo->FontFamily,
pConInfo->FaceName);
if (Font == NULL)
{
DPRINT1("PaintText: CreateFont failed\n");
DeleteObject(hBrush);
return FALSE;
}
OldFont = SelectObject(drawItem->hDC, Font);
if (OldFont == NULL)
{
DeleteObject(Font);
DeleteObject(hBrush);
return FALSE;
}
hOldFont = SelectObject(drawItem->hDC, hCurrentFont);
//if (hOldFont == NULL)
//{
// DeleteObject(hBrush);
// return FALSE;
//}
FillRect(drawItem->hDC, &drawItem->rcItem, hBrush);
@ -161,10 +134,10 @@ PaintText(
DrawTextW(drawItem->hDC, szPreviewText, wcslen(szPreviewText), &drawItem->rcItem, 0);
SetTextColor(drawItem->hDC, ptColor);
SetBkColor(drawItem->hDC, pbkColor);
DeleteObject(hBrush);
SelectObject(drawItem->hDC, OldFont);
DeleteObject(Font);
SelectObject(drawItem->hDC, hOldFont);
DeleteObject(hBrush);
return TRUE;
}