diff --git a/gdk/win32/gdkproperty-win32.c b/gdk/win32/gdkproperty-win32.c index 7c780428c0..5891debeea 100644 --- a/gdk/win32/gdkproperty-win32.c +++ b/gdk/win32/gdkproperty-win32.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "gdkscreen.h" #include "gdkproperty.h" @@ -239,6 +240,32 @@ _gdk_win32_window_delete_property (GdkWindow *window, } } +static gchar* +_get_system_font_name (HDC hdc) +{ + NONCLIENTMETRICSW ncm; + PangoFontDescription *font_desc; + gchar *result, *font_desc_string; + int logpixelsy; + gint font_size; + + ncm.cbSize = sizeof(NONCLIENTMETRICSW); + if (!SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0)) + return NULL; + + logpixelsy = GetDeviceCaps (hdc, LOGPIXELSY); + font_desc = pango_win32_font_description_from_logfontw (&ncm.lfMessageFont); + font_desc_string = pango_font_description_to_string (font_desc); + pango_font_description_free (font_desc); + + /* https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-taglogfonta */ + font_size = -MulDiv (ncm.lfMessageFont.lfHeight, 72, logpixelsy); + result = g_strdup_printf ("%s %d", font_desc_string, font_size); + g_free (font_desc_string); + + return result; +} + /* For reference, from gdk/x11/gdksettings.c: @@ -371,58 +398,27 @@ _gdk_win32_screen_get_setting (GdkScreen *screen, } else if (strcmp ("gtk-font-name", name) == 0) { - NONCLIENTMETRICS ncm; - CPINFOEX cpinfoex_default, cpinfoex_curr_thread; - OSVERSIONINFO info; - BOOL result_default, result_curr_thread; + gchar *font_name = _get_system_font_name (_gdk_display_hdc); - info.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); - - /* TODO: Fallback to using Pango on Windows 8 and later, - * as this method of handling gtk-font-name does not work - * well there, where garbled text will be displayed for texts - * that are not supported by the default menu font. Look for - * whether there is a better solution for this on Windows 8 and - * later - */ - if (!GetVersionEx (&info) || - info.dwMajorVersion > 6 || - (info.dwMajorVersion == 6 && info.dwMinorVersion >= 2)) - return FALSE; - - /* check whether the system default ANSI codepage matches the - * ANSI code page of the running thread. If so, continue, otherwise - * fall back to using Pango to handle gtk-font-name - */ - result_default = GetCPInfoEx (CP_ACP, 0, &cpinfoex_default); - result_curr_thread = GetCPInfoEx (CP_THREAD_ACP, 0, &cpinfoex_curr_thread); - - if (!result_default || - !result_curr_thread || - cpinfoex_default.CodePage != cpinfoex_curr_thread.CodePage) - return FALSE; - - ncm.cbSize = sizeof(NONCLIENTMETRICS); - if (SystemParametersInfo (SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, FALSE)) + if (font_name) { - /* Pango finally uses GetDeviceCaps to scale, we use simple - * approximation here. - */ - int nHeight = (0 > ncm.lfMenuFont.lfHeight ? - 3 * ncm.lfMenuFont.lfHeight / 4 : 10); - if (OUT_STRING_PRECIS == ncm.lfMenuFont.lfOutPrecision) - GDK_NOTE(MISC, g_print("gdk_screen_get_setting(%s) : ignoring bitmap font '%s'\n", - name, ncm.lfMenuFont.lfFaceName)); - else if (ncm.lfMenuFont.lfFaceName && strlen(ncm.lfMenuFont.lfFaceName) > 0 && - /* Avoid issues like those described in bug #135098 */ - g_utf8_validate (ncm.lfMenuFont.lfFaceName, -1, NULL)) + /* The pango font fallback list got fixed during 1.43, before that + * using anything but "Segoe UI" would lead to a poor glyph coverage */ + if (pango_version_check (1, 43, 0) != NULL && + g_ascii_strncasecmp (font_name, "Segoe UI", strlen ("Segoe UI")) != 0) { - char *s = g_strdup_printf ("%s %d", ncm.lfMenuFont.lfFaceName, nHeight); - GDK_NOTE(MISC, g_print("gdk_screen_get_setting(%s) : %s\n", name, s)); - g_value_set_string (value, s); - - g_free(s); - return TRUE; + g_free (font_name); + return FALSE; } + + GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : %s\n", name, font_name)); + g_value_take_string (value, font_name); + return TRUE; + } + else + { + g_warning ("gdk_screen_get_setting: Detecting the system font failed"); + return FALSE; } } else if (strcmp ("gtk-im-module", name) == 0)