After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 404506 - Windows system fonts that have multi-byte font names cannot be loaded
Windows system fonts that have multi-byte font names cannot be loaded
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Backend: Win32
2.10.x
Other Windows
: Normal normal
: ---
Assigned To: gtk-win32 maintainers
gtk-bugs
: 428284 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2007-02-05 05:53 UTC by Hiroyuki Yamamoto
Modified: 2007-04-13 01:21 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Hiroyuki Yamamoto 2007-02-05 05:53:19 UTC
Under Windows 2000/XP/Vista, when using ms-windows engine, it tries to use system fonts, but fails to load fonts with multi-byte names in it with the following warnings (in this case it's Japanese). The older GTK+ (<= 2.6) crashed if this occurs, but 2.8 or later just fall backs to Sans (no crash).

** Pango-WARNING: couldn't load font "メイリオ Bold 9", falling back to "Sans Bold 9", expect ugly output.

I have looked into the code of gtk-wimp, and I think I have found a bug in function msw_style.c::sys_font_to_pango_font().

It gets hDC from destop window handle with GetDC(), calculate pt_size, and release hDC with ReleaseDC(). Then, the already released hDC is passed to function get_family_name().

In get_family_name() function, the hDC (pango_win32_hdc) is passed to SelectObject(). It fails with ERROR_INVALID_PARAMETER (87) because hDC is already released. If the hDC is not released, the corresponding ASCII font name (in this case "Meiryo") is looked up as expected.

Somehow the current code doesn't fail if the font only contains an ASCII name. I think that's why this bug was overlooked for a long time.

The following simple patch fixes the bug.
(Maybe this bug is related to #112401)

--- msw_style.c.orig    Tue Jan 23 00:52:04 2007
+++ msw_style.c Mon Feb  5 14:36:37 2007
@@ -466,12 +466,13 @@
                {
                    pt_size = -MulDiv (lf.lfHeight, 72,
                                       GetDeviceCaps (hDC, LOGPIXELSY));
-                   ReleaseDC (hwnd, hDC);
                }
            else
                pt_size = 10;
 
            font = get_family_name (&lf, hDC);
+           if (hDC)
+               ReleaseDC (hwnd, hDC);
            if(!(font && *font))
                return NULL;
Comment 1 Dominic Lachowicz 2007-02-12 20:57:56 UTC
2007-02-05  Dom Lachowicz <domlachowicz@gmail.com>

        * modules/engines/ms-windows/msw_style.c: Fix bug 404506, caused
        by prematurely releasing a DC. By Hiroyuki Yamamoto
        * modules/engines/ms-windows/msw_style.c: Fix bug 403470 - leaking
        pixbufs when drawing rotated tabs. By Daniel Atallah
Comment 2 Dominic Lachowicz 2007-04-13 01:21:52 UTC
*** Bug 428284 has been marked as a duplicate of this bug. ***