[KERNEL32]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Thu, 14 Aug 2014 20:10:00 +0000 (20:10 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Thu, 14 Aug 2014 20:10:00 +0000 (20:10 +0000)
OpenConsoleW was implemented :P

[CONSOLE.CPL][CONSRV]
Create all the fonts needed at console startup, and then just select what's needed when fonts attributes need to be changed at run-time.

[CONSOLE.CPL][CONSRV]
- HACKFIX: Temporary use FW_NORMAL instead of FW_DONTCARE as default font weight (in ReactOS, FW_DONTCARE makes fonts bold by default, instead of normal)
- Use bold fonts instead of the underlined ones for underlined fonts in the terminal.

Timo, FIX THE FONTS !!!!!!!!!! :P

CORE-8439 #comment Should be fixed in revision 63885.

svn path=/branches/condrv_restructure/; revision=63885

dll/cpl/console/console.c
dll/cpl/console/layout.c
dll/win32/kernel32/client/console/console.c
win32ss/user/winsrv/consrv/frontends/gui/conwnd.c
win32ss/user/winsrv/consrv/frontends/gui/conwnd.h
win32ss/user/winsrv/consrv/frontends/gui/guisettings.c
win32ss/user/winsrv/consrv/frontends/gui/guisettings.h
win32ss/user/winsrv/consrv/frontends/gui/guiterm.h
win32ss/user/winsrv/consrv/frontends/gui/text.c

index 436626b..8fdda90 100644 (file)
@@ -117,7 +117,8 @@ InitConsoleDefaults(PCONSOLE_PROPS pConInfo)
     GuiInfo->FontFamily = FF_DONTCARE;
     GuiInfo->FontSize.X = 0;
     GuiInfo->FontSize.Y = 0;
-    GuiInfo->FontWeight = FW_DONTCARE;
+    GuiInfo->FontWeight = FW_NORMAL; // HACK: !!
+    // GuiInfo->FontWeight = FW_DONTCARE;
 
     GuiInfo->FullScreen   = FALSE;
     GuiInfo->ShowWindow   = SW_SHOWNORMAL;
index fac40bb..90926c8 100644 (file)
@@ -121,7 +121,7 @@ PaintText(LPDRAWITEMSTRUCT drawItem,
     if (!hBrush) return FALSE;
 
     Font = CreateFontW(GuiInfo->FontSize.Y,
-                       0, // GuiInfo->FontSize.X,
+                       GuiInfo->FontSize.X,
                        0,
                        TA_BASELINE,
                        GuiInfo->FontWeight,
@@ -131,8 +131,8 @@ PaintText(LPDRAWITEMSTRUCT drawItem,
                        OEM_CHARSET,
                        OUT_DEFAULT_PRECIS,
                        CLIP_DEFAULT_PRECIS,
-                       NONANTIALIASED_QUALITY,
-                       FIXED_PITCH | GuiInfo->FontFamily /* FF_DONTCARE */,
+                       DEFAULT_QUALITY, // NONANTIALIASED_QUALITY ; ANTIALIASED_QUALITY
+                       FIXED_PITCH | GuiInfo->FontFamily,
                        GuiInfo->FaceName);
     if (Font == NULL)
     {
index fe4a084..0a4059a 100644 (file)
@@ -561,7 +561,7 @@ InvalidateConsoleDIBits(IN HANDLE hConsoleOutput,
 
 
 /*
- * @unimplemented (Undocumented)
+ * @implemented (Undocumented)
  */
 HANDLE
 WINAPI
index c0373a6..84de187 100644 (file)
@@ -486,75 +486,106 @@ ResizeConWnd(PGUI_CONSOLE_DATA GuiData, DWORD WidthUnit, DWORD HeightUnit)
     // to: InvalidateRect(GuiData->hWindow, NULL, TRUE);
 }
 
-static BOOL
-OnNcCreate(HWND hWnd, LPCREATESTRUCTW Create)
-{
-    PGUI_CONSOLE_DATA GuiData = (PGUI_CONSOLE_DATA)Create->lpCreateParams;
-    PCONSRV_CONSOLE Console;
-    HDC hDC;
-    HFONT OldFont;
-    TEXTMETRICW Metrics;
-    SIZE CharSize;
 
-    if (NULL == GuiData)
+VOID
+DeleteFonts(PGUI_CONSOLE_DATA GuiData)
+{
+    ULONG i;
+    for (i = 0; i < sizeof(GuiData->Font) / sizeof(GuiData->Font[0]); ++i)
     {
-        DPRINT1("GuiConsoleNcCreate: No GUI data\n");
-        return FALSE;
+        if (GuiData->Font[i] != NULL) DeleteObject(GuiData->Font[i]);
+        GuiData->Font[i] = NULL;
     }
+}
 
-    Console = GuiData->Console;
+static HFONT
+CreateDerivedFont(HFONT OrgFont,
+                  // COORD   FontSize,
+                  ULONG   FontWeight,
+                  // BOOLEAN bItalic,
+                  BOOLEAN bUnderline,
+                  BOOLEAN bStrikeOut)
+{
+    LOGFONT lf;
 
-    GuiData->hWindow = hWnd;
+    /* Initialize the LOGFONT structure */
+    RtlZeroMemory(&lf, sizeof(lf));
+
+    /* Retrieve the details of the current font */
+    if (GetObject(OrgFont, sizeof(lf), &lf) == 0)
+        return NULL;
 
-    GuiData->Font = CreateFontW(GuiData->GuiInfo.FontSize.Y,
-                                0, // GuiData->GuiInfo.FontSize.X,
-                                0,
-                                TA_BASELINE,
-                                GuiData->GuiInfo.FontWeight,
-                                FALSE,
-                                FALSE,
-                                FALSE,
-                                OEM_CHARSET,
-                                OUT_DEFAULT_PRECIS,
-                                CLIP_DEFAULT_PRECIS,
-                                NONANTIALIASED_QUALITY,
-                                FIXED_PITCH | GuiData->GuiInfo.FontFamily /* FF_DONTCARE */,
-                                GuiData->GuiInfo.FaceName);
-
-    if (NULL == GuiData->Font)
+    /* Change the font attributes */
+    // lf.lfHeight = FontSize.Y;
+    // lf.lfWidth  = FontSize.X;
+    lf.lfWeight = FontWeight;
+    // lf.lfItalic = bItalic;
+    lf.lfUnderline = bUnderline;
+    lf.lfStrikeOut = bStrikeOut;
+
+    /* Build a new font */
+    return CreateFontIndirect(&lf);
+}
+
+BOOL
+InitFonts(PGUI_CONSOLE_DATA GuiData,
+          LPWSTR FaceName, // Points to a WCHAR array of LF_FACESIZE elements.
+          ULONG  FontFamily,
+          COORD  FontSize,
+          ULONG  FontWeight)
+{
+    HDC hDC;
+    HFONT OldFont, NewFont;
+    TEXTMETRICW Metrics;
+    SIZE CharSize;
+
+    /*
+     * Initialize a new NORMAL font and get its metrics.
+     */
+
+    NewFont = CreateFontW(FontSize.Y,
+                          FontSize.X,
+                          0,
+                          TA_BASELINE,
+                          FontWeight,
+                          FALSE,
+                          FALSE,
+                          FALSE,
+                          OEM_CHARSET,
+                          OUT_DEFAULT_PRECIS,
+                          CLIP_DEFAULT_PRECIS,
+                          DEFAULT_QUALITY, // NONANTIALIASED_QUALITY ; ANTIALIASED_QUALITY
+                          FIXED_PITCH | FontFamily,
+                          FaceName);
+    if (NewFont == NULL)
     {
-        DPRINT1("GuiConsoleNcCreate: CreateFont failed\n");
-        GuiData->hWindow = NULL;
-        SetEvent(GuiData->hGuiInitEvent);
+        DPRINT1("InitFonts: CreateFontW failed\n");
         return FALSE;
     }
+
     hDC = GetDC(GuiData->hWindow);
-    if (NULL == hDC)
+    if (hDC == NULL)
     {
-        DPRINT1("GuiConsoleNcCreate: GetDC failed\n");
-        DeleteObject(GuiData->Font);
-        GuiData->hWindow = NULL;
-        SetEvent(GuiData->hGuiInitEvent);
+        DPRINT1("InitFonts: GetDC failed\n");
+        DeleteObject(NewFont);
         return FALSE;
     }
-    OldFont = SelectObject(hDC, GuiData->Font);
-    if (NULL == OldFont)
+
+    OldFont = SelectObject(hDC, NewFont);
+    if (OldFont == NULL)
     {
-        DPRINT1("GuiConsoleNcCreate: SelectObject failed\n");
+        DPRINT1("InitFonts: SelectObject failed\n");
         ReleaseDC(GuiData->hWindow, hDC);
-        DeleteObject(GuiData->Font);
-        GuiData->hWindow = NULL;
-        SetEvent(GuiData->hGuiInitEvent);
+        DeleteObject(NewFont);
         return FALSE;
     }
+
     if (!GetTextMetricsW(hDC, &Metrics))
     {
-        DPRINT1("GuiConsoleNcCreate: GetTextMetrics failed\n");
+        DPRINT1("InitFonts: GetTextMetrics failed\n");
         SelectObject(hDC, OldFont);
         ReleaseDC(GuiData->hWindow, hDC);
-        DeleteObject(GuiData->Font);
-        GuiData->hWindow = NULL;
-        SetEvent(GuiData->hGuiInitEvent);
+        DeleteObject(NewFont);
         return FALSE;
     }
     GuiData->CharWidth  = Metrics.tmMaxCharWidth;
@@ -565,9 +596,80 @@ OnNcCreate(HWND hWnd, LPCREATESTRUCTW Create)
         GuiData->CharWidth = CharSize.cx;
 
     SelectObject(hDC, OldFont);
-
     ReleaseDC(GuiData->hWindow, hDC);
 
+    /*
+     * Initialization succeeded.
+     */
+    // Delete all the old fonts first.
+    DeleteFonts(GuiData);
+    GuiData->Font[FONT_NORMAL] = NewFont;
+
+    /*
+     * Now build the other fonts (bold, underlined, mixed).
+     */
+    GuiData->Font[FONT_BOLD] =
+        CreateDerivedFont(GuiData->Font[FONT_NORMAL],
+                          FontWeight < FW_BOLD ? FW_BOLD : FontWeight,
+                          FALSE,
+                          FALSE);
+    GuiData->Font[FONT_UNDERLINE] =
+        CreateDerivedFont(GuiData->Font[FONT_NORMAL],
+                          FontWeight,
+                          TRUE,
+                          FALSE);
+    GuiData->Font[FONT_BOLD | FONT_UNDERLINE] =
+        CreateDerivedFont(GuiData->Font[FONT_NORMAL],
+                          FontWeight < FW_BOLD ? FW_BOLD : FontWeight,
+                          TRUE,
+                          FALSE);
+
+    /*
+     * Save the settings.
+     */
+    if (FaceName != GuiData->GuiInfo.FaceName)
+    {
+        SIZE_T Length = min(wcslen(FaceName) + 1, LF_FACESIZE); // wcsnlen
+        wcsncpy(GuiData->GuiInfo.FaceName, FaceName, LF_FACESIZE);
+        GuiData->GuiInfo.FaceName[Length] = L'\0'; // NULL-terminate
+    }
+    GuiData->GuiInfo.FontFamily = FontFamily;
+    GuiData->GuiInfo.FontSize   = FontSize;
+    GuiData->GuiInfo.FontWeight = FontWeight;
+
+    return TRUE;
+}
+
+
+static BOOL
+OnNcCreate(HWND hWnd, LPCREATESTRUCTW Create)
+{
+    PGUI_CONSOLE_DATA GuiData = (PGUI_CONSOLE_DATA)Create->lpCreateParams;
+    PCONSRV_CONSOLE Console;
+
+    if (NULL == GuiData)
+    {
+        DPRINT1("GuiConsoleNcCreate: No GUI data\n");
+        return FALSE;
+    }
+
+    Console = GuiData->Console;
+
+    GuiData->hWindow = hWnd;
+
+    /* Initialize the fonts */
+    if (!InitFonts(GuiData,
+                   GuiData->GuiInfo.FaceName,
+                   GuiData->GuiInfo.FontFamily,
+                   GuiData->GuiInfo.FontSize,
+                   GuiData->GuiInfo.FontWeight))
+    {
+        DPRINT1("GuiConsoleNcCreate: InitFonts failed\n");
+        GuiData->hWindow = NULL;
+        SetEvent(GuiData->hGuiInitEvent);
+        return FALSE;
+    }
+
     /* Initialize the terminal framebuffer */
     GuiData->hMemDC  = CreateCompatibleDC(NULL);
     GuiData->hBitmap = NULL;
@@ -1341,7 +1443,7 @@ OnNcDestroy(HWND hWnd)
         if (GuiData->hMemDC ) DeleteDC(GuiData->hMemDC);
         if (GuiData->hBitmap) DeleteObject(GuiData->hBitmap);
         // if (GuiData->hSysPalette) DeleteObject(GuiData->hSysPalette);
-        if (GuiData->Font) DeleteObject(GuiData->Font);
+        DeleteFonts(GuiData);
     }
 
     /* Free the GuiData registration */
index e7ee0c5..dee5c32 100644 (file)
 #define PM_CONSOLE_BEEP         (WM_APP + 4)
 #define PM_CONSOLE_SET_TITLE    (WM_APP + 5)
 
+/*
+typedef struct _CONSOLE_FONT
+{
+    HFONT Font;
+    ULONG Flag;
+} CONSOLE_FONT, *PCONSOLE_FONT;
+*/
+#define FONT_NORMAL     0x00
+#define FONT_BOLD       0x01
+#define FONT_UNDERLINE  0x02
+#define FONT_MAXNO      0x04
 
 typedef struct _GUI_CONSOLE_DATA
 {
@@ -56,9 +67,9 @@ typedef struct _GUI_CONSOLE_DATA
 
 //  PVOID   ScreenBuffer;       /* Hardware screen buffer */
 
-    HFONT Font;
-    UINT CharWidth;
-    UINT CharHeight;
+    HFONT Font[FONT_MAXNO];
+    UINT CharWidth;     /* The character width and height should be the same for */
+    UINT CharHeight;    /* both normal and bold/underlined fonts...              */
 /*****************************************************/
 
     PCONSRV_CONSOLE Console;           /* Pointer to the owned console */
index 8b19b79..12dce74 100644 (file)
@@ -17,9 +17,6 @@
 #include "guiterm.h"
 #include "guisettings.h"
 
-VOID GuiConsoleMoveWindow(PGUI_CONSOLE_DATA GuiData);
-VOID SwitchFullScreen(PGUI_CONSOLE_DATA GuiData, BOOL FullScreen);
-
 /* FUNCTIONS ******************************************************************/
 
 BOOL
@@ -199,14 +196,14 @@ GuiConsoleGetDefaultSettings(IN OUT PGUI_CONSOLE_INFO TermInfo,
     // wcsncpy(TermInfo->FaceName, L"DejaVu Sans Mono", LF_FACESIZE);
     // TermInfo->FontSize = MAKELONG(8, 12); // 0x000C0008; // font is 8x12
     // TermInfo->FontSize = MAKELONG(16, 16); // font is 16x16
-    // TermInfo->FontWeight = FW_NORMAL;
 
     wcsncpy(TermInfo->FaceName, L"VGA", LF_FACESIZE); // HACK: !!
     // TermInfo->FaceName[0] = L'\0';
     TermInfo->FontFamily = FF_DONTCARE;
     TermInfo->FontSize.X = 0;
     TermInfo->FontSize.Y = 0;
-    TermInfo->FontWeight = FW_DONTCARE;
+    TermInfo->FontWeight = FW_NORMAL; // HACK: !!
+    // TermInfo->FontWeight = FW_DONTCARE;
 
     TermInfo->FullScreen   = FALSE;
     TermInfo->ShowWindow   = SW_SHOWNORMAL;
@@ -418,92 +415,6 @@ Quit:
     return;
 }
 
-
-
-
-BOOL
-ChangeFont(PGUI_CONSOLE_DATA GuiData,
-           LPWSTR FaceName, // Points to a WCHAR array of LF_FACESIZE elements.
-           ULONG  FontFamily,
-           COORD  FontSize,
-           ULONG  FontWeight)
-{
-    HDC hDC;
-    HFONT OldFont, NewFont;
-    TEXTMETRICW Metrics;
-    SIZE CharSize;
-    SIZE_T Length;
-
-    NewFont = CreateFontW(FontSize.Y,
-                          0, // FontSize.X,
-                          0,
-                          TA_BASELINE,
-                          FontWeight,
-                          FALSE,
-                          FALSE,
-                          FALSE,
-                          OEM_CHARSET,
-                          OUT_DEFAULT_PRECIS,
-                          CLIP_DEFAULT_PRECIS,
-                          NONANTIALIASED_QUALITY,
-                          FIXED_PITCH | FontFamily /* FF_DONTCARE */,
-                          FaceName);
-    if (NewFont == NULL)
-    {
-        DPRINT1("ChangeFont: CreateFont failed\n");
-        return FALSE;
-    }
-
-    hDC = GetDC(GuiData->hWindow);
-    if (hDC == NULL)
-    {
-        DPRINT1("ChangeFont: GetDC failed\n");
-        DeleteObject(NewFont);
-        return FALSE;
-    }
-
-    OldFont = SelectObject(hDC, NewFont);
-    if (OldFont == NULL)
-    {
-        DPRINT1("ChangeFont: SelectObject failed\n");
-        ReleaseDC(GuiData->hWindow, hDC);
-        DeleteObject(NewFont);
-        return FALSE;
-    }
-
-    if (!GetTextMetricsW(hDC, &Metrics))
-    {
-        DPRINT1("ChangeFont: 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);
-
-    if (GuiData->Font != NULL) DeleteObject(GuiData->Font);
-    GuiData->Font = NewFont;
-
-    Length = min(wcslen(FaceName) + 1, LF_FACESIZE); // wcsnlen
-    wcsncpy(GuiData->GuiInfo.FaceName, FaceName, LF_FACESIZE);
-    GuiData->GuiInfo.FaceName[Length] = L'\0'; // NULL-terminate
-    GuiData->GuiInfo.FontFamily     = FontFamily;
-    GuiData->GuiInfo.FontSize       = FontSize;
-    GuiData->GuiInfo.FontWeight     = FontWeight;
-
-    return TRUE;
-}
-
-
-
 VOID
 GuiApplyUserSettings(PGUI_CONSOLE_DATA GuiData,
                      HANDLE hClientSection,
@@ -586,11 +497,11 @@ GuiApplyUserSettings(PGUI_CONSOLE_DATA GuiData,
             // memcpy(&GuiData->GuiInfo, GuiInfo, sizeof(GUI_CONSOLE_INFO));
 
             /* Change the font */
-            ChangeFont(GuiData,
-                       GuiInfo->FaceName,
-                       GuiInfo->FontFamily,
-                       GuiInfo->FontSize,
-                       GuiInfo->FontWeight);
+            InitFonts(GuiData,
+                      GuiInfo->FaceName,
+                      GuiInfo->FontFamily,
+                      GuiInfo->FontSize,
+                      GuiInfo->FontWeight);
            // HACK, needed because changing font may change the size of the window
            /**/TermResizeTerminal(Console);/**/
 
@@ -768,11 +679,11 @@ GuiApplyWindowsConsoleSettings(PGUI_CONSOLE_DATA GuiData,
             // memcpy(&GuiData->GuiInfo, &GuiInfo, sizeof(GUI_CONSOLE_INFO));
 
             /* Change the font */
-            ChangeFont(GuiData,
-                       GuiInfo.FaceName,
-                       GuiInfo.FontFamily,
-                       GuiInfo.FontSize,
-                       GuiInfo.FontWeight);
+            InitFonts(GuiData,
+                      GuiInfo.FaceName,
+                      GuiInfo.FontFamily,
+                      GuiInfo.FontSize,
+                      GuiInfo.FontWeight);
            // HACK, needed because changing font may change the size of the window
            /**/TermResizeTerminal(Console);/**/
 
index df95bdc..593c14e 100644 (file)
@@ -29,7 +29,6 @@
 
 typedef struct _GUI_CONSOLE_INFO
 {
-    // FONTSIGNATURE FontSignature;
     WCHAR FaceName[LF_FACESIZE];
     ULONG FontFamily;
     COORD FontSize;
index d039706..8755cdd 100644 (file)
@@ -20,3 +20,18 @@ NTSTATUS GuiInitConsole(PCONSOLE Console,
                         DWORD ProcessId,
                         LPCWSTR IconPath,
                         INT IconIndex);
+
+VOID
+GuiConsoleMoveWindow(PGUI_CONSOLE_DATA GuiData);
+
+VOID
+SwitchFullScreen(PGUI_CONSOLE_DATA GuiData, BOOL FullScreen);
+
+BOOL
+InitFonts(PGUI_CONSOLE_DATA GuiData,
+          LPWSTR FaceName, // Points to a WCHAR array of LF_FACESIZE elements.
+          ULONG  FontFamily,
+          COORD  FontSize,
+          ULONG  FontWeight);
+VOID
+DeleteFonts(PGUI_CONSOLE_DATA GuiData);
index cf02767..ba38aaa 100644 (file)
@@ -36,44 +36,6 @@ PaletteRGBFromAttrib(PCONSRV_CONSOLE Console, WORD Attribute)
     return PALETTERGB(pe.peRed, pe.peGreen, pe.peBlue);
 }
 
-static HFONT
-ChangeFontAttributes(PGUI_CONSOLE_DATA GuiData,
-                     // COORD   FontSize,
-                     ULONG   FontWeight,
-                     BOOLEAN bItalic,
-                     BOOLEAN bUnderline,
-                     BOOLEAN bStrikeOut)
-{
-    HFONT NewFont;
-    LOGFONT lf;
-
-    /* Initialize the LOGFONT structure */
-    RtlZeroMemory(&lf, sizeof(lf));
-
-    /* Retrieve the details of the current font */
-    if (GetObject(GuiData->Font, sizeof(lf), &lf) == 0)
-        return NULL; // GuiData->Font;
-
-    /* Change the font attributes */
-    // lf.lfHeight = FontSize.Y;
-    // lf.lfWidth  = FontSize.X;
-    lf.lfWeight = FontWeight;
-    lf.lfItalic = bItalic;
-    lf.lfUnderline = bUnderline;
-    lf.lfStrikeOut = bStrikeOut;
-
-    /* Build a new font */
-    NewFont = CreateFontIndirect(&lf);
-    if (NewFont == NULL)
-        return NULL; // GuiData->Font;
-
-    // FIXME: Do we need to update GuiData->CharWidth and GuiData->CharHeight ??
-
-    /* Select it (return the old font) */
-    // return SelectObject(GuiData->hMemDC, NewFont);
-    return NewFont;
-}
-
 static VOID
 CopyBlock(PTEXTMODE_SCREEN_BUFFER Buffer,
           PSMALL_RECT Selection)
@@ -388,7 +350,7 @@ GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
     ULONG CursorX, CursorY, CursorHeight;
     HBRUSH CursorBrush, OldBrush;
     HFONT OldFont, NewFont;
-    BOOLEAN IsUnderscore;
+    BOOLEAN IsUnderline;
 
     if (Buffer->Buffer == NULL) return;
 
@@ -412,17 +374,10 @@ GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
     SetTextColor(GuiData->hMemDC, PaletteRGBFromAttrib(Console, TextAttribFromAttrib(LastAttribute)));
     SetBkColor(GuiData->hMemDC, PaletteRGBFromAttrib(Console, BkgdAttribFromAttrib(LastAttribute)));
 
-    // OldFont = ChangeFontAttributes(GuiData, /* {0}, */ GuiData->GuiInfo.FontWeight, FALSE, FALSE, FALSE);
-    IsUnderscore = !!(LastAttribute & COMMON_LVB_UNDERSCORE);
-    NewFont = ChangeFontAttributes(GuiData, /* {0}, */ GuiData->GuiInfo.FontWeight,
-                                   FALSE,
-                                   IsUnderscore,
-                                   FALSE);
-    if (NewFont == NULL)
-    {
-        DPRINT1("ChangeFontAttributes failed, use the original font\n");
-        NewFont = GuiData->Font;
-    }
+    /* We use the underscore flag as a underline flag */
+    IsUnderline = !!(LastAttribute & COMMON_LVB_UNDERSCORE);
+    /* Select the new font */
+    NewFont = GuiData->Font[IsUnderline ? FONT_BOLD : FONT_NORMAL];
     OldFont = SelectObject(GuiData->hMemDC, NewFont);
 
     for (Line = TopLine; Line <= BottomLine; Line++)
@@ -454,25 +409,12 @@ GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
                     SetTextColor(GuiData->hMemDC, PaletteRGBFromAttrib(Console, TextAttribFromAttrib(LastAttribute)));
                     SetBkColor(GuiData->hMemDC, PaletteRGBFromAttrib(Console, BkgdAttribFromAttrib(LastAttribute)));
 
-                    /* Change underscore state if needed */
-                    if (!!(LastAttribute & COMMON_LVB_UNDERSCORE) != IsUnderscore)
+                    /* Change underline state if needed */
+                    if (!!(LastAttribute & COMMON_LVB_UNDERSCORE) != IsUnderline)
                     {
-                        IsUnderscore = !!(LastAttribute & COMMON_LVB_UNDERSCORE);
-
-                        /* Delete the font we used up to now */
-                        // SelectObject(GuiData->hMemDC, OldFont);
-                        if (NewFont != GuiData->Font) DeleteObject(NewFont);
-                        /* Recreate it */
-                        NewFont = ChangeFontAttributes(GuiData, /* {0}, */ GuiData->GuiInfo.FontWeight,
-                                                       FALSE,
-                                                       IsUnderscore,
-                                                       FALSE);
-                        if (NewFont == NULL)
-                        {
-                            DPRINT1("ChangeFontAttributes failed, use the original font\n");
-                            NewFont = GuiData->Font;
-                        }
-                        /* Select it */
+                        IsUnderline = !!(LastAttribute & COMMON_LVB_UNDERSCORE);
+                        /* Select the new font */
+                        NewFont = GuiData->Font[IsUnderline ? FONT_BOLD : FONT_NORMAL];
                         /* OldFont = */ SelectObject(GuiData->hMemDC, NewFont);
                     }
                 }
@@ -488,6 +430,9 @@ GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
                  RightChar - Start + 1);
     }
 
+    /* Restore the old font */
+    SelectObject(GuiData->hMemDC, OldFont);
+
     /*
      * Draw the caret
      */
@@ -520,10 +465,6 @@ GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
         }
     }
 
-    /* Restore the old font and delete the font we used up to now */
-    SelectObject(GuiData->hMemDC, OldFont);
-    if (NewFont != GuiData->Font) DeleteObject(NewFont);
-
     LeaveCriticalSection(&Console->Lock);
 }