mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 09:25:10 +00:00
[CONSRV]: Improvements for console font support (part 2):
- Use the font functions from the concfg library (see r74462) to create a new console font & retrieve its metrics, inspired by the suggestions from Katayama Hirofumi MZ in CORE-12451 and CORE-13122; - Use string-safe functions to copy the font names into the fixed-size buffers; - Use explicit UNICODE calls to GetObject and CreateFontIndirect. Related to CORE-13182. svn path=/trunk/; revision=74464
This commit is contained in:
parent
c1934a3a17
commit
259a8515b0
1 changed files with 23 additions and 55 deletions
|
@ -18,6 +18,7 @@
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include "font.h"
|
||||||
#include "guiterm.h"
|
#include "guiterm.h"
|
||||||
#include "conwnd.h"
|
#include "conwnd.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
@ -503,13 +504,13 @@ CreateDerivedFont(HFONT OrgFont,
|
||||||
BOOLEAN bUnderline,
|
BOOLEAN bUnderline,
|
||||||
BOOLEAN bStrikeOut)
|
BOOLEAN bStrikeOut)
|
||||||
{
|
{
|
||||||
LOGFONT lf;
|
LOGFONTW lf;
|
||||||
|
|
||||||
/* Initialize the LOGFONT structure */
|
/* Initialize the LOGFONT structure */
|
||||||
RtlZeroMemory(&lf, sizeof(lf));
|
RtlZeroMemory(&lf, sizeof(lf));
|
||||||
|
|
||||||
/* Retrieve the details of the current font */
|
/* Retrieve the details of the current font */
|
||||||
if (GetObject(OrgFont, sizeof(lf), &lf) == 0)
|
if (GetObjectW(OrgFont, sizeof(lf), &lf) == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Change the font attributes */
|
/* Change the font attributes */
|
||||||
|
@ -521,7 +522,7 @@ CreateDerivedFont(HFONT OrgFont,
|
||||||
lf.lfStrikeOut = bStrikeOut;
|
lf.lfStrikeOut = bStrikeOut;
|
||||||
|
|
||||||
/* Build a new font */
|
/* Build a new font */
|
||||||
return CreateFontIndirect(&lf);
|
return CreateFontIndirectW(&lf);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL
|
BOOL
|
||||||
|
@ -532,65 +533,32 @@ InitFonts(PGUI_CONSOLE_DATA GuiData,
|
||||||
ULONG FontWeight)
|
ULONG FontWeight)
|
||||||
{
|
{
|
||||||
HDC hDC;
|
HDC hDC;
|
||||||
HFONT OldFont, NewFont;
|
HFONT hFont;
|
||||||
TEXTMETRICW Metrics;
|
|
||||||
SIZE CharSize;
|
|
||||||
|
|
||||||
hDC = GetDC(GuiData->hWindow);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize a new NORMAL font and get its metrics.
|
* Initialize a new NORMAL font and get its character cell size.
|
||||||
*/
|
*/
|
||||||
|
/* NOTE: FontSize is always in cell height/width units (pixels) */
|
||||||
FontSize.Y = FontSize.Y > 0 ? -MulDiv(FontSize.Y, GetDeviceCaps(hDC, LOGPIXELSY), 72)
|
hFont = CreateConsoleFontEx((LONG)(ULONG)FontSize.Y,
|
||||||
: FontSize.Y;
|
(LONG)(ULONG)FontSize.X,
|
||||||
|
FaceName,
|
||||||
NewFont = CreateFontW(FontSize.Y,
|
FontFamily,
|
||||||
FontSize.X,
|
FontWeight,
|
||||||
0,
|
GuiData->Console->OutputCodePage);
|
||||||
TA_BASELINE,
|
if (hFont == NULL)
|
||||||
FontWeight,
|
|
||||||
FALSE,
|
|
||||||
FALSE,
|
|
||||||
FALSE,
|
|
||||||
OEM_CHARSET,
|
|
||||||
OUT_DEFAULT_PRECIS,
|
|
||||||
CLIP_DEFAULT_PRECIS,
|
|
||||||
DEFAULT_QUALITY,
|
|
||||||
FIXED_PITCH | FontFamily,
|
|
||||||
FaceName);
|
|
||||||
if (NewFont == NULL)
|
|
||||||
{
|
{
|
||||||
DPRINT1("InitFonts: CreateFontW failed\n");
|
DPRINT1("InitFonts: CreateConsoleFontEx failed\n");
|
||||||
ReleaseDC(GuiData->hWindow, hDC);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
OldFont = SelectObject(hDC, NewFont);
|
hDC = GetDC(GuiData->hWindow);
|
||||||
if (OldFont == NULL)
|
if (!GetFontCellSize(hDC, hFont, &GuiData->CharHeight, &GuiData->CharWidth))
|
||||||
{
|
{
|
||||||
DPRINT1("InitFonts: SelectObject failed\n");
|
DPRINT1("InitFonts: GetFontCellSize failed\n");
|
||||||
ReleaseDC(GuiData->hWindow, hDC);
|
ReleaseDC(GuiData->hWindow, hDC);
|
||||||
DeleteObject(NewFont);
|
DeleteObject(hFont);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GetTextMetricsW(hDC, &Metrics))
|
|
||||||
{
|
|
||||||
DPRINT1("InitFonts: GetTextMetrics failed\n");
|
|
||||||
SelectObject(hDC, OldFont);
|
|
||||||
ReleaseDC(GuiData->hWindow, hDC);
|
|
||||||
DeleteObject(NewFont);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
GuiData->CharWidth = Metrics.tmMaxCharWidth;
|
|
||||||
GuiData->CharHeight = Metrics.tmHeight + Metrics.tmExternalLeading;
|
|
||||||
|
|
||||||
/* Measure real char width more precisely if possible */
|
|
||||||
if (GetTextExtentPoint32W(hDC, L"R", 1, &CharSize))
|
|
||||||
GuiData->CharWidth = CharSize.cx;
|
|
||||||
|
|
||||||
SelectObject(hDC, OldFont);
|
|
||||||
ReleaseDC(GuiData->hWindow, hDC);
|
ReleaseDC(GuiData->hWindow, hDC);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -598,7 +566,7 @@ InitFonts(PGUI_CONSOLE_DATA GuiData,
|
||||||
*/
|
*/
|
||||||
// Delete all the old fonts first.
|
// Delete all the old fonts first.
|
||||||
DeleteFonts(GuiData);
|
DeleteFonts(GuiData);
|
||||||
GuiData->Font[FONT_NORMAL] = NewFont;
|
GuiData->Font[FONT_NORMAL] = hFont;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now build the other fonts (bold, underlined, mixed).
|
* Now build the other fonts (bold, underlined, mixed).
|
||||||
|
@ -624,8 +592,8 @@ InitFonts(PGUI_CONSOLE_DATA GuiData,
|
||||||
*/
|
*/
|
||||||
if (FaceName != GuiData->GuiInfo.FaceName)
|
if (FaceName != GuiData->GuiInfo.FaceName)
|
||||||
{
|
{
|
||||||
wcsncpy(GuiData->GuiInfo.FaceName, FaceName, LF_FACESIZE);
|
StringCchCopyNW(GuiData->GuiInfo.FaceName, ARRAYSIZE(GuiData->GuiInfo.FaceName),
|
||||||
GuiData->GuiInfo.FaceName[LF_FACESIZE - 1] = UNICODE_NULL;
|
FaceName, LF_FACESIZE);
|
||||||
}
|
}
|
||||||
GuiData->GuiInfo.FontFamily = FontFamily;
|
GuiData->GuiInfo.FontFamily = FontFamily;
|
||||||
GuiData->GuiInfo.FontSize = FontSize;
|
GuiData->GuiInfo.FontSize = FontSize;
|
||||||
|
@ -1012,7 +980,7 @@ UpdateSelection(PGUI_CONSOLE_DATA GuiData,
|
||||||
WindowTitle = ConsoleAllocHeap(0, Length);
|
WindowTitle = ConsoleAllocHeap(0, Length);
|
||||||
|
|
||||||
wcsncpy(WindowTitle, SelTypeStr, SelTypeStrLength);
|
wcsncpy(WindowTitle, SelTypeStr, SelTypeStrLength);
|
||||||
WindowTitle[SelTypeStrLength] = L'\0';
|
WindowTitle[SelTypeStrLength] = UNICODE_NULL;
|
||||||
wcscat(WindowTitle, L" - ");
|
wcscat(WindowTitle, L" - ");
|
||||||
wcscat(WindowTitle, Console->Title.Buffer);
|
wcscat(WindowTitle, Console->Title.Buffer);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue