[PATCH] to gdk_load_font()



Hi,

on AIX when I do two identical XLoadQueryFont():

	XFontStruct	*f1, *f2;
	f1 = XLoadQueryFont (display, "fixed");
	f2 = XLoadQueryFont (display, "fixed");

I get f1 == f2, and hence f1->fid == f2->fid.
As a consequence, with gdk_font_load() I have two GdkFont*, but only one 
entry in the XID-Hashtable. This means, if I do a gdk_font_unref(f1) and
then try a gdk_font_lookup(gdk_font_id(f2)), I receive a NULL-pointer.
Here is a short testprogram:

--testfont.c--8<--cut here---------
#include	<assert.h>
#include	<gdk/gdk.h>
#include	<gdk/gdkprivate.h>

int	main (int argc, char **argv)
{
	GdkFont	*f1, *f2, *f3;

	gdk_init (&argc, &argv);

	f1 = gdk_font_load ("fixed");
	f2 = gdk_font_load ("fixed");
	gdk_font_unref (f1);

	f3 = gdk_font_lookup (gdk_font_id (f2));
	assert (f3 != NULL);

	return 0;
}
--cut here-->8-----------

And here is my proposed patch:

diff -u gdkfont.c.orig gdkfont.c gives:

--8<--cut here------------
--- gdkfont.c.orig	Sun Mar  7 12:38:23 1999
+++ gdkfont.c	Sun Mar  7 19:50:23 1999
@@ -34,27 +34,35 @@
 {
   GdkFont *font;
   GdkFontPrivate *private;
+  XFontStruct *xfont;
 
-  private = g_new (GdkFontPrivate, 1);
-  font = (GdkFont*) private;
+  xfont = XLoadQueryFont (gdk_display, font_name);
+  if (xfont == NULL)
+    return NULL;
 
-  private->xdisplay = gdk_display;
-  private->xfont = XLoadQueryFont (private->xdisplay, font_name);
-  private->ref_count = 1;
-
-  if (!private->xfont)
+  font = gdk_font_lookup (xfont->fid);
+  if (font != NULL)
     {
-      g_free (font);
-      return NULL;
+      private = (GdkFontPrivate *) font;
+      if (xfont != private->xfont)
+	XFreeFont (gdk_display, xfont);
+
+      gdk_font_ref (font);
     }
   else
     {
+      private = g_new (GdkFontPrivate, 1);
+      private->xdisplay = gdk_display;
+      private->xfont = xfont;
+      private->ref_count = 1;
+
+      font = (GdkFont*) private;
       font->type = GDK_FONT_FONT;
-      font->ascent =  ((XFontStruct *) private->xfont)->ascent;
-      font->descent = ((XFontStruct *) private->xfont)->descent;
-    }
+      font->ascent =  xfont->ascent;
+      font->descent = xfont->descent;
 
-  gdk_xid_table_insert (&((XFontStruct *) private->xfont)->fid, font);
+      gdk_xid_table_insert (&xfont->fid, font);
+    }
 
   return font;
 }
--cut here-->8---------

Regards, Olaf.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]