]> Pileus Git - ~andy/gtk/commitdiff
Don't use TextOutW for GDK_FONT_FONT fonts (which is all we have for now,
authorTor Lillqvist <tml@iki.fi>
Wed, 13 Oct 1999 21:46:33 +0000 (21:46 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Wed, 13 Oct 1999 21:46:33 +0000 (21:46 +0000)
1999-10-14  Tor Lillqvist  <tml@iki.fi>

* 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.

16 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gdk/win32/gdkdraw.c
gdk/win32/gdkdrawable-win32.c
gdk/win32/gdkevents-win32.c
gdk/win32/gdkevents.c
gdk/win32/gdkfont-win32.c
gdk/win32/gdkfont.c
gdk/win32/gdkprivate-win32.h
gdk/win32/gdkprivate.h
gtk/makefile.cygwin

index 66459eec63c9e5b6a3fc99652efe7d03b44f5b0b..da734fab2df69497d3b5b18cd060546cebdb2200 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+1999-10-14  Tor Lillqvist  <tml@iki.fi>
+
+       * 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  <cactus@cactus.rulez.org>
 
        * gdk/gdk.c (gdk_beep): Modified the XBell call to use the default
index 66459eec63c9e5b6a3fc99652efe7d03b44f5b0b..da734fab2df69497d3b5b18cd060546cebdb2200 100644 (file)
@@ -1,3 +1,27 @@
+1999-10-14  Tor Lillqvist  <tml@iki.fi>
+
+       * 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  <cactus@cactus.rulez.org>
 
        * gdk/gdk.c (gdk_beep): Modified the XBell call to use the default
index 66459eec63c9e5b6a3fc99652efe7d03b44f5b0b..da734fab2df69497d3b5b18cd060546cebdb2200 100644 (file)
@@ -1,3 +1,27 @@
+1999-10-14  Tor Lillqvist  <tml@iki.fi>
+
+       * 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  <cactus@cactus.rulez.org>
 
        * gdk/gdk.c (gdk_beep): Modified the XBell call to use the default
index 66459eec63c9e5b6a3fc99652efe7d03b44f5b0b..da734fab2df69497d3b5b18cd060546cebdb2200 100644 (file)
@@ -1,3 +1,27 @@
+1999-10-14  Tor Lillqvist  <tml@iki.fi>
+
+       * 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  <cactus@cactus.rulez.org>
 
        * gdk/gdk.c (gdk_beep): Modified the XBell call to use the default
index 66459eec63c9e5b6a3fc99652efe7d03b44f5b0b..da734fab2df69497d3b5b18cd060546cebdb2200 100644 (file)
@@ -1,3 +1,27 @@
+1999-10-14  Tor Lillqvist  <tml@iki.fi>
+
+       * 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  <cactus@cactus.rulez.org>
 
        * gdk/gdk.c (gdk_beep): Modified the XBell call to use the default
index 66459eec63c9e5b6a3fc99652efe7d03b44f5b0b..da734fab2df69497d3b5b18cd060546cebdb2200 100644 (file)
@@ -1,3 +1,27 @@
+1999-10-14  Tor Lillqvist  <tml@iki.fi>
+
+       * 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  <cactus@cactus.rulez.org>
 
        * gdk/gdk.c (gdk_beep): Modified the XBell call to use the default
index 66459eec63c9e5b6a3fc99652efe7d03b44f5b0b..da734fab2df69497d3b5b18cd060546cebdb2200 100644 (file)
@@ -1,3 +1,27 @@
+1999-10-14  Tor Lillqvist  <tml@iki.fi>
+
+       * 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  <cactus@cactus.rulez.org>
 
        * gdk/gdk.c (gdk_beep): Modified the XBell call to use the default
index 34b7a8cba84c6249b9817a0fb2020bcdc426a770..8006e1e864f79986262ce28a6cc116d0ff414586 100644 (file)
@@ -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; i<text_length; i++)
+       str[i] = text[i];
+      if (!TextOutA (hdc, x, y, str, text_length))
+       g_warning ("gdk_draw_text: TextOutA failed");
+      g_free (str);
+#endif
       SelectObject (hdc, oldfont);
       gdk_gc_postdraw (drawable_private, gc_private);
     }
index 34b7a8cba84c6249b9817a0fb2020bcdc426a770..8006e1e864f79986262ce28a6cc116d0ff414586 100644 (file)
@@ -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; i<text_length; i++)
+       str[i] = text[i];
+      if (!TextOutA (hdc, x, y, str, text_length))
+       g_warning ("gdk_draw_text: TextOutA failed");
+      g_free (str);
+#endif
       SelectObject (hdc, oldfont);
       gdk_gc_postdraw (drawable_private, gc_private);
     }
index 653e62ba7963aa6006c3cda786d92527f7869120..53097d20b741efe05fb6f4b06489106ceb04ebb6 100644 (file)
@@ -2898,7 +2898,8 @@ gdk_events_queue (void)
   while (!gdk_event_queue_find_first()
         && PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
     {
-      GDK_NOTE (EVENTS, g_print ("gdk_events_queue: got event\n"));
+      GDK_NOTE (EVENTS, g_print ("gdk_events_queue:  PeekMessage: %#x\n",
+                                msg.message));
       TranslateMessage (&msg);
 
       event = gdk_event_new ();
index 653e62ba7963aa6006c3cda786d92527f7869120..53097d20b741efe05fb6f4b06489106ceb04ebb6 100644 (file)
@@ -2898,7 +2898,8 @@ gdk_events_queue (void)
   while (!gdk_event_queue_find_first()
         && PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
     {
-      GDK_NOTE (EVENTS, g_print ("gdk_events_queue: got event\n"));
+      GDK_NOTE (EVENTS, g_print ("gdk_events_queue:  PeekMessage: %#x\n",
+                                msg.message));
       TranslateMessage (&msg);
 
       event = gdk_event_new ();
index 77aa8c703a02b4e86d8d0153de66b9757aa6febe..9c2649eded73c3232077191301002501bd33fc20 100644 (file)
 #include "gdkfont.h"
 #include "gdkprivate.h"
 
+static GHashTable *font_name_hash = NULL;
+static GHashTable *fontset_name_hash = NULL;
+
+static void
+gdk_font_hash_insert (GdkFontType type, GdkFont *font, const gchar *font_name)
+{
+  GdkFontPrivate *private = (GdkFontPrivate *)font;
+  GHashTable **hashp = (type == GDK_FONT_FONT) ?
+    &font_name_hash : &fontset_name_hash;
+
+  if (!*hashp)
+    *hashp = g_hash_table_new (g_str_hash, g_str_equal);
+
+  private->names = 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<text_length; i++)
+       str[i] = text[i];
+      GetTextExtentPoint32A (gdk_DC, str, text_length, &size);
+      g_free (str);
+#endif
       SelectObject (gdk_DC, oldfont);
       width = size.cx;
       break;
@@ -654,8 +744,6 @@ gint
 gdk_char_measure (GdkFont *font,
                   gchar    character)
 {
-  g_return_val_if_fail (font != NULL, -1);
-
   return gdk_text_measure (font, &character, 1);
 }
 
@@ -703,7 +791,5 @@ gint
 gdk_char_height (GdkFont *font,
                 gchar    character)
 {
-  g_return_val_if_fail (font != NULL, -1);
-
   return gdk_text_height (font, &character, 1);
 }
index 77aa8c703a02b4e86d8d0153de66b9757aa6febe..9c2649eded73c3232077191301002501bd33fc20 100644 (file)
 #include "gdkfont.h"
 #include "gdkprivate.h"
 
+static GHashTable *font_name_hash = NULL;
+static GHashTable *fontset_name_hash = NULL;
+
+static void
+gdk_font_hash_insert (GdkFontType type, GdkFont *font, const gchar *font_name)
+{
+  GdkFontPrivate *private = (GdkFontPrivate *)font;
+  GHashTable **hashp = (type == GDK_FONT_FONT) ?
+    &font_name_hash : &fontset_name_hash;
+
+  if (!*hashp)
+    *hashp = g_hash_table_new (g_str_hash, g_str_equal);
+
+  private->names = 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<text_length; i++)
+       str[i] = text[i];
+      GetTextExtentPoint32A (gdk_DC, str, text_length, &size);
+      g_free (str);
+#endif
       SelectObject (gdk_DC, oldfont);
       width = size.cx;
       break;
@@ -654,8 +744,6 @@ gint
 gdk_char_measure (GdkFont *font,
                   gchar    character)
 {
-  g_return_val_if_fail (font != NULL, -1);
-
   return gdk_text_measure (font, &character, 1);
 }
 
@@ -703,7 +791,5 @@ gint
 gdk_char_height (GdkFont *font,
                 gchar    character)
 {
-  g_return_val_if_fail (font != NULL, -1);
-
   return gdk_text_height (font, &character, 1);
 }
index a35bd703b0b80b9a4e24314139b1d11c3e56ccf8..5df4fe73587254e0d8789006b723747a38c64ee3 100644 (file)
@@ -296,11 +296,10 @@ struct _GdkVisualPrivate
 struct _GdkFontPrivate
 {
   GdkFont font;
-  /* XFontStruct *xfont; */
-  /* generic pointer point to XFontStruct or XFontSet */
-  /* in Win32 a HFONT */ 
-  gpointer xfont;
+  HFONT xfont;
   guint ref_count;
+
+  GSList *names;
 };
 
 struct _GdkCursorPrivate
index a35bd703b0b80b9a4e24314139b1d11c3e56ccf8..5df4fe73587254e0d8789006b723747a38c64ee3 100644 (file)
@@ -296,11 +296,10 @@ struct _GdkVisualPrivate
 struct _GdkFontPrivate
 {
   GdkFont font;
-  /* XFontStruct *xfont; */
-  /* generic pointer point to XFontStruct or XFontSet */
-  /* in Win32 a HFONT */ 
-  gpointer xfont;
+  HFONT xfont;
   guint ref_count;
+
+  GSList *names;
 };
 
 struct _GdkCursorPrivate
index de6092a7626cde8c510c82caf101a88a0cba74f4..cbfa12b40e6f61e03b4b0da85c3ef7224569eef0 100644 (file)
@@ -339,10 +339,15 @@ gtkmarshal.h gtkmarshal.c : gtkmarshal.list genmarshal.pl
 gtk-$(GTK_VER).dll : generated $(gtk_OBJECTS) gtk.def
        $(GLIB)/build-dll gtk $(GTK_VER) gtk.def $(gtk_OBJECTS) -L $(GDKSYSDEP) -lgdk-$(GTK_VER) -L$(INTL) -lgnu-intl -L $(GLIB) -lglib-$(GLIB_VER) -lgmodule-$(GLIB_VER) -lgdi32 -luser32
 
+.SUFFIXES: .c .o .i
+
 # General rule for compiling the objects into the DLL
 .c.o :
        $(CC) $(CFLAGS) -c -DGTK_COMPILATION -DG_LOG_DOMAIN=\"Gtk\" $<
 
+.c.i :
+       $(CC) $(CFLAGS) -E -DGDK_COMPILATION -DG_LOG_DOMAIN=\"Gdk\" $< >$@
+
 #
 # Test programs:
 #