From: Jim Evins Date: Fri, 24 Oct 2008 03:30:36 +0000 (+0000) Subject: 2008-10-23 Jim Evins X-Git-Tag: glabels-2_3_0~253 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c9e2de5f7326b9bd172268da0584d6c6e31a7e03;p=glabels 2008-10-23 Jim Evins * src/label-text.c: (set_font_family): * src/object-editor-text-page.c: (gl_object_editor_prepare_text_page), (gl_object_editor_set_font_family): * src/prefs-dialog.c: (construct_object_page), (update_object_page_from_prefs): * src/ui-property-bar.c: (gl_ui_property_bar_construct), (reset_to_default_properties): * src/util.c: (gl_util_get_font_family_list): * src/util.h: Bug #1902275 and Bug #2186214. Cache font list so that it is not re-created everytime the list is requested. * src/object-editor-text-page.c: (gl_object_editor_set_font_family): Don't change font-family if it hasn't actually changed. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@788 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 69519f68..5a7943bf 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,21 @@ +2008-10-23 Jim Evins + + * src/label-text.c: (set_font_family): + * src/object-editor-text-page.c: + (gl_object_editor_prepare_text_page), + (gl_object_editor_set_font_family): + * src/prefs-dialog.c: (construct_object_page), + (update_object_page_from_prefs): + * src/ui-property-bar.c: (gl_ui_property_bar_construct), + (reset_to_default_properties): + * src/util.c: (gl_util_get_font_family_list): + * src/util.h: + Bug #1902275 and Bug #2186214. Cache font list so that it is not re-created + everytime the list is requested. + * src/object-editor-text-page.c: + (gl_object_editor_set_font_family): + Don't change font-family if it hasn't actually changed. + 2008-10-19 Jim Evins * data/builder/object-editor.glade: diff --git a/glabels2/src/label-text.c b/glabels2/src/label-text.c index 6139d5e7..9a4d59a1 100644 --- a/glabels2/src/label-text.c +++ b/glabels2/src/label-text.c @@ -450,7 +450,6 @@ set_font_family (glLabelObject *object, good_font_family = g_strdup (font_family); } } - gl_util_font_family_list_free (family_names); if (ltext->priv->font_family) { if (g_strcasecmp (ltext->priv->font_family, good_font_family) == 0) { diff --git a/glabels2/src/object-editor-text-page.c b/glabels2/src/object-editor-text-page.c index 79f13051..57b37dae 100644 --- a/glabels2/src/object-editor-text-page.c +++ b/glabels2/src/object-editor-text-page.c @@ -103,7 +103,6 @@ gl_object_editor_prepare_text_page (glObjectEditor *editor) family_names = gl_util_get_font_family_list (); gl_util_combo_box_set_strings (GTK_COMBO_BOX(editor->priv->text_family_combo), family_names); - gl_util_font_family_list_free (family_names); /* Modify widgets */ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio), TRUE); @@ -223,26 +222,34 @@ gl_object_editor_set_font_family (glObjectEditor *editor, const gchar *font_family) { GList *family_names; + gchar *old_font_family; gchar *good_font_family; gl_debug (DEBUG_EDITOR, "START"); editor->priv->stop_signals = TRUE; - /* Make sure we have a valid font family. if not provide a good default. */ - family_names = gl_util_get_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 */ + old_font_family = gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->text_family_combo)); + + if ( !old_font_family || g_utf8_collate( old_font_family, font_family ) ) + { + + /* Make sure we have a valid font family. if not provide a good default. */ + family_names = gl_util_get_font_family_list (); + if (g_list_find_custom (family_names, font_family, (GCompareFunc)g_utf8_collate)) { + good_font_family = g_strdup (font_family); } else { - good_font_family = NULL; + if (family_names != NULL) { + good_font_family = g_strdup (family_names->data); /* 1st entry */ + } else { + good_font_family = NULL; + } } + gl_util_combo_box_set_active_text (GTK_COMBO_BOX (editor->priv->text_family_combo), good_font_family); + g_free (good_font_family); } - gl_util_font_family_list_free (family_names); - gl_util_combo_box_set_active_text (GTK_COMBO_BOX (editor->priv->text_family_combo), good_font_family); - g_free (good_font_family); + + g_free (old_font_family); editor->priv->stop_signals = FALSE; diff --git a/glabels2/src/prefs-dialog.c b/glabels2/src/prefs-dialog.c index a578e9ff..e5f79d3d 100644 --- a/glabels2/src/prefs-dialog.c +++ b/glabels2/src/prefs-dialog.c @@ -346,7 +346,6 @@ construct_object_page (glPrefsDialog *dialog) family_names = gl_util_get_font_family_list (); gl_util_combo_box_set_strings (GTK_COMBO_BOX (dialog->priv->text_family_combo), family_names); - gl_util_font_family_list_free (family_names); g_signal_connect_swapped (G_OBJECT(dialog->priv->text_family_combo), @@ -526,7 +525,6 @@ update_object_page_from_prefs (glPrefsDialog *dialog) good_font_family = NULL; } } - gl_util_font_family_list_free (family_names); gl_util_combo_box_set_active_text (GTK_COMBO_BOX (dialog->priv->text_family_combo), good_font_family); g_free (good_font_family); diff --git a/glabels2/src/ui-property-bar.c b/glabels2/src/ui-property-bar.c index 98d23305..2cfca42f 100644 --- a/glabels2/src/ui-property-bar.c +++ b/glabels2/src/ui-property-bar.c @@ -336,7 +336,6 @@ gl_ui_property_bar_construct (glUIPropertyBar *this) { gtk_combo_box_set_active (GTK_COMBO_BOX (this->priv->font_family_combo), 0); } - gl_util_font_family_list_free (family_names); g_signal_connect (G_OBJECT (this->priv->font_family_combo), "changed", G_CALLBACK (font_family_changed_cb), this); @@ -435,7 +434,6 @@ reset_to_default_properties (glView *view, gl_util_combo_box_set_active_text (GTK_COMBO_BOX (this->priv->font_family_combo), good_font_family); g_free (good_font_family); - gl_util_font_family_list_free (family_names); gtk_spin_button_set_value (GTK_SPIN_BUTTON(this->priv->font_size_spin), view->default_font_size); diff --git a/glabels2/src/util.c b/glabels2/src/util.c index 161f2bfc..92e31107 100644 --- a/glabels2/src/util.c +++ b/glabels2/src/util.c @@ -306,13 +306,14 @@ gl_util_combo_box_add_text_model (GtkComboBox *combo) } + /****************************************************************************/ /* Get list of available font families. */ /****************************************************************************/ GList * gl_util_get_font_family_list (void) { - GList *list = NULL; + static GList *list = NULL; PangoFontMap *fontmap; PangoContext *context; PangoFontFamily **families; @@ -320,39 +321,27 @@ gl_util_get_font_family_list (void) gint i; gchar *name; - fontmap = pango_cairo_font_map_new (); - context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fontmap)); - - pango_context_list_families (context, &families, &n); - - for ( i=0; inext) { - g_free (p->data); - p->data = NULL; + g_object_unref (context); + g_object_unref (fontmap); } - g_list_free (list); + return list; } diff --git a/glabels2/src/util.h b/glabels2/src/util.h index 267b0ef2..5629cbac 100644 --- a/glabels2/src/util.h +++ b/glabels2/src/util.h @@ -52,7 +52,6 @@ void gl_util_combo_box_set_active_text (GtkComboBox *combo, void gl_util_combo_box_add_text_model (GtkComboBox *combo); GList *gl_util_get_font_family_list (void); -void gl_util_font_family_list_free (GList *list); GdkPixbuf *gl_util_cairo_convert_to_pixbuf (cairo_surface_t *surface);