From 21c78e4b481abe340cfcb6af32c1ef1ba0ac223a Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Wed, 25 Dec 2002 03:02:00 +0000 Subject: [PATCH] Adds test to ensure a valid font family. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@219 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/src/label-text.c | 18 ++++++++++++++++-- glabels2/src/wdgt-text-props.c | 19 ++++++++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/glabels2/src/label-text.c b/glabels2/src/label-text.c index 37d010ed..240507d2 100644 --- a/glabels2/src/label-text.c +++ b/glabels2/src/label-text.c @@ -231,15 +231,29 @@ gl_label_text_set_props (glLabelText *ltext, guint color, GtkJustification just) { - GdkPixbuf *pixbuf; + GList *family_names; + gchar *good_font_family; gl_debug (DEBUG_LABEL, "START"); g_return_if_fail (ltext && GL_IS_LABEL_TEXT (ltext)); + /* Make sure we have a valid font family. if not privide a good default. */ + family_names = gnome_font_family_list (); + if (g_list_find_custom (family_names, font_family, (GCompareFunc)g_utf8_collate)) { + good_font_family = g_strdup (font_family); + } else { + if (family_names != NULL) { + good_font_family = g_strdup (family_names->data); /* 1st entry */ + } else { + good_font_family = NULL; + } + } + gnome_font_family_list_free (family_names); + g_free (ltext->private->font_family); - ltext->private->font_family = g_strdup (font_family); + ltext->private->font_family = good_font_family; ltext->private->font_size = font_size; ltext->private->font_weight = font_weight; ltext->private->font_italic_flag = font_italic_flag; diff --git a/glabels2/src/wdgt-text-props.c b/glabels2/src/wdgt-text-props.c index 94704585..7a727404 100644 --- a/glabels2/src/wdgt-text-props.c +++ b/glabels2/src/wdgt-text-props.c @@ -409,7 +409,24 @@ gl_wdgt_text_props_set_params (glWdgtTextProps *text, guint color, GtkJustification just) { - gtk_entry_set_text (GTK_ENTRY (text->font_family_entry), font_family); + GList *family_names; + gchar *good_font_family; + + /* Make sure we have a valid font family. if not privide a good default. */ + family_names = gnome_font_family_list (); + if (g_list_find_custom (family_names, font_family, (GCompareFunc)g_utf8_collate)) { + good_font_family = g_strdup (font_family); + } else { + if (family_names != NULL) { + good_font_family = g_strdup (family_names->data); /* 1st entry */ + } else { + good_font_family = NULL; + } + } + gnome_font_family_list_free (family_names); + + gtk_entry_set_text (GTK_ENTRY (text->font_family_entry), good_font_family); + g_free (good_font_family); gtk_spin_button_set_value (GTK_SPIN_BUTTON (text->font_size_spin), font_size); -- 2.39.5