From f3330ba8ef8348e17bcbb5f236507b94b92fb504 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Fri, 24 Oct 2008 03:17:46 +0000 Subject: [PATCH] 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/branches/glabels-2_2@787 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/ChangeLog | 17 ++++++++++ glabels2/src/label-text.c | 1 - glabels2/src/object-editor-text-page.c | 31 ++++++++++------- glabels2/src/prefs-dialog.c | 2 -- glabels2/src/ui-property-bar.c | 2 -- glabels2/src/util.c | 46 ++++++++++---------------- glabels2/src/util.h | 1 - 7 files changed, 53 insertions(+), 47 deletions(-) diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 4d2351da..77b9aef7 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,20 @@ +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-08-29 Jim Evins * src/file.c: (gl_file_open), (gl_file_save_as): 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 93aad0a4..e8a463da 100644 --- a/glabels2/src/object-editor-text-page.c +++ b/glabels2/src/object-editor-text-page.c @@ -108,7 +108,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); @@ -228,26 +227,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 683926fb..0a095231 100644 --- a/glabels2/src/prefs-dialog.c +++ b/glabels2/src/prefs-dialog.c @@ -341,7 +341,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), @@ -522,7 +521,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 ea2d10a4..d128682c 100644 --- a/glabels2/src/ui-property-bar.c +++ b/glabels2/src/ui-property-bar.c @@ -301,7 +301,6 @@ gl_ui_property_bar_construct (glUIPropertyBar *property_bar) { gtk_combo_box_set_active (GTK_COMBO_BOX (property_bar->priv->font_family_combo), 0); } - gl_util_font_family_list_free (family_names); g_signal_connect (G_OBJECT (property_bar->priv->font_family_combo), "changed", G_CALLBACK (font_family_changed_cb), property_bar); @@ -406,7 +405,6 @@ reset_to_default_properties (glView *view, gl_util_combo_box_set_active_text (GTK_COMBO_BOX (property_bar->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(property_bar->priv->font_size_spin), view->default_font_size); diff --git a/glabels2/src/util.c b/glabels2/src/util.c index ee9151bf..1e852eca 100644 --- a/glabels2/src/util.c +++ b/glabels2/src/util.c @@ -305,13 +305,14 @@ gl_util_combo_box_add_text_model (GtkComboBox *combo) NULL); } + /****************************************************************************/ /* 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; @@ -319,39 +320,26 @@ 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 aa0ff25e..bed0112f 100644 --- a/glabels2/src/util.h +++ b/glabels2/src/util.h @@ -51,7 +51,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); G_END_DECLS -- 2.39.5