[gtk+] gdkproperty-win32.c: Fix gtk-font-name handling



commit 9e686d1fb5cb2067e440d6cd6b501c0500390899
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Fri Mar 14 16:33:53 2014 +0800

    gdkproperty-win32.c: Fix gtk-font-name handling
    
    ...on Windows 8+ and when the system setting for non-Unicode programs do
    not match the language version of Windows by falling back to using Pango.
    
    This ensures that the correct font is used during these scenarios, so that
    we minimize the risk of seeing garbled characters for texts that the system
    code page does not support due to system peculiarties.  There might be a
    way to support gtk-font-name handling using the native Windows APIs
    directly on Windows 8+, but that needs to be investigated.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=726298

 gdk/win32/gdkproperty-win32.c |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/gdk/win32/gdkproperty-win32.c b/gdk/win32/gdkproperty-win32.c
index 2e36b04..cc0bd25 100644
--- a/gdk/win32/gdkproperty-win32.c
+++ b/gdk/win32/gdkproperty-win32.c
@@ -398,6 +398,36 @@ _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;
+
+      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))
         {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]