GNOME Bugzilla – Bug 68113
PangoFontDescription is locale-dependent strings on Windows.
Last modified: 2004-12-22 21:47:04 UTC
I built gtk+ and pango cvs head sources on Mingw environment. I executed testgtk and invoked Font Selection Dialog on Japanese Windows 2000 Professional. Japanese popular Font "MS Gothic" and "MS Mincho" in Japanese KANJI were not listed. logfont_to_xlfd() in gtk+/gdk/win32/gdkfont-win32.c has g_filename_to_utf8(), but pangowin32 does not have this function. I created following patch and attached it, I confirmed "MS Gothic" and "MS Mincho" in Japanese KANJI were listed. I think strings allocated by g_filename_to_utf8() must be freed in somewhere, but I can not understand where to free this. --- pangowin32-fontmap.c Sun Jan 6 16:53:54 2002 +++ pangowin32-fontmap.c.new Sun Jan 6 16:53:09 2002 @@ -750,11 +750,12 @@ size_info->logfonts = g_slist_prepend (size_info->logfonts, lfp2); /* Convert the LOGFONT into a PangoFontDescription */ - family_name = lfp2->lfFaceName; + /* family_name = lfp2->lfFaceName; */ + family_name = g_filename_to_utf8 (lfp->lfFaceName, -1, NULL, NULL, NULL); if (!lfp2->lfItalic) style = PANGO_STYLE_NORMAL; else style = PANGO_STYLE_ITALIC;
Should this be using the lfCharset value from the LOGFONT structure instead of the current codepage as g_locale_to_utf8() does? The value can be freed after the last use in the function, since pango_win32_get_font_family copies the family. But there seem to be other uses of lfpFaceName, so I'm not sure this is a complete solution. As a more general issue: - The family names in font descriptions are supposed to be locale independent so you can write programs that can run in different locales. The SDK docs say: The fonts for many East Asian languages have two typeface names: an English name and a localized name. EnumFonts, EnumFontFamilies, and EnumFontFamiliesEx return the English typeface name if the system locale does not match the language of the font. Which is not a helpful behavior. Can we switch the locale for the program temporarily, list the fonts, and switch back? We should have pango_font_family_get_display_name() that returns a localized name, if available, but that would be a future API addition.
I think this probrem is simply character set probrem. So, in order to resolve this problem, pango only should convert Shift-JIS as locale-dependent strings to UTF-8. > Should this be using the lfCharset value from the LOGFONT > structure instead of the current codepage as g_locale_to_utf8() > does? Sorry, I can't understand what this means. g_filename_to_utf8() simply calls g_locale_to_utf8() on windows. > Can we switch the locale > for the program temporarily, list the fonts, and switch > back? I tried to try whether this would be possible. Win32 API SetThreadLocale() is supported on Windows NT/2000/XP. But this function is NOT supported on Windows 95/98/Me.
On X11 environment with Xft enabled, encoding of TrueType font name cause trouble. GtkFontSelection class cannot work correctly. Most of font names are displayed as empty. So, Japanese user can't use font selection dialog on many application. Encoding of name of Japanese TrueType fonts and family_name holded by PangoFontDescrition are Shift_JIS (Mac variants of Windows varints), locale encoding is EUC-JP, and GTK+ assumes encodig of string are UTF-8.
For some more on the Xft problem, see: http://www.freetype.org/pipermail/devel/2002-March/003101.html
Re Owen's comment from 2002-01-06 : No, unfortunately we cannot switch the thread's locale back and forth. There is SetThreadLocale (), but it isn't present on Win9x/Me. But presumably one should be able to peek out the ASCII name from the font file using GetFontData(). Will have to borrow code from FreeType to do that.
The code in PangoWin32 now seems to implement the same algorithm as FreeType, so I think this can be considered fixesd. I've filed bug 95731 to cover the issue of adding an API to get the localized name for display.