GNOME Bugzilla – Bug 135098
Way to convert from LOGFONT => PangoFontDescription
Last modified: 2006-02-10 21:50:23 UTC
When any gtk-win32 programs start up, the console writes: ** (test.exe:4032): WARNING **: [Invalid UTF-8] Couldn¡¯t load font ¡°ËÎ Ìå 9¡± falling back to ¡°Sans 9¡± But the specified font DOES exist in my system! The result is that my gtk programs look very ugly on my Windows OS.
Are you specifying the font explicitely or is it being picked up as a default font from the system?
*** Bug 135097 has been marked as a duplicate of this bug. ***
I had not modified any of the files such as gtkrc, etc. I installed gtk using GTK-Runtime-Environment-2.2.4.1.exe installer.
I think this is a gtk-wimp bug; when it retrieves the font via GetSystemFont or however, it is getting it in the wrong encoding; what we say for fontconfig is that PangoFontDescription always contains an ASCII font name that is independent of the user's current language. (If it is non ASCII, it should be in UTF-8, but preferrably we should be using an ASCII name.) See pango/pango/pangowin32-fontmap.c:get_family_name() for how Pango derives the right name from a LOGFONT. Raymond - could you make sure that this gets entered wherever gtk-wimp bugs are tracked? (if you agree that it is a gtk-wimp issue) I'm going to retitle and purpose this font to adding an API to convert from LOGFONT to PangoFontDescription, since I think that would be useful.
gosh, that function is nasty looking :) i'll cut+paste it into gtk-wimp. when pango 1.6 comes out, i'll use the publicly available function as Owen has suggested. thanks, Owen.
gtk-wimp has copied these few functions from pango-win32-fontmap.c and pango-win32.c. i'm looking forward to pango 1.6 so that i can get rid of these functions.
Bumping the priority to High as a simple fix I think it would be nice to get into 1.10.
Tor, can you fix this? I don't have access to win32 and don't want to mess with code that I cannot compile more than I'm currently doing :).
Function added to HEAD, will thus be in Pango 1.12. Behdad, does the name look OK to you? /** * pango_win32_pango_font_description_from_logfont: * @lfp: pointer to a LOGFONT * * Creates a #PangoFontDescription from a LOGFONT. * * The face name, italicness and weight fields in the LOGFONT are used * to set up the resulting #PangoFontDescription. If the face name in * the LOGFONT contains non-ASCII characters the font is temporarily * loaded (using CreateFontIndirect) and an ASCII (usually English) * name for it is looked up from the font name tables in the font * data. If that doesn't work, the face name is converted from the * system codepage to UTF-8 and that is used. * * Return value: a new #PangoFontDescription that should be freed with * pango_font_desciption_free() when no longer needed. * * Since: 1.12 */ PangoFontDescription * pango_win32_pango_font_description_from_logfont (const LOGFONT *lfp) 2006-02-10 Tor Lillqvist <tml@novell.com> Fix #135098 and #322510. * pango/pangowin32-fontmap.c (case_insensitive_hash) (case_insensitive_equal): New helper functions for string hashing based on ASCII case insensitivity.. (logfont_nosize_hash): Use case_insensitive_hash(). (logfont_nosize_equal): Use case_insensitive_equal(). (pango_win32_font_map_init): Use the case-insensitive functions for the PangoWin32FontMap::families hash table. (pango_win32_font_map_load_font): Consequently we don't need to lowercase the name before looking up from the hash table. (get_family_name): Constify parameter. (get_family_name_lowercase): Not needed any longer. (pango_win32_pango_font_description_from_logfont): New public function. Code moved from pango_win32_insert_font(). Use family name as such, don't lowercase it. (pango_win32_insert_font): Use the above new function. Don't bother looking for superfluos copies of the font entry as that shouldn't ever happen. We have pruned out fonts that differ only in charset already earlier. * pango/pangowin32.h: Declare pango_win32_pango_font_description_from_logfont().
Thanks Tor. I think I prefer pango_win32_font_description_from_logfont, as we already have this pattern in pango_fc_font_description_from_pattern. There's a type in the docs. Please replace the Return value paragraph with this: * Return value: the newly allocated #PangoFontDescription, which * should be freed using pango_font_description_free(). I just made them all look like this, so a bit of consistency here :). Oh, and don't forget to add an entry to pangowin32.def and add it in the right place in the docs/pango-sections.txt.
This is exactly the functionality that gtk-wimp needs. I can't wait to get rid of my duplicate code. Thanks Tor.
Behdad, ok, done.