From 6a597dc85342abf8c88a5b4f1ba99d50589f64ef Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 31 Jan 2013 19:35:26 +0100 Subject: Text toolbar will display style options for the first font in a font-family list. Also, fix mem leak. (bzr r12082) --- src/widgets/text-toolbar.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/widgets/text-toolbar.cpp') diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 6c22c81e3..1f60c6214 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -178,6 +178,11 @@ static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL) return; } + // If font list, take only first font in list + gchar** tokens = g_strsplit( current_font, ",", 0 ); + g_strstrip( tokens[0] ); + current_font = tokens[0]; + // Get an iter to the selected font from the model data // We cant get it from the combo, cause it might not have been created yet gboolean found = false; @@ -197,6 +202,8 @@ static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL) valid = gtk_tree_model_iter_next( model, &iter ); } + g_strfreev( tokens ); + if (!found) { return; } -- cgit v1.2.3 From c84cc8045be0f7374f0668df62b4f34ef8b9df9c Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sat, 2 Feb 2013 13:15:56 +0100 Subject: Allow simple font style changes even if first font-family in font list is not on users system. (bzr r12093) --- src/widgets/text-toolbar.cpp | 53 ++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 14 deletions(-) (limited to 'src/widgets/text-toolbar.cpp') diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 1f60c6214..9fdc1ea7b 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -204,14 +204,6 @@ static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL) g_strfreev( tokens ); - if (!found) { - return; - } - - // Get the list of styles from the selected font - GList *list = NULL; - gtk_tree_model_get (model, &iter, 1, &list, -1); - Ink_ComboBoxEntry_Action* fontStyleAction = INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontStyleAction" ) ); gchar *current_style = ink_comboboxentry_action_get_active_text( fontStyleAction ); @@ -219,11 +211,30 @@ static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL) GtkListStore *store = GTK_LIST_STORE( ink_comboboxentry_action_get_model( fontStyleAction ) ); gtk_list_store_clear ( store ); - // Add list of styles to the style combo - for (GList *l=list; l; l = l->next) - { + // Get the list of styles from the selected font + GList *list = NULL; + + if (found) { + + // Add list of styles to the style combo + gtk_tree_model_get (model, &iter, 1, &list, -1); + for (GList *l=list; l; l = l->next) + { + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, (char*)l->data, -1); + } + + } else { + + // Create generic list if selected font-family not available on system + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, "Normal", -1); + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, "Italic", -1); + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, "Bold", -1); gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, (char*)l->data, -1); + gtk_list_store_set (store, &iter, 0, "Bold Italic", -1); } // Select the style in the combo that best matches font @@ -526,7 +537,7 @@ static void sp_text_fontstyle_value_changed( Ink_ComboBoxEntry_Action *act, GObj SPCSSAttr *css = sp_repr_css_attr_new (); - gchar *current_style = ink_comboboxentry_action_get_active_text( act ); + Glib::ustring current_style = ink_comboboxentry_action_get_active_text( act ); Glib::ustring fontFamily = ""; if (query->text->font_family.set) { @@ -537,9 +548,10 @@ static void sp_text_fontstyle_value_changed( Ink_ComboBoxEntry_Action *act, GObj fontFamily = ink_comboboxentry_action_get_active_text( act ); } - font_instance *font = (font_factory::Default())->FaceFromUIStrings (fontFamily.c_str(), current_style); + font_instance *font = (font_factory::Default())->FaceFromUIStrings (fontFamily.c_str(), current_style.c_str()); if (font) { + gchar c[256]; font->Attribute( "weight", c, 256); @@ -556,6 +568,19 @@ static void sp_text_fontstyle_value_changed( Ink_ComboBoxEntry_Action *act, GObj font->Unref(); font = NULL; + + } else { + + // Font not found on system, blindly update style + // Options match choices in sp_text_fontstyle_populate + sp_repr_css_set_property (css, "font-weight", "normal"); + sp_repr_css_set_property (css, "font-style", "normal" ); + if( current_style.find("Bold") != Glib::ustring::npos ) { + sp_repr_css_set_property (css, "font-weight", "bold"); + } + if( current_style.find("Italic") != Glib::ustring::npos ) { + sp_repr_css_set_property (css, "font-style", "italic"); + } } // If querying returned nothing, update default style. -- cgit v1.2.3 From c37431c37889fed55de3b8c76a0dc0569f0fe42d Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sun, 3 Feb 2013 19:37:58 +0100 Subject: fix crash Fixed bugs: - https://launchpad.net/bugs/1114243 (bzr r12094) --- src/widgets/text-toolbar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets/text-toolbar.cpp') diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 9fdc1ea7b..f9921864c 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -238,7 +238,7 @@ static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL) } // Select the style in the combo that best matches font - if (font) { + if (font && list) { unsigned int index = sp_font_selector_get_best_style(font, list); -- cgit v1.2.3 From 61eb37a18f652117804d6e3a890ebde5959be214 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sun, 3 Feb 2013 19:40:00 +0100 Subject: add todo comment for fixing fontstyle fall-back behaviour (bzr r12095) --- src/widgets/text-toolbar.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/widgets/text-toolbar.cpp') diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index f9921864c..060bb4a80 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -235,6 +235,8 @@ static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL) gtk_list_store_set (store, &iter, 0, "Bold", -1); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, 0, "Bold Italic", -1); + + /// \todo \c list should be initialized here with "Normal", "Italic", etc too } // Select the style in the combo that best matches font -- cgit v1.2.3 From 2c7d2b2cd8f2571cc65d2ba7ac628bb8b43e5c7a Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 4 Feb 2013 10:47:19 +0100 Subject: Better fix for 1114243, crash on launch with default prefs from stable (bzr r12097) --- src/widgets/text-toolbar.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'src/widgets/text-toolbar.cpp') diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 060bb4a80..dc4a6be27 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -211,32 +211,31 @@ static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL) GtkListStore *store = GTK_LIST_STORE( ink_comboboxentry_action_get_model( fontStyleAction ) ); gtk_list_store_clear ( store ); - // Get the list of styles from the selected font + // Get the list of styles from the selected font. GList *list = NULL; if (found) { - // Add list of styles to the style combo + // Use precompiled list if font-family on system. gtk_tree_model_get (model, &iter, 1, &list, -1); - for (GList *l=list; l; l = l->next) - { - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, (char*)l->data, -1); - } } else { - // Create generic list if selected font-family not available on system - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, "Normal", -1); - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, "Italic", -1); - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, "Bold", -1); - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, "Bold Italic", -1); + // Use generic list if font-family not on system. + static GList *glist = NULL; + if( glist == NULL ) { + glist = g_list_append (glist, (void*)"Normal"); + glist = g_list_append (glist, (void*)"Italic"); + glist = g_list_append (glist, (void*)"Bold"); + glist = g_list_append (glist, (void*)"Bold Italic"); + } + list = glist; + } - /// \todo \c list should be initialized here with "Normal", "Italic", etc too + for (GList *l=list; l; l = l->next) + { + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, (char*)l->data, -1); } // Select the style in the combo that best matches font -- cgit v1.2.3 From 048beb0d69537f56f6b662830356553e469a4259 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 4 Feb 2013 19:54:53 +0100 Subject: Only set up text-tool bar if has actually been created. Ensures proper initialization after creation. (bzr r12099) --- src/widgets/text-toolbar.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/widgets/text-toolbar.cpp') diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index dc4a6be27..6adff8bfb 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -1173,6 +1173,13 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ std::cout << selected_text << std::endl; #endif + // Check if the toolbar has been created; quit if it has not. + Ink_ComboBoxEntry_Action* fontFamilyAction = + INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontFamilyAction" ) ); + if( fontFamilyAction->combobox == NULL ) { + return; + } + // quit if run by the _changed callbacks if (g_object_get_data(G_OBJECT(tbl), "freeze")) { #ifdef DEBUG_TEXT -- cgit v1.2.3 From f7810c8932b5097aebb9c1b11e346d1a56b4a11e Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 5 Feb 2013 19:45:34 +0100 Subject: Second try at getting text toolbar properly initialized when there is no prefs file. (bzr r12101) --- src/widgets/text-toolbar.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/widgets/text-toolbar.cpp') diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 6adff8bfb..3eccf1d2f 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -1173,13 +1173,6 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ std::cout << selected_text << std::endl; #endif - // Check if the toolbar has been created; quit if it has not. - Ink_ComboBoxEntry_Action* fontFamilyAction = - INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontFamilyAction" ) ); - if( fontFamilyAction->combobox == NULL ) { - return; - } - // quit if run by the _changed callbacks if (g_object_get_data(G_OBJECT(tbl), "freeze")) { #ifdef DEBUG_TEXT @@ -1243,7 +1236,13 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ return; } - g_object_set_data(tbl, "text_style_from_prefs", GINT_TO_POINTER(TRUE)); + // To ensure the value of the combobox is properly set on start-up, only mark + // the prefs set if the combobox has already been constructed. + Ink_ComboBoxEntry_Action* fontFamilyAction = + INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontFamilyAction" ) ); + if( fontFamilyAction->combobox != NULL ) { + g_object_set_data(tbl, "text_style_from_prefs", GINT_TO_POINTER(TRUE)); + } } else { g_object_set_data(tbl, "text_style_from_prefs", GINT_TO_POINTER(FALSE)); } -- cgit v1.2.3