[PATCH v3 2/4] kernel32: Implement GetCurrentConsoleFontEx.

Gijs Vermeulen gijsvrm at codeweavers.com
Wed Nov 20 04:45:29 CST 2019


Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47620
Signed-off-by: Gijs Vermeulen <gijsvrm at codeweavers.com>
---
 dlls/kernel32/console.c     | 50 +++++++++++++++++++++++++++++++++++--
 dlls/kernel32/kernel32.spec |  2 +-
 server/console.c            | 17 +++++++++++--
 server/protocol.def         | 31 ++++++++++++-----------
 4 files changed, 81 insertions(+), 19 deletions(-)

diff --git a/dlls/kernel32/console.c b/dlls/kernel32/console.c
index a698e53efe..7f7c843d66 100644
--- a/dlls/kernel32/console.c
+++ b/dlls/kernel32/console.c
@@ -1639,17 +1639,33 @@ BOOL WINAPI SetConsoleKeyShortcuts(BOOL set, BYTE keys, VOID *a, DWORD b)
 }
 
 
-BOOL WINAPI GetCurrentConsoleFont(HANDLE hConsole, BOOL maxwindow, LPCONSOLE_FONT_INFO fontinfo)
+BOOL WINAPI GetCurrentConsoleFontEx(HANDLE hConsole, BOOL maxwindow, CONSOLE_FONT_INFOEX *fontinfo)
 {
     BOOL ret;
+    void *data;
+    size_t color_map_size = 16 * sizeof(unsigned int);
+    size_t face_name_len = sizeof(fontinfo->FaceName) - sizeof(WCHAR);
 
-    memset(fontinfo, 0, sizeof(CONSOLE_FONT_INFO));
+    if (fontinfo->cbSize != sizeof(CONSOLE_FONT_INFOEX))
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
+    data = HeapAlloc(GetProcessHeap(), 0, face_name_len + color_map_size);
+    if (!data)
+    {
+        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+        return FALSE;
+    }
 
     SERVER_START_REQ(get_console_output_info)
     {
         req->handle = console_handle_unmap(hConsole);
+        wine_server_set_reply(req, data, face_name_len + color_map_size);
         if ((ret = !wine_server_call_err(req)))
         {
+            fontinfo->nFont = 0;
             if (maxwindow)
             {
                 fontinfo->dwFontSize.X = min(reply->width, reply->max_width);
@@ -1660,9 +1676,39 @@ BOOL WINAPI GetCurrentConsoleFont(HANDLE hConsole, BOOL maxwindow, LPCONSOLE_FON
                 fontinfo->dwFontSize.X = reply->win_right - reply->win_left + 1;
                 fontinfo->dwFontSize.Y = reply->win_bottom - reply->win_top + 1;
             }
+            if (wine_server_reply_size(reply) > color_map_size)
+            {
+                face_name_len = min(face_name_len, wine_server_reply_size(reply) - color_map_size);
+                memcpy(fontinfo->FaceName, (char *)data + color_map_size, face_name_len);
+                fontinfo->FaceName[face_name_len / sizeof(WCHAR)] = 0;
+            }
+            else
+                fontinfo->FaceName[0] = 0;
+            fontinfo->FontFamily = reply->font_pitch_family;
+            fontinfo->FontWeight = reply->font_weight;
         }
     }
     SERVER_END_REQ;
+
+    HeapFree(GetProcessHeap(), 0, data);
+
+    return ret;
+}
+
+BOOL WINAPI GetCurrentConsoleFont(HANDLE hConsole, BOOL maxwindow, CONSOLE_FONT_INFO *fontinfo)
+{
+    BOOL ret;
+    CONSOLE_FONT_INFOEX res;
+
+    res.cbSize = sizeof(CONSOLE_FONT_INFOEX);
+
+    ret = GetCurrentConsoleFontEx(hConsole, maxwindow, &res);
+    if(ret)
+    {
+        fontinfo->nFont = res.nFont;
+        fontinfo->dwFontSize.X = res.dwFontSize.X;
+        fontinfo->dwFontSize.Y = res.dwFontSize.Y;
+    }
     return ret;
 }
 
diff --git a/dlls/kernel32/kernel32.spec b/dlls/kernel32/kernel32.spec
index 5d543f1eb5..28c3b83a06 100644
--- a/dlls/kernel32/kernel32.spec
+++ b/dlls/kernel32/kernel32.spec
@@ -623,7 +623,7 @@
 @ stdcall GetCurrencyFormatW(long long wstr ptr ptr long)
 @ stdcall -import GetCurrentActCtx(ptr)
 @ stdcall GetCurrentConsoleFont(long long ptr)
-# @ stub GetCurrentConsoleFontEx
+@ stdcall GetCurrentConsoleFontEx(long long ptr)
 @ stdcall -import GetCurrentDirectoryA(long ptr)
 @ stdcall -import GetCurrentDirectoryW(long ptr)
 @ stdcall GetCurrentPackageFamilyName(ptr ptr)
diff --git a/server/console.c b/server/console.c
index d40da275e9..f746cdf3b3 100644
--- a/server/console.c
+++ b/server/console.c
@@ -1755,6 +1755,8 @@ DECL_HANDLER(set_console_output_info)
 DECL_HANDLER(get_console_output_info)
 {
     struct screen_buffer *screen_buffer;
+    void *data;
+    data_size_t total;
 
     if ((screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->handle,
                                                                  FILE_READ_PROPERTIES, &screen_buffer_ops)))
@@ -1775,8 +1777,19 @@ DECL_HANDLER(get_console_output_info)
         reply->max_height     = screen_buffer->max_height;
         reply->font_width     = screen_buffer->font.width;
         reply->font_height    = screen_buffer->font.height;
-        set_reply_data( screen_buffer->color_map,
-                        min( sizeof(screen_buffer->color_map), get_reply_max_size() ));
+        reply->font_weight    = screen_buffer->font.weight;
+        reply->font_pitch_family = screen_buffer->font.pitch_family;
+        total = min( sizeof(screen_buffer->color_map) + screen_buffer->font.face_name.len, get_reply_max_size() );
+        if (total)
+        {
+            data = set_reply_data_size( total );
+            memcpy( data, screen_buffer->color_map, min( total, sizeof(screen_buffer->color_map) ));
+            if (screen_buffer->font.face_name.len && total > sizeof(screen_buffer->color_map))
+            {
+                memcpy( (char *)data + sizeof(screen_buffer->color_map), screen_buffer->font.face_name.str,
+                    min( total - sizeof(screen_buffer->color_map), screen_buffer->font.face_name.len ));
+            }
+        }
         release_object( screen_buffer );
     }
 }
diff --git a/server/protocol.def b/server/protocol.def
index 4dc9a278ad..950c6d0525 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -1651,25 +1651,28 @@ struct console_renderer_event
 
 /* Get info about a console (output only) */
 @REQ(get_console_output_info)
-    obj_handle_t handle;        /* handle to the console */
+    obj_handle_t handle;            /* handle to the console */
 @REPLY
-    short int    cursor_size;   /* size of cursor (percentage filled) */
-    short int    cursor_visible;/* cursor visibility flag */
-    short int    cursor_x;      /* position of cursor (x, y) */
+    short int    cursor_size;       /* size of cursor (percentage filled) */
+    short int    cursor_visible;    /* cursor visibility flag */
+    short int    cursor_x;          /* position of cursor (x, y) */
     short int    cursor_y;
-    short int    width;         /* width of the screen buffer */
-    short int    height;        /* height of the screen buffer */
-    short int    attr;          /* default fill attributes (screen colors) */
-    short int    popup_attr;    /* pop-up color attributes */
-    short int    win_left;      /* window actually displayed by renderer */
-    short int    win_top;       /* the rect area is expressed within the */
-    short int    win_right;     /* boundaries of the screen buffer */
+    short int    width;             /* width of the screen buffer */
+    short int    height;            /* height of the screen buffer */
+    short int    attr;              /* default fill attributes (screen colors) */
+    short int    popup_attr;        /* pop-up color attributes */
+    short int    win_left;          /* window actually displayed by renderer */
+    short int    win_top;           /* the rect area is expressed within the */
+    short int    win_right;         /* boundaries of the screen buffer */
     short int    win_bottom;
-    short int    max_width;     /* maximum size (width x height) for the window */
+    short int    max_width;         /* maximum size (width x height) for the window */
     short int    max_height;
-    short int    font_width;    /* font size (width x height) */
+    short int    font_width;        /* font size (width x height) */
     short int    font_height;
-    VARARG(colors,uints);       /* color table */
+    short int    font_weight;       /* font weight */
+    short int    font_pitch_family; /* font pitch & family */
+    VARARG(colors,uints);           /* color table */
+    VARARG(face_name,unicode_str);  /* font face name */
 @END
 
 /* Add input records to a console input queue */
-- 
2.24.0




More information about the wine-devel mailing list