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 135098 - Way to convert from LOGFONT => PangoFontDescription
Way to convert from LOGFONT => PangoFontDescription
Status: RESOLVED FIXED
Product: pango
Classification: Platform
Component: win32
unspecified
Other Windows
: High normal
: Small API
Assigned To: gtk-win32 maintainers
pango-maint
: 135097 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2004-02-22 04:14 UTC by Zhang Yong
Modified: 2006-02-10 21:50 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Zhang Yong 2004-02-22 04:14:31 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.
Comment 1 Owen Taylor 2004-02-22 17:01:38 UTC
Are you specifying the font explicitely or is it being picked up as a
default font from the system?
Comment 2 Owen Taylor 2004-02-22 17:02:27 UTC
*** Bug 135097 has been marked as a duplicate of this bug. ***
Comment 3 Zhang Yong 2004-02-23 01:41:49 UTC
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.
Comment 4 Owen Taylor 2004-02-23 17:14:33 UTC
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.
Comment 5 Dominic Lachowicz 2004-02-23 17:36:21 UTC
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.
Comment 6 Dominic Lachowicz 2004-02-25 22:40:49 UTC
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.
Comment 7 Owen Taylor 2004-12-13 21:00:41 UTC
Bumping the priority to High as a simple fix I think it would be
nice to get into 1.10.
Comment 8 Behdad Esfahbod 2006-02-08 09:16:15 UTC
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 :).
Comment 9 Tor Lillqvist 2006-02-10 13:00:49 UTC
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().
Comment 10 Behdad Esfahbod 2006-02-10 19:23:03 UTC
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.
Comment 11 Dominic Lachowicz 2006-02-10 19:33:21 UTC
This is exactly the functionality that gtk-wimp needs. I can't wait to get rid of my duplicate code. Thanks Tor.
Comment 12 Tor Lillqvist 2006-02-10 21:50:23 UTC
Behdad, ok, done.