Re: Problem with GTK fonts



Victor Vicente Mateos wrote:

Hi!

I've got a problem with fonts in GTK. I've made a simple example which consist on a main window with a label. With a button press in the main window, a GtkFontSelectionDialog appears to select a font to apply to the label. I think I do the process correctly, but when I change sometimes the font, a violation-segment occurs and the following error message: GLib-CRITICAL **: file gcache.c: line 160 (g_cache_remove) : assertion `node != NULL` failed

This question should probably have been sent to gtk-app-devel-list instead. This list is for discussion of development _of_ gtk, rather than _with_ gtk. My comments are below.

static gint accept_cb (GtkWidget *widget, gpointer data)
{
 GtkFontSelectionDialog *dlg;
 GtkStyle *style;

 dlg = GTK_FONT_SELECTION_DIALOG (data);

 style = gtk_style_copy (gtk_widget_get_style (GTK_WIDGET (data)));
 style->font = gtk_font_selection_dialog_get_font (dlg);

This bit should be:
 gdk_font_unref(style->font);
 style->font = gdk_font_ref(gtk_font_selection_dialog_get_font(dlg));

Note that use of GdkFont objects is deprecated now, so a better way to achieve this is to replace the style modification code with:
 font_name = gtk_font_selection_dialog_get_font_name(dlg);
 font_desc = pango_font_description_from_string(font_name);
 gtk_widget_modify_font(GTK_WIDGET(label), font_desc);
 pango_font_description_free(font_desc);
 g_free(font_name);


James.

--
Email: james daa com au              | Linux.conf.au 2003 Call for Papers out
WWW:   http://www.daa.com.au/~james/ |   http://conf.linux.org.au/cfp.html







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