From 018d098240567972205f0ade11c8cdc8eb5a91c1 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Wed, 13 Oct 1999 21:46:33 +0000 Subject: [PATCH] Don't use TextOutW for GDK_FONT_FONT fonts (which is all we have for now, 1999-10-14 Tor Lillqvist * gdk/win32/gdkdraw.c (gdk_draw_text_wc): Don't use TextOutW for GDK_FONT_FONT fonts (which is all we have for now, we don't emulate fontsets). The X11 version uses plain XDrawString in that case, too. The string passed to gdk_draw_text_wc seems to be in fact (at least, when used by gtkentry and gtktext) either in a single-byte charset, or a DBCS. Not Unicode. This fixes the problem in gtkfontsel, where even if you had selected a font with a non-Latin1 charset (windows-greek, for instance), the preview still used Latin-1 glyphs. * gdk/win32/gdkfont.c (gdk_text_width_wc): Similar change. Don't use GetTextExtentPoint32W, use GetTextExtentPoint32A. (gdk_font_load): Recognize the demibold etc weights, even if we don't have the corresponding constants in the headers. (gdk_font_hash_insert): Use same hash mechanism as in the X11 version. Should save font resources a bit, when we don't have multiple HFONTs for the same font. * gdk/win32/gdkprivate.h: Add the names field as in the X11 version. --- ChangeLog | 24 ++++++ ChangeLog.pre-2-0 | 24 ++++++ ChangeLog.pre-2-10 | 24 ++++++ ChangeLog.pre-2-2 | 24 ++++++ ChangeLog.pre-2-4 | 24 ++++++ ChangeLog.pre-2-6 | 24 ++++++ ChangeLog.pre-2-8 | 24 ++++++ gdk/win32/gdkdraw.c | 17 ++++- gdk/win32/gdkdrawable-win32.c | 17 ++++- gdk/win32/gdkevents-win32.c | 3 +- gdk/win32/gdkevents.c | 3 +- gdk/win32/gdkfont-win32.c | 134 ++++++++++++++++++++++++++++------ gdk/win32/gdkfont.c | 134 ++++++++++++++++++++++++++++------ gdk/win32/gdkprivate-win32.h | 7 +- gdk/win32/gdkprivate.h | 7 +- gtk/makefile.cygwin | 5 ++ 16 files changed, 433 insertions(+), 62 deletions(-) diff --git a/ChangeLog b/ChangeLog index 66459eec63..da734fab2d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +1999-10-14 Tor Lillqvist + + * gdk/win32/gdkdraw.c (gdk_draw_text_wc): Don't use TextOutW for + GDK_FONT_FONT fonts (which is all we have for now, we don't + emulate fontsets). The X11 version uses plain XDrawString in that + case, too. The string passed to gdk_draw_text_wc seems to be in + fact (at least, when used by gtkentry and gtktext) either in a + single-byte charset, or a DBCS. Not Unicode. + + This fixes the problem in gtkfontsel, where even if you had + selected a font with a non-Latin1 charset (windows-greek, for + instance), the preview still used Latin-1 glyphs. + + * gdk/win32/gdkfont.c (gdk_text_width_wc): Similar change. Don't + use GetTextExtentPoint32W, use GetTextExtentPoint32A. + (gdk_font_load): Recognize the demibold etc weights, even if we + don't have the corresponding constants in the headers. + (gdk_font_hash_insert): Use same hash mechanism as in the X11 + version. Should save font resources a bit, when we don't have + multiple HFONTs for the same font. + + * gdk/win32/gdkprivate.h: Add the names field as in the X11 + version. + 1999-10-11 ERDI Gergo * gdk/gdk.c (gdk_beep): Modified the XBell call to use the default diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 66459eec63..da734fab2d 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,27 @@ +1999-10-14 Tor Lillqvist + + * gdk/win32/gdkdraw.c (gdk_draw_text_wc): Don't use TextOutW for + GDK_FONT_FONT fonts (which is all we have for now, we don't + emulate fontsets). The X11 version uses plain XDrawString in that + case, too. The string passed to gdk_draw_text_wc seems to be in + fact (at least, when used by gtkentry and gtktext) either in a + single-byte charset, or a DBCS. Not Unicode. + + This fixes the problem in gtkfontsel, where even if you had + selected a font with a non-Latin1 charset (windows-greek, for + instance), the preview still used Latin-1 glyphs. + + * gdk/win32/gdkfont.c (gdk_text_width_wc): Similar change. Don't + use GetTextExtentPoint32W, use GetTextExtentPoint32A. + (gdk_font_load): Recognize the demibold etc weights, even if we + don't have the corresponding constants in the headers. + (gdk_font_hash_insert): Use same hash mechanism as in the X11 + version. Should save font resources a bit, when we don't have + multiple HFONTs for the same font. + + * gdk/win32/gdkprivate.h: Add the names field as in the X11 + version. + 1999-10-11 ERDI Gergo * gdk/gdk.c (gdk_beep): Modified the XBell call to use the default diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 66459eec63..da734fab2d 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,27 @@ +1999-10-14 Tor Lillqvist + + * gdk/win32/gdkdraw.c (gdk_draw_text_wc): Don't use TextOutW for + GDK_FONT_FONT fonts (which is all we have for now, we don't + emulate fontsets). The X11 version uses plain XDrawString in that + case, too. The string passed to gdk_draw_text_wc seems to be in + fact (at least, when used by gtkentry and gtktext) either in a + single-byte charset, or a DBCS. Not Unicode. + + This fixes the problem in gtkfontsel, where even if you had + selected a font with a non-Latin1 charset (windows-greek, for + instance), the preview still used Latin-1 glyphs. + + * gdk/win32/gdkfont.c (gdk_text_width_wc): Similar change. Don't + use GetTextExtentPoint32W, use GetTextExtentPoint32A. + (gdk_font_load): Recognize the demibold etc weights, even if we + don't have the corresponding constants in the headers. + (gdk_font_hash_insert): Use same hash mechanism as in the X11 + version. Should save font resources a bit, when we don't have + multiple HFONTs for the same font. + + * gdk/win32/gdkprivate.h: Add the names field as in the X11 + version. + 1999-10-11 ERDI Gergo * gdk/gdk.c (gdk_beep): Modified the XBell call to use the default diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 66459eec63..da734fab2d 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,27 @@ +1999-10-14 Tor Lillqvist + + * gdk/win32/gdkdraw.c (gdk_draw_text_wc): Don't use TextOutW for + GDK_FONT_FONT fonts (which is all we have for now, we don't + emulate fontsets). The X11 version uses plain XDrawString in that + case, too. The string passed to gdk_draw_text_wc seems to be in + fact (at least, when used by gtkentry and gtktext) either in a + single-byte charset, or a DBCS. Not Unicode. + + This fixes the problem in gtkfontsel, where even if you had + selected a font with a non-Latin1 charset (windows-greek, for + instance), the preview still used Latin-1 glyphs. + + * gdk/win32/gdkfont.c (gdk_text_width_wc): Similar change. Don't + use GetTextExtentPoint32W, use GetTextExtentPoint32A. + (gdk_font_load): Recognize the demibold etc weights, even if we + don't have the corresponding constants in the headers. + (gdk_font_hash_insert): Use same hash mechanism as in the X11 + version. Should save font resources a bit, when we don't have + multiple HFONTs for the same font. + + * gdk/win32/gdkprivate.h: Add the names field as in the X11 + version. + 1999-10-11 ERDI Gergo * gdk/gdk.c (gdk_beep): Modified the XBell call to use the default diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 66459eec63..da734fab2d 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,27 @@ +1999-10-14 Tor Lillqvist + + * gdk/win32/gdkdraw.c (gdk_draw_text_wc): Don't use TextOutW for + GDK_FONT_FONT fonts (which is all we have for now, we don't + emulate fontsets). The X11 version uses plain XDrawString in that + case, too. The string passed to gdk_draw_text_wc seems to be in + fact (at least, when used by gtkentry and gtktext) either in a + single-byte charset, or a DBCS. Not Unicode. + + This fixes the problem in gtkfontsel, where even if you had + selected a font with a non-Latin1 charset (windows-greek, for + instance), the preview still used Latin-1 glyphs. + + * gdk/win32/gdkfont.c (gdk_text_width_wc): Similar change. Don't + use GetTextExtentPoint32W, use GetTextExtentPoint32A. + (gdk_font_load): Recognize the demibold etc weights, even if we + don't have the corresponding constants in the headers. + (gdk_font_hash_insert): Use same hash mechanism as in the X11 + version. Should save font resources a bit, when we don't have + multiple HFONTs for the same font. + + * gdk/win32/gdkprivate.h: Add the names field as in the X11 + version. + 1999-10-11 ERDI Gergo * gdk/gdk.c (gdk_beep): Modified the XBell call to use the default diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 66459eec63..da734fab2d 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,27 @@ +1999-10-14 Tor Lillqvist + + * gdk/win32/gdkdraw.c (gdk_draw_text_wc): Don't use TextOutW for + GDK_FONT_FONT fonts (which is all we have for now, we don't + emulate fontsets). The X11 version uses plain XDrawString in that + case, too. The string passed to gdk_draw_text_wc seems to be in + fact (at least, when used by gtkentry and gtktext) either in a + single-byte charset, or a DBCS. Not Unicode. + + This fixes the problem in gtkfontsel, where even if you had + selected a font with a non-Latin1 charset (windows-greek, for + instance), the preview still used Latin-1 glyphs. + + * gdk/win32/gdkfont.c (gdk_text_width_wc): Similar change. Don't + use GetTextExtentPoint32W, use GetTextExtentPoint32A. + (gdk_font_load): Recognize the demibold etc weights, even if we + don't have the corresponding constants in the headers. + (gdk_font_hash_insert): Use same hash mechanism as in the X11 + version. Should save font resources a bit, when we don't have + multiple HFONTs for the same font. + + * gdk/win32/gdkprivate.h: Add the names field as in the X11 + version. + 1999-10-11 ERDI Gergo * gdk/gdk.c (gdk_beep): Modified the XBell call to use the default diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 66459eec63..da734fab2d 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,27 @@ +1999-10-14 Tor Lillqvist + + * gdk/win32/gdkdraw.c (gdk_draw_text_wc): Don't use TextOutW for + GDK_FONT_FONT fonts (which is all we have for now, we don't + emulate fontsets). The X11 version uses plain XDrawString in that + case, too. The string passed to gdk_draw_text_wc seems to be in + fact (at least, when used by gtkentry and gtktext) either in a + single-byte charset, or a DBCS. Not Unicode. + + This fixes the problem in gtkfontsel, where even if you had + selected a font with a non-Latin1 charset (windows-greek, for + instance), the preview still used Latin-1 glyphs. + + * gdk/win32/gdkfont.c (gdk_text_width_wc): Similar change. Don't + use GetTextExtentPoint32W, use GetTextExtentPoint32A. + (gdk_font_load): Recognize the demibold etc weights, even if we + don't have the corresponding constants in the headers. + (gdk_font_hash_insert): Use same hash mechanism as in the X11 + version. Should save font resources a bit, when we don't have + multiple HFONTs for the same font. + + * gdk/win32/gdkprivate.h: Add the names field as in the X11 + version. + 1999-10-11 ERDI Gergo * gdk/gdk.c (gdk_beep): Modified the XBell call to use the default diff --git a/gdk/win32/gdkdraw.c b/gdk/win32/gdkdraw.c index 34b7a8cba8..8006e1e864 100644 --- a/gdk/win32/gdkdraw.c +++ b/gdk/win32/gdkdraw.c @@ -437,8 +437,6 @@ gdk_draw_string (GdkDrawable *drawable, } /* gdk_draw_text - * - * Modified by Li-Da Lho to draw 16 bits and Multibyte strings * * Interface changed: add "GdkFont *font" to specify font or fontset explicitely */ @@ -507,6 +505,7 @@ gdk_draw_text_wc (GdkDrawable *drawable, GdkGCPrivate *gc_private; gint i; wchar_t *wcstr; + guchar *str; g_return_if_fail (drawable != NULL); g_return_if_fail (font != NULL); @@ -537,12 +536,26 @@ gdk_draw_text_wc (GdkDrawable *drawable, if ((oldfont = SelectObject (hdc, xfont)) == NULL) g_warning ("gdk_draw_text: SelectObject failed"); +#if 0 /* No. Don't use TextOutW. Compare to the X11 version, + * it uses plain XDrawString for GDK_FONT_FONT fonts, too. + * TextOutW by definition interprets the string as Unicode. + * We don't have that, but either chars from some single-byte codepage + * or from a DBCS. + */ wcstr = g_new (wchar_t, text_length); for (i = 0; i < text_length; i++) wcstr[i] = text[i]; if (!TextOutW (hdc, x, y, wcstr, text_length)) g_warning ("gdk_draw_text: TextOutW failed"); g_free (wcstr); +#else + str = g_new (guchar, text_length); + for (i=0; inames = g_slist_prepend (private->names, g_strdup (font_name)); + g_hash_table_insert (*hashp, private->names->data, font); +} + +static void +gdk_font_hash_remove (GdkFontType type, GdkFont *font) +{ + GdkFontPrivate *private = (GdkFontPrivate *)font; + GSList *tmp_list; + GHashTable *hash = (type == GDK_FONT_FONT) ? + font_name_hash : fontset_name_hash; + + tmp_list = private->names; + while (tmp_list) + { + g_hash_table_remove (hash, tmp_list->data); + g_free (tmp_list->data); + + tmp_list = tmp_list->next; + } + + g_slist_free (private->names); + private->names = NULL; +} + +static GdkFont * +gdk_font_hash_lookup (GdkFontType type, const gchar *font_name) +{ + GdkFont *result; + GHashTable *hash = (type == GDK_FONT_FONT) ? + font_name_hash : fontset_name_hash; + + if (!hash) + return NULL; + else + { + result = g_hash_table_lookup (hash, font_name); + if (result) + gdk_font_ref (result); + + return result; + } +} + GdkFont* gdk_font_load (const gchar *font_name) { GdkFont *font; GdkFontPrivate *private; + HFONT hfont; LOGFONT logfont; HGDIOBJ oldfont; TEXTMETRIC textmetric; @@ -56,8 +114,11 @@ gdk_font_load (const gchar *font_name) g_return_val_if_fail (font_name != NULL, NULL); - private = g_new (GdkFontPrivate, 1); - font = (GdkFont*) private; + GDK_NOTE (MISC, g_print ("gdk_font_load: %s\n", font_name)); + + font = gdk_font_hash_lookup (GDK_FONT_FONT, font_name); + if (font) + return font; numfields = sscanf (font_name, "-%30[^-]-%100[^-]-%30[^-]-%30[^-]-%30[^-]-%n", @@ -152,9 +213,13 @@ gdk_font_load (const gchar *font_name) fnWeight = FW_THIN; else if (g_strcasecmp (weight, "extralight") == 0) fnWeight = FW_EXTRALIGHT; -#ifdef FW_ULTRALIGHT else if (g_strcasecmp (weight, "ultralight") == 0) +#ifdef FW_ULTRALIGHT fnWeight = FW_ULTRALIGHT; +#else + fnWeight = FW_EXTRALIGHT; /* In fact, FW_ULTRALIGHT really is + * defined as FW_EXTRALIGHT anyway. + */ #endif else if (g_strcasecmp (weight, "light") == 0) fnWeight = FW_LIGHT; @@ -166,23 +231,29 @@ gdk_font_load (const gchar *font_name) fnWeight = FW_MEDIUM; else if (g_strcasecmp (weight, "semibold") == 0) fnWeight = FW_SEMIBOLD; -#ifdef FW_DEMIBOLD else if (g_strcasecmp (weight, "demibold") == 0) +#ifdef FW_DEMIBOLD fnWeight = FW_DEMIBOLD; +#else + fnWeight = FW_SEMIBOLD; /* As above */ #endif else if (g_strcasecmp (weight, "bold") == 0) fnWeight = FW_BOLD; else if (g_strcasecmp (weight, "extrabold") == 0) fnWeight = FW_EXTRABOLD; -#ifdef FW_ULTRABOLD else if (g_strcasecmp (weight, "ultrabold") == 0) +#ifdef FW_ULTRABOLD fnWeight = FW_ULTRABOLD; +#else + fnWeight = FW_EXTRABOLD; /* As above */ #endif else if (g_strcasecmp (weight, "heavy") == 0) fnWeight = FW_HEAVY; -#ifdef FW_BLACK else if (g_strcasecmp (weight, "black") == 0) +#ifdef FW_BLACK fnWeight = FW_BLACK; +#else + fnWeight = FW_HEAVY; /* As above */ #endif else fnWeight = FW_DONTCARE; @@ -250,12 +321,15 @@ gdk_font_load (const gchar *font_name) for (tries = 0; ; tries++) { - GDK_NOTE (MISC, g_print ("gdk_font_load: trying CreateFont(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%#.02x,\"%s\")\n", + GDK_NOTE (MISC, g_print ("...trying CreateFont(%d,%d,%d,%d," + "%d,%d,%d,%d," + "%d,%d,%d," + "%d,%#.02x,\"%s\")\n", nHeight, nWidth, nEscapement, nOrientation, fnWeight, fdwItalic, fdwUnderline, fdwStrikeOut, fdwCharSet, fdwOutputPrecision, fdwClipPrecision, fdwQuality, fdwPitchAndFamily, lpszFace)); - if ((private->xfont = + if ((hfont = CreateFont (nHeight, nWidth, nEscapement, nOrientation, fnWeight, fdwItalic, fdwUnderline, fdwStrikeOut, fdwCharSet, fdwOutputPrecision, fdwClipPrecision, @@ -308,14 +382,15 @@ gdk_font_load (const gchar *font_name) tries++; } - if (!private->xfont) - { - g_warning ("gdk_font_load: font %s not found", font_name); - g_free (font); - return NULL; - } + if (!hfont) + return NULL; + private = g_new (GdkFontPrivate, 1); + font = (GdkFont*) private; + + private->xfont = hfont; private->ref_count = 1; + private->names = NULL; font->type = GDK_FONT_FONT; GetObject (private->xfont, sizeof (logfont), &logfont); oldfont = SelectObject (gdk_DC, private->xfont); @@ -324,15 +399,16 @@ gdk_font_load (const gchar *font_name) font->ascent = textmetric.tmAscent; font->descent = textmetric.tmDescent; - GDK_NOTE (MISC, g_print ("gdk_font_load: %s = %#x asc %d desc %d\n", - font_name, private->xfont, - font->ascent, font->descent)); + GDK_NOTE (MISC, g_print ("... = %#x asc %d desc %d\n", + private->xfont, font->ascent, font->descent)); /* This memory is leaked, so shoot me. */ f = g_new (HANDLE, 1); *f = (HANDLE) ((guint) private->xfont + HFONT_DITHER); gdk_xid_table_insert (f, font); + gdk_font_hash_insert (GDK_FONT_FONT, font, font_name); + return font; } @@ -340,6 +416,7 @@ GdkFont* gdk_fontset_load (gchar *fontset_name) { g_warning ("gdk_fontset_load: Not implemented"); + return NULL; } @@ -359,14 +436,16 @@ void gdk_font_unref (GdkFont *font) { GdkFontPrivate *private; + private = (GdkFontPrivate*) font; g_return_if_fail (font != NULL); - - private = (GdkFontPrivate*) font; + g_return_if_fail (private->ref_count > 0); private->ref_count -= 1; if (private->ref_count == 0) { + gdk_font_hash_remove (font->type, font); + switch (font->type) { case GDK_FONT_FONT: @@ -465,6 +544,7 @@ gdk_text_width_wc (GdkFont *font, HGDIOBJ oldfont; SIZE size; wchar_t *wcstr; + guchar *str; gint i, width; g_return_val_if_fail (font != NULL, -1); @@ -475,12 +555,22 @@ gdk_text_width_wc (GdkFont *font, switch (font->type) { case GDK_FONT_FONT: + oldfont = SelectObject (gdk_DC, private->xfont); +#if 0 /* No. Don't assume Unicode here either. + * (Read the comments in gdk_draw_text_wc.) + */ wcstr = g_new (wchar_t, text_length); for (i = 0; i < text_length; i++) wcstr[i] = text[i]; - oldfont = SelectObject (gdk_DC, private->xfont); GetTextExtentPoint32W (gdk_DC, wcstr, text_length, &size); g_free (wcstr); +#else + str = g_new (guchar, text_length); + for (i=0; inames = g_slist_prepend (private->names, g_strdup (font_name)); + g_hash_table_insert (*hashp, private->names->data, font); +} + +static void +gdk_font_hash_remove (GdkFontType type, GdkFont *font) +{ + GdkFontPrivate *private = (GdkFontPrivate *)font; + GSList *tmp_list; + GHashTable *hash = (type == GDK_FONT_FONT) ? + font_name_hash : fontset_name_hash; + + tmp_list = private->names; + while (tmp_list) + { + g_hash_table_remove (hash, tmp_list->data); + g_free (tmp_list->data); + + tmp_list = tmp_list->next; + } + + g_slist_free (private->names); + private->names = NULL; +} + +static GdkFont * +gdk_font_hash_lookup (GdkFontType type, const gchar *font_name) +{ + GdkFont *result; + GHashTable *hash = (type == GDK_FONT_FONT) ? + font_name_hash : fontset_name_hash; + + if (!hash) + return NULL; + else + { + result = g_hash_table_lookup (hash, font_name); + if (result) + gdk_font_ref (result); + + return result; + } +} + GdkFont* gdk_font_load (const gchar *font_name) { GdkFont *font; GdkFontPrivate *private; + HFONT hfont; LOGFONT logfont; HGDIOBJ oldfont; TEXTMETRIC textmetric; @@ -56,8 +114,11 @@ gdk_font_load (const gchar *font_name) g_return_val_if_fail (font_name != NULL, NULL); - private = g_new (GdkFontPrivate, 1); - font = (GdkFont*) private; + GDK_NOTE (MISC, g_print ("gdk_font_load: %s\n", font_name)); + + font = gdk_font_hash_lookup (GDK_FONT_FONT, font_name); + if (font) + return font; numfields = sscanf (font_name, "-%30[^-]-%100[^-]-%30[^-]-%30[^-]-%30[^-]-%n", @@ -152,9 +213,13 @@ gdk_font_load (const gchar *font_name) fnWeight = FW_THIN; else if (g_strcasecmp (weight, "extralight") == 0) fnWeight = FW_EXTRALIGHT; -#ifdef FW_ULTRALIGHT else if (g_strcasecmp (weight, "ultralight") == 0) +#ifdef FW_ULTRALIGHT fnWeight = FW_ULTRALIGHT; +#else + fnWeight = FW_EXTRALIGHT; /* In fact, FW_ULTRALIGHT really is + * defined as FW_EXTRALIGHT anyway. + */ #endif else if (g_strcasecmp (weight, "light") == 0) fnWeight = FW_LIGHT; @@ -166,23 +231,29 @@ gdk_font_load (const gchar *font_name) fnWeight = FW_MEDIUM; else if (g_strcasecmp (weight, "semibold") == 0) fnWeight = FW_SEMIBOLD; -#ifdef FW_DEMIBOLD else if (g_strcasecmp (weight, "demibold") == 0) +#ifdef FW_DEMIBOLD fnWeight = FW_DEMIBOLD; +#else + fnWeight = FW_SEMIBOLD; /* As above */ #endif else if (g_strcasecmp (weight, "bold") == 0) fnWeight = FW_BOLD; else if (g_strcasecmp (weight, "extrabold") == 0) fnWeight = FW_EXTRABOLD; -#ifdef FW_ULTRABOLD else if (g_strcasecmp (weight, "ultrabold") == 0) +#ifdef FW_ULTRABOLD fnWeight = FW_ULTRABOLD; +#else + fnWeight = FW_EXTRABOLD; /* As above */ #endif else if (g_strcasecmp (weight, "heavy") == 0) fnWeight = FW_HEAVY; -#ifdef FW_BLACK else if (g_strcasecmp (weight, "black") == 0) +#ifdef FW_BLACK fnWeight = FW_BLACK; +#else + fnWeight = FW_HEAVY; /* As above */ #endif else fnWeight = FW_DONTCARE; @@ -250,12 +321,15 @@ gdk_font_load (const gchar *font_name) for (tries = 0; ; tries++) { - GDK_NOTE (MISC, g_print ("gdk_font_load: trying CreateFont(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%#.02x,\"%s\")\n", + GDK_NOTE (MISC, g_print ("...trying CreateFont(%d,%d,%d,%d," + "%d,%d,%d,%d," + "%d,%d,%d," + "%d,%#.02x,\"%s\")\n", nHeight, nWidth, nEscapement, nOrientation, fnWeight, fdwItalic, fdwUnderline, fdwStrikeOut, fdwCharSet, fdwOutputPrecision, fdwClipPrecision, fdwQuality, fdwPitchAndFamily, lpszFace)); - if ((private->xfont = + if ((hfont = CreateFont (nHeight, nWidth, nEscapement, nOrientation, fnWeight, fdwItalic, fdwUnderline, fdwStrikeOut, fdwCharSet, fdwOutputPrecision, fdwClipPrecision, @@ -308,14 +382,15 @@ gdk_font_load (const gchar *font_name) tries++; } - if (!private->xfont) - { - g_warning ("gdk_font_load: font %s not found", font_name); - g_free (font); - return NULL; - } + if (!hfont) + return NULL; + private = g_new (GdkFontPrivate, 1); + font = (GdkFont*) private; + + private->xfont = hfont; private->ref_count = 1; + private->names = NULL; font->type = GDK_FONT_FONT; GetObject (private->xfont, sizeof (logfont), &logfont); oldfont = SelectObject (gdk_DC, private->xfont); @@ -324,15 +399,16 @@ gdk_font_load (const gchar *font_name) font->ascent = textmetric.tmAscent; font->descent = textmetric.tmDescent; - GDK_NOTE (MISC, g_print ("gdk_font_load: %s = %#x asc %d desc %d\n", - font_name, private->xfont, - font->ascent, font->descent)); + GDK_NOTE (MISC, g_print ("... = %#x asc %d desc %d\n", + private->xfont, font->ascent, font->descent)); /* This memory is leaked, so shoot me. */ f = g_new (HANDLE, 1); *f = (HANDLE) ((guint) private->xfont + HFONT_DITHER); gdk_xid_table_insert (f, font); + gdk_font_hash_insert (GDK_FONT_FONT, font, font_name); + return font; } @@ -340,6 +416,7 @@ GdkFont* gdk_fontset_load (gchar *fontset_name) { g_warning ("gdk_fontset_load: Not implemented"); + return NULL; } @@ -359,14 +436,16 @@ void gdk_font_unref (GdkFont *font) { GdkFontPrivate *private; + private = (GdkFontPrivate*) font; g_return_if_fail (font != NULL); - - private = (GdkFontPrivate*) font; + g_return_if_fail (private->ref_count > 0); private->ref_count -= 1; if (private->ref_count == 0) { + gdk_font_hash_remove (font->type, font); + switch (font->type) { case GDK_FONT_FONT: @@ -465,6 +544,7 @@ gdk_text_width_wc (GdkFont *font, HGDIOBJ oldfont; SIZE size; wchar_t *wcstr; + guchar *str; gint i, width; g_return_val_if_fail (font != NULL, -1); @@ -475,12 +555,22 @@ gdk_text_width_wc (GdkFont *font, switch (font->type) { case GDK_FONT_FONT: + oldfont = SelectObject (gdk_DC, private->xfont); +#if 0 /* No. Don't assume Unicode here either. + * (Read the comments in gdk_draw_text_wc.) + */ wcstr = g_new (wchar_t, text_length); for (i = 0; i < text_length; i++) wcstr[i] = text[i]; - oldfont = SelectObject (gdk_DC, private->xfont); GetTextExtentPoint32W (gdk_DC, wcstr, text_length, &size); g_free (wcstr); +#else + str = g_new (guchar, text_length); + for (i=0; i$@ + # # Test programs: #