Re: Font name inside GdkFont



Darin Adler <darin bentspoon com> writes:

> Nautilus and Eel currently rely on getting the name of a GdkFont, using the
> GdkFontPrivateX structure. This is the basis of the functions in
> eel-gdk-font-extensions.[ch]. With the recent changes to the gdk library,
> GdkFontPrivateX is now so private that Eel can't get at it.
> 
> For the first stage of the gnome 2 port, I was hoping to keep the functions
> that depend on this working. I assume that in a later stage I will be able
> to convert everything to use Pango and not use the deprecated GdkFont at
> all. But I'm a little worried about what to do in the mean time.
> 
> Your thoughts?

One possibility would be to add something like
the following patch. The other possibility would be to the
technique gal uses .. extract the XFontStruct or XFontSet
using gdk_x11_font_get_xfont() then use Xlib to turn that
into a name.

I haven't really experimented with the gal approach myself,
but I think it should work. On the other hand, providing
an accessor is certainly simpler.

Regards,
                                        Owen
Index: x11/gdkfont-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkfont-x11.c,v
retrieving revision 1.27
diff -u -r1.27 gdkfont-x11.c
--- x11/gdkfont-x11.c	2001/09/07 21:50:09	1.27
+++ x11/gdkfont-x11.c	2001/09/08 01:35:26
@@ -678,3 +678,27 @@
   return ((GdkFontPrivateX *)font)->xfont;
 }
 
+/**
+ * gdk_x11_font_get_name:
+ * @font: a #GdkFont.
+ * 
+ * Return the X Logical Font Description (for font->type == GDK_FONT_FONT)
+ * or comma separated list of XLFDs (for font->type == GDK_FONT_FONTSET)
+ * that was used to load the font. If the same font was loaded
+ * via multiple names, which name is returned is undefined.
+ * 
+ * Return value: the name of the font. This string is owned
+ *   by GDK and must not be modified or freed.
+ **/
+G_CONST_RETURN char *
+gdk_x11_font_get_name (GdkFont *font)
+{
+  GdkFontPrivateX *private = (GdkFontPrivateX *)font;
+
+  g_return_val_if_fail (font != NULL, NULL);
+
+  g_assert (private->names);
+
+  return private->names->data;
+}
+     
Index: x11/gdkx.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkx.h,v
retrieving revision 1.22
diff -u -r1.22 gdkx.h
--- x11/gdkx.h	2001/09/07 21:50:09	1.22
+++ x11/gdkx.h	2001/09/08 01:35:26
@@ -124,8 +124,9 @@
 
 #ifndef GDK_DISABLE_DEPRECATED
 
-Display *gdk_x11_font_get_xdisplay      (GdkFont     *font);
-gpointer gdk_x11_font_get_xfont         (GdkFont     *font);
+Display *            gdk_x11_font_get_xdisplay (GdkFont *font);
+gpointer             gdk_x11_font_get_xfont    (GdkFont *font);
+G_CONST_RETURN char *gdk_x11_font_get_name     (GdkFont *font);
 
 #define GDK_FONT_XDISPLAY(font)       (gdk_x11_font_get_xdisplay (font))
 #define GDK_FONT_XFONT(font)          (gdk_x11_font_get_xfont (font))




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