summaryrefslogtreecommitdiffstats
path: root/src/widgets/text-toolbar.cpp
diff options
context:
space:
mode:
authorMarkus Engel <markus.engel@tum.de>2013-03-29 23:52:42 +0000
committerMarkus Engel <markus.engel@tum.de>2013-03-29 23:52:42 +0000
commita168040d5a452544328a1e6ad35aaac351f94d44 (patch)
treefae1ba829f543a473da281bd5fa6e4deabbf6912 /src/widgets/text-toolbar.cpp
parentRemoved function pointers from SPObject and subclasses. (diff)
parentDutch translation update (diff)
downloadinkscape-a168040d5a452544328a1e6ad35aaac351f94d44.tar.gz
inkscape-a168040d5a452544328a1e6ad35aaac351f94d44.zip
merged from trunk
(bzr r11608.1.56)
Diffstat (limited to 'src/widgets/text-toolbar.cpp')
-rw-r--r--src/widgets/text-toolbar.cpp557
1 files changed, 182 insertions, 375 deletions
diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp
index b769c41f6..87cb54d10 100644
--- a/src/widgets/text-toolbar.cpp
+++ b/src/widgets/text-toolbar.cpp
@@ -18,8 +18,8 @@
*
* Copyright (C) 2004 David Turner
* Copyright (C) 2003 MenTaLguY
- * Copyright (C) 1999-2011 authors
* Copyright (C) 2001-2002 Ximian, Inc.
+ * Copyright (C) 1999-2013 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
@@ -28,10 +28,8 @@
# include "config.h"
#endif
-
-#include <glibmm/i18n.h>
-
#include "ui/widget/spinbutton.h"
+#include <glibmm/i18n.h>
#include "toolbox.h"
#include "text-toolbar.h"
@@ -39,6 +37,7 @@
#include "../desktop-handles.h"
#include "../desktop-style.h"
#include "document-undo.h"
+#include "../sp-root.h"
#include "../verbs.h"
#include "../inkscape.h"
#include "../connection-pool.h"
@@ -105,6 +104,10 @@ static void sp_print_font( SPStyle *query ) {
<< " FontSpec: "
<< (query->text->font_specification.value ? query->text->font_specification.value : "No value")
<< std::endl;
+ std::cout << " LineHeight: " << query->line_height.computed
+ << " WordSpacing: " << query->word_spacing.computed
+ << " LetterSpacing: " << query->letter_spacing.computed
+ << std::endl;
}
static void sp_print_fontweight( SPStyle *query ) {
@@ -128,130 +131,7 @@ static void sp_print_fontstyle( SPStyle *query ) {
}
#endif
-// Format family drop-down menu.
-static void cell_data_func(GtkCellLayout * /*cell_layout*/,
- GtkCellRenderer *cell,
- GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- gpointer /*data*/)
-{
- gchar *family;
- gtk_tree_model_get(tree_model, iter, 0, &family, -1);
- gchar *const family_escaped = g_markup_escape_text(family, -1);
-
- Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- int show_sample = prefs->getInt("/tools/text/show_sample_in_list", 1);
- if (show_sample) {
-
- Glib::ustring sample = prefs->getString("/tools/text/font_sample");
- gchar *const sample_escaped = g_markup_escape_text(sample.data(), -1);
-
- std::stringstream markup;
- markup << family_escaped << " <span foreground='gray' font_family='"
- << family_escaped << "'>" << sample_escaped << "</span>";
- g_object_set (G_OBJECT (cell), "markup", markup.str().c_str(), NULL);
-
- g_free(sample_escaped);
- } else {
- g_object_set (G_OBJECT (cell), "markup", family_escaped, NULL);
- }
- // This doesn't work for two reasons... it set both selected and not selected backgrounds
- // to white.. which means that white foreground text is invisible. It also only effects
- // the text region, leaving the padding untouched.
- // g_object_set (G_OBJECT (cell), "cell-background", "white", "cell-background-set", true, NULL);
-
- g_free(family);
- g_free(family_escaped);
-}
-
-/*
- * Fill the font style combobox with the available font styles for the selected font family
- * Set the selected style to that in font
- */
-static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL)
-{
-
- Ink_ComboBoxEntry_Action* act = INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontFamilyAction" ) );
- GtkTreeModel *model = ink_comboboxentry_action_get_model( act );
- gchar *current_font = ink_comboboxentry_action_get_active_text( act );
-
- // 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;
- GtkTreeIter iter;
- gboolean valid = gtk_tree_model_get_iter_first( model, &iter );
- while ( valid ) {
-
- // Get text from list entry
- gchar* text = 0;
- gtk_tree_model_get( model, &iter, 0, &text, -1 ); // Column 0
-
- // Check for match
- if( strcmp( current_font, text ) == 0 ){
- found = true;
- break;
- }
- valid = gtk_tree_model_iter_next( model, &iter );
- }
-
- if (!found) {
- return;
- }
-
- // Get the list of styles from the selected font
- GList *list=0;
- 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 );
-
- 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)
- {
- 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
- if (font) {
-
- unsigned int index = sp_font_selector_get_best_style(font, list);
-
- Ink_ComboBoxEntry_Action* fontStyleAction =
- INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontStyleAction" ) );
- model = ink_comboboxentry_action_get_model( fontStyleAction );
- GtkTreePath *path_c = gtk_tree_path_new ();
- gtk_tree_path_append_index (path_c, index);
- gtk_tree_model_get_iter(model, &iter, path_c);
- gchar *name;
- gtk_tree_model_get (model, &iter, 0, &name, -1);
- ink_comboboxentry_action_set_active_text( fontStyleAction, name );
-
- } else if (current_style) {
- ink_comboboxentry_action_set_active_text( fontStyleAction, current_style );
- }
-
-}
-
// Font family
-//
-// In most cases we should just be able to set the new family name
-// but there may be cases where a font family doesn't follow the
-// standard naming pattern. To handle those cases, we do a song and
-// dance to use Pango to find the best match. To do that we start
-// with the old "fontSpec" (which is the returned string from
-// pango_font_description_to_string() with the size unset). This
-// has the form "[family-list] [style-options]" where the
-// family-list is a comma separated list of font-family names
-// (optionally terminated by a comma). An example would be
-// "DejaVu Sans, Sans Bold". Only a "fontSpec" containing a
-// single font-family will work with Pango's best match routine.
-// If we can't obtain a good "fontSpec", we then resort to blindly
-// changing the font-family.
static void sp_text_fontfamily_value_changed( Ink_ComboBoxEntry_Action *act, GObject *tbl )
{
#ifdef DEBUG_TEXT
@@ -262,156 +142,45 @@ static void sp_text_fontfamily_value_changed( Ink_ComboBoxEntry_Action *act, GOb
// quit if run by the _changed callbacks
if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
- return;
- }
- g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
-
- gchar *family = ink_comboboxentry_action_get_active_text( act );
-#ifdef DEBUG_TEXT
- std::cout << " New family: " << family << std::endl;
-#endif
-
- // First try to get the old font spec from the stored value
- SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
- int result_fontspec = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION);
-
- Glib::ustring fontSpec = query->text->font_specification.set ? query->text->font_specification.value : "";
#ifdef DEBUG_TEXT
- std::cout << " fontSpec from query :" << fontSpec << ":" << std::endl;
-#endif
-
- // If that didn't work, try to get font spec from style
- if (fontSpec.empty()) {
-
- // Must query all to fill font-family, font-style, font-weight, font-specification
- sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY);
- sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE);
- sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
-
- // Construct a new font specification if it does not yet exist
- font_instance * fontFromStyle = font_factory::Default()->FaceFromStyle(query);
- if( fontFromStyle ) {
- fontSpec = font_factory::Default()->ConstructFontSpecification(fontFromStyle);
- fontFromStyle->Unref();
- }
-
-#ifdef DEBUG_TEXT
- std::cout << " fontSpec empty, try from style" << std::endl;
- std::cout << " from style :" << fontSpec << ":" << std::endl;
- sp_print_font( query );
-#endif
-
- }
-
- // And if that didn't work use default. DO WE REALLY WANT TO DO THIS?
- if ( fontSpec.empty() ) {
-
- sp_style_read_from_prefs(query, "/tools/text");
-
- // Construct a new font specification if it does not yet exist
- font_instance * fontFromStyle = font_factory::Default()->FaceFromStyle(query);
- if ( fontFromStyle ) {
- fontSpec = font_factory::Default()->ConstructFontSpecification(fontFromStyle);
- fontFromStyle->Unref();
- }
-
-#ifdef DEBUG_TEXT
- std::cout << " fontSpec empty, trying from prefs" << std::endl;
- std::cout << " from prefs :" << fontSpec << ":" << std::endl;
- sp_print_font( query );
+ std::cout << "sp_text_fontfamily_value_changed: frozen... return" << std::endl;
+ std::cout << "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n" << std::endl;
#endif
+ return;
}
+ g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
- // Now we have a font specification, replace family.
- Glib::ustring newFontSpec = "";
- SPCSSAttr *css = sp_repr_css_attr_new ();
-
- if (!fontSpec.empty()) newFontSpec = font_factory::Default()->ReplaceFontSpecificationFamily(fontSpec, family);
-
-#ifdef DEBUG_TEXT
- std::cout << " New FontSpec from ReplaceFontSpecificationFamily :" << newFontSpec << ":" << std::endl;
-#endif
-
- if (!fontSpec.empty() && !newFontSpec.empty() ) {
-
- if (fontSpec != newFontSpec) {
-
- font_instance *font = font_factory::Default()->FaceFromFontSpecification(newFontSpec.c_str());
-
- if (font) {
- sp_repr_css_set_property (css, "-inkscape-font-specification", newFontSpec.c_str());
-
- // Set all the these just in case they were altered when finding the best
- // match for the new family and old style... Unnecessary?
-
- gchar c[256];
-
- font->Family(c, 256);
-
- sp_repr_css_set_property (css, "font-family", c);
-
- font->Attribute( "weight", c, 256);
- sp_repr_css_set_property (css, "font-weight", c);
-
- font->Attribute("style", c, 256);
- sp_repr_css_set_property (css, "font-style", c);
-
- font->Attribute("stretch", c, 256);
- sp_repr_css_set_property (css, "font-stretch", c);
-
- font->Attribute("variant", c, 256);
- sp_repr_css_set_property (css, "font-variant", c);
-
- font->Unref();
-
- // Set the list of font styles
- sp_text_fontstyle_populate(tbl);
-
- } else {
- g_warning(_("Failed to find font matching: %s\n"), newFontSpec.c_str());
- }
- }
- } else {
-
- // Either old font does not exist on system or ReplaceFontSpecificationFamily() failed.
- // Blindly fall back to setting the family to text in the font-family chooser.
+ Glib::ustring new_family = ink_comboboxentry_action_get_active_text( act );
+ // TODO: Think about how to handle handle multiple selections. While
+ // the font-family may be the same for all, the styles might be different.
+ // See: TextEdit::onApply() for example of looping over selected items.
+ Inkscape::FontLister* fontlister = Inkscape::FontLister::get_instance();
#ifdef DEBUG_TEXT
- std::cout << " Failed to find new font, blindly setting family: " << family << std::endl;
+ std::cout << " Old family: " << fontlister->get_font_family() << std::endl;
+ std::cout << " New family: " << new_family << std::endl;
+ std::cout << " Old active: " << fontlister->get_font_family_row() << std::endl;
+ std::cout << " New active: " << act->active << std::endl;
#endif
- sp_repr_css_set_property (css, "-inkscape-font-specification", family);
- sp_repr_css_set_property (css, "font-family", family);
- }
+ if( new_family.compare( fontlister->get_font_family() ) != 0 ) {
- // If querying returned nothing, update default style.
- if (result_fontspec == QUERY_STYLE_NOTHING)
- {
- Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- prefs->mergeStyle("/tools/text/style", css);
- //sp_text_edit_dialog_default_set_insensitive (); //FIXME: Replace through a verb
- }
- else
- {
- sp_desktop_set_style (SP_ACTIVE_DESKTOP, css, true, true);
- }
+ std::pair<Glib::ustring,Glib::ustring> ui = fontlister->set_font_family( act->active );
+ // active text set in sp_text_toolbox_selection_changed()
- sp_style_unref(query);
+ SPCSSAttr *css = sp_repr_css_attr_new ();
+ fontlister->fill_css( css );
- g_free (family);
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ sp_desktop_set_style (desktop, css, true, true); // Results in selection change called twice.
+ sp_repr_css_attr_unref (css);
- // Save for undo
- if (result_fontspec != QUERY_STYLE_NOTHING) {
- DocumentUndo::done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT,
+ DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT,
_("Text: Change font family"));
}
- sp_repr_css_attr_unref (css);
// unfreeze
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
- // focus to canvas
- gtk_widget_grab_focus (GTK_WIDGET((SP_ACTIVE_DESKTOP)->canvas));
-
#ifdef DEBUG_TEXT
std::cout << "sp_text_toolbox_fontfamily_changes: exit" << std::endl;
std::cout << "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM" << std::endl;
@@ -445,10 +214,14 @@ static void sp_text_fontsize_value_changed( Ink_ComboBoxEntry_Action *act, GObje
size = max_size;
// Set css font size.
- int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
SPCSSAttr *css = sp_repr_css_attr_new ();
Inkscape::CSSOStringStream osfs;
- osfs << size << sp_style_get_css_unit_string(unit);
+ int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
+ if (prefs->getBool("/options/font/textOutputPx", true)) {
+ osfs << sp_style_css_size_units_to_px(size, unit) << sp_style_get_css_unit_string(SP_CSS_UNIT_PX);
+ } else {
+ osfs << size << sp_style_get_css_unit_string(unit);
+ }
sp_repr_css_set_property (css, "font-size", osfs.str().c_str());
// Apply font size to selected objects.
@@ -479,7 +252,6 @@ static void sp_text_fontsize_value_changed( Ink_ComboBoxEntry_Action *act, GObje
/*
* Font style
*/
-//static void sp_text_fontstyle_value_changed( EgeSelectOneAction *act, GObject *tbl )
static void sp_text_fontstyle_value_changed( Ink_ComboBoxEntry_Action *act, GObject *tbl )
{
// quit if run by the _changed callbacks
@@ -488,79 +260,26 @@ static void sp_text_fontstyle_value_changed( Ink_ComboBoxEntry_Action *act, GObj
}
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
- // First query font-specification, this is the most complete font face description.
- SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
- int result_fontspec = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION);
-
- // font_specification will not be set unless defined explicitily on a tspan.
- // This should be fixed!
- Glib::ustring fontSpec = query->text->font_specification.set ? query->text->font_specification.value : "";
-
- if (fontSpec.empty()) {
- // Construct a new font specification if it does not yet exist
- // Must query font-family, font-style, font-weight, to find correct font face.
- sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY);
- sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE);
- sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
-
- font_instance * fontFromStyle = font_factory::Default()->FaceFromStyle(query);
- if ( fontFromStyle ) {
- fontSpec = font_factory::Default()->ConstructFontSpecification(fontFromStyle);
- fontFromStyle->Unref();
- }
- }
-
- // Now that we have the old face, find the new face.
- Glib::ustring newFontSpec = "";
- SPCSSAttr *css = sp_repr_css_attr_new ();
-
- gchar *current_style = ink_comboboxentry_action_get_active_text( act );
- Glib::ustring fontFamily = query->text->font_family.set ? query->text->font_family.value : "";
+ Glib::ustring new_style = ink_comboboxentry_action_get_active_text( act );
- font_instance *font = (font_factory::Default())->FaceFromUIStrings (fontFamily.c_str(), current_style);
+ Inkscape::FontLister* fontlister = Inkscape::FontLister::get_instance();
- if (font) {
- gchar c[256];
+ if( new_style.compare( fontlister->get_font_style() ) != 0 ) {
- font->Attribute( "weight", c, 256);
- sp_repr_css_set_property (css, "font-weight", c);
+ fontlister->set_font_style( new_style );
+ // active text set in sp_text_toolbox_seletion_changed()
- font->Attribute("style", c, 256);
- sp_repr_css_set_property (css, "font-style", c);
+ SPCSSAttr *css = sp_repr_css_attr_new ();
+ fontlister->fill_css( css );
- font->Attribute("stretch", c, 256);
- sp_repr_css_set_property (css, "font-stretch", c);
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ sp_desktop_set_style (desktop, css, true, true);
+ sp_repr_css_attr_unref (css);
- font->Attribute("variant", c, 256);
- sp_repr_css_set_property (css, "font-variant", c);
-
- font->Unref();
- font = NULL;
- }
-
-
- if (!newFontSpec.empty()) {
- sp_repr_css_set_property (css, "-inkscape-font-specification", newFontSpec.c_str());
+ DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT,
+ _("Text: Change font style"));
}
- // If querying returned nothing, update default style.
- if (result_fontspec == QUERY_STYLE_NOTHING)
- {
- Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- prefs->mergeStyle("/tools/text/style", css);
- }
-
- sp_style_unref(query);
-
- // Do we need to update other CSS values?
- SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- sp_desktop_set_style (desktop, css, true, true);
- if (result_fontspec != QUERY_STYLE_NOTHING) {
- DocumentUndo::done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT,
- _("Text: Change font style"));
- }
- sp_repr_css_attr_unref (css);
-
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
}
@@ -659,7 +378,7 @@ static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl )
// move the x of all texts to preserve the same bbox
Inkscape::Selection *selection = sp_desktop_selection(desktop);
for (GSList const *items = selection->itemList(); items != NULL; items = items->next) {
- if (SP_IS_TEXT((SPItem *) items->data)) {
+ if (SP_IS_TEXT(SP_ITEM(items->data))) {
SPItem *item = SP_ITEM(items->data);
unsigned writing_mode = item->style->writing_mode.value;
@@ -1081,7 +800,7 @@ static void sp_text_orientation_mode_changed( EgeSelectOneAction *act, GObject *
/*
* Set the default list of font sizes, scaled to the users preferred unit
*/
-void sp_text_set_sizes(GtkListStore* model_size, int unit)
+static void sp_text_set_sizes(GtkListStore* model_size, int unit)
{
gtk_list_store_clear(model_size);
@@ -1135,6 +854,7 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
#ifdef DEBUG_TEXT
std::cout << " Frozen, returning" << std::endl;
+ std::cout << "sp_text_toolbox_selection_changed: exit " << count << std::endl;
std::cout << "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" << std::endl;
std::cout << std::endl;
#endif
@@ -1142,6 +862,21 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
}
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
+ Ink_ComboBoxEntry_Action* fontFamilyAction =
+ INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontFamilyAction" ) );
+ Ink_ComboBoxEntry_Action* fontStyleAction =
+ INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontStyleAction" ) );
+
+ Inkscape::FontLister* fontlister = Inkscape::FontLister::get_instance();
+ fontlister->update_font_list( sp_desktop_document( SP_ACTIVE_DESKTOP ));
+ fontlister->selection_update();
+
+ // Update font list, but only if widget already created.
+ if( fontFamilyAction->combobox != NULL ) {
+ ink_comboboxentry_action_set_active_text( fontFamilyAction, fontlister->get_font_family().c_str(), fontlister->get_font_family_row() );
+ ink_comboboxentry_action_set_active_text( fontStyleAction, fontlister->get_font_style().c_str() );
+ }
+
// Only flowed text can be justified, only normal text can be kerned...
// Find out if we have flowed text now so we can use it several places
gboolean isFlow = false;
@@ -1150,7 +885,7 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
items = items->next) {
// const gchar* id = reinterpret_cast<SPItem *>(items->data)->getId();
// std::cout << " " << id << std::endl;
- if( SP_IS_FLOWTEXT(( SPItem *) items->data )) {
+ if( SP_IS_FLOWTEXT(SP_ITEM(items->data))) {
isFlow = true;
// std::cout << " Found flowed text" << std::endl;
break;
@@ -1164,16 +899,12 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
* Numbers (font-size, letter-spacing, word-spacing, line-height, text-anchor, writing-mode)
* Font specification (Inkscape private attribute)
*/
- SPStyle *query =
- sp_style_new (SP_ACTIVE_DOCUMENT);
+ SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY);
int result_style = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE);
int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
int result_baseline = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_BASELINES);
- // Used later:
- sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION);
-
/*
* If no text in selection (querying returned nothing), read the style from
* the /tools/text preferencess (default style for new texts). Return if
@@ -1192,13 +923,18 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
#ifdef DEBUG_TEXT
std::cout << " text_style_from_prefs: toolbar already set" << std:: endl;
+ std::cout << "sp_text_toolbox_selection_changed: exit " << count << std::endl;
std::cout << "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" << std::endl;
std::cout << std::endl;
#endif
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.
+ 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));
}
@@ -1206,34 +942,29 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
// If we have valid query data for text (font-family, font-specification) set toolbar accordingly.
if (query->text)
{
- // Font family
- if( query->text->font_family.value ) {
- gchar *fontFamily = query->text->font_family.value;
-
- Ink_ComboBoxEntry_Action* fontFamilyAction =
- INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontFamilyAction" ) );
- ink_comboboxentry_action_set_active_text( fontFamilyAction, fontFamily );
- }
-
// Size (average of text selected)
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
- double size = sp_style_get_css_font_size_units(query->font_size.computed, unit);
+ double size = sp_style_css_size_px_to_units(query->font_size.computed, unit);
- gchar size_text[G_ASCII_DTOSTR_BUF_SIZE];
- g_ascii_dtostr (size_text, sizeof (size_text), size);
+ //gchar size_text[G_ASCII_DTOSTR_BUF_SIZE];
+ //g_ascii_dtostr (size_text, sizeof (size_text), size);
+
+ Inkscape::CSSOStringStream os;
+ os << size;
Ink_ComboBoxEntry_Action* fontSizeAction =
INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontSizeAction" ) );
+
+ // Freeze to ignore callbacks.
+ //g_object_freeze_notify( G_OBJECT( fontSizeAction->combobox ) );
sp_text_set_sizes(GTK_LIST_STORE(ink_comboboxentry_action_get_model(fontSizeAction)), unit);
- ink_comboboxentry_action_set_active_text( fontSizeAction, size_text );
+ //g_object_thaw_notify( G_OBJECT( fontSizeAction->combobox ) );
- Glib::ustring tooltip = Glib::ustring::format("Font size (", sp_style_get_css_unit_string(unit), ")");
- ink_comboboxentry_action_set_tooltip ( fontSizeAction, tooltip.c_str());
+ ink_comboboxentry_action_set_active_text( fontSizeAction, os.str().c_str() );
- // Font styles
- font_instance *font = font_factory::Default()->FaceFromStyle(query);
- sp_text_fontstyle_populate(tbl, font);
+ Glib::ustring tooltip = Glib::ustring::format(_("Font size"), " (", sp_style_get_css_unit_string(unit), ")");
+ ink_comboboxentry_action_set_tooltip ( fontSizeAction, tooltip.c_str());
// Superscript
gboolean superscriptSet =
@@ -1416,6 +1147,7 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
}
#ifdef DEBUG_TEXT
+ std::cout << "sp_text_toolbox_selection_changed: exit " << count << std::endl;
std::cout << "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" << std::endl;
std::cout << std::endl;
#endif
@@ -1429,12 +1161,56 @@ static void sp_text_toolbox_selection_modified(Inkscape::Selection *selection, g
sp_text_toolbox_selection_changed (selection, tbl);
}
-void
+static void
sp_text_toolbox_subselection_changed (gpointer /*tc*/, GObject *tbl)
{
sp_text_toolbox_selection_changed (NULL, tbl);
}
+// TODO: possibly share with font-selector by moving most code to font-lister (passing family name)
+static void sp_text_toolbox_select_cb( GtkEntry* entry, GtkEntryIconPosition /*position*/, GdkEvent /*event*/, gpointer /*data*/ ) {
+
+ Glib::ustring family = gtk_entry_get_text ( entry );
+ //std::cout << "text_toolbox_missing_font_cb: selecting: " << family << std::endl;
+
+ // Get all items with matching font-family set (not inherited!).
+ GSList *selectList = NULL;
+
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ SPDocument *document = sp_desktop_document( desktop );
+ GSList *allList = get_all_items(NULL, document->getRoot(), desktop, false, false, true, NULL);
+ for (GSList *i = allList; i != NULL; i = i->next) {
+
+ SPItem *item = SP_ITEM(i->data);
+ SPStyle *style = item->style;
+
+ if (style && style->text) {
+
+ Glib::ustring family_style;
+ if (style->text->font_family.set) {
+ family_style = style->text->font_family.value;
+ //std::cout << " family style from font_family: " << family_style << std::endl;
+ }
+ else if (style->text->font_specification.set) {
+ family_style = style->text->font_specification.value;
+ //std::cout << " family style from font_spec: " << family_style << std::endl;
+ }
+
+ if (family_style.compare( family ) == 0 ) {
+ //std::cout << " found: " << item->getId() << std::endl;
+ selectList = g_slist_prepend (selectList, item);
+ }
+ }
+ }
+
+ // Update selection
+ Inkscape::Selection *selection = sp_desktop_selection (desktop );
+ selection->clear();
+ //std::cout << " list length: " << g_slist_length ( selectList ) << std::endl;
+ selection->setList(selectList);
+}
+
+
// Define all the "widgets" in the toolbar.
void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
{
@@ -1449,20 +1225,33 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
/* Font family */
{
// Font list
- Glib::RefPtr<Gtk::ListStore> store = Inkscape::FontLister::get_instance()->get_font_list();
+ Inkscape::FontLister* fontlister = Inkscape::FontLister::get_instance();
+ fontlister->update_font_list( sp_desktop_document( SP_ACTIVE_DESKTOP ));
+ Glib::RefPtr<Gtk::ListStore> store = fontlister->get_font_list();
GtkListStore* model = store->gobj();
- Ink_ComboBoxEntry_Action* act = ink_comboboxentry_action_new( "TextFontFamilyAction",
- _("Font Family"),
- _("Select Font Family (Alt-X to access)"),
- NULL,
- GTK_TREE_MODEL(model),
- -1, // Entry width
- 50, // Extra list width
- (gpointer)cell_data_func ); // Cell layout
+ Ink_ComboBoxEntry_Action* act =
+ ink_comboboxentry_action_new( "TextFontFamilyAction",
+ _("Font Family"),
+ _("Select Font Family (Alt-X to access)"),
+ NULL,
+ GTK_TREE_MODEL(model),
+ -1, // Entry width
+ 50, // Extra list width
+ (gpointer)font_lister_cell_data_func, // Cell layout
+ (gpointer)font_lister_separator_func,
+ GTK_WIDGET(desktop->canvas)); // Focus widget
ink_comboboxentry_action_popup_enable( act ); // Enable entry completion
+
+ gchar *const info = _("Select all text with this font-family");
+ ink_comboboxentry_action_set_info( act, info ); // Show selection icon
+ ink_comboboxentry_action_set_info_cb( act, (gpointer)sp_text_toolbox_select_cb );
+
gchar *const warning = _("Font not found on system");
- ink_comboboxentry_action_set_warning( act, warning ); // Show icon with tooltip if missing font
+ ink_comboboxentry_action_set_warning( act, warning ); // Show icon w/ tooltip if font missing
+ ink_comboboxentry_action_set_warning_cb( act, (gpointer)sp_text_toolbox_select_cb );
+
+ //ink_comboboxentry_action_set_warning_callback( act, sp_text_fontfamily_select_all );
ink_comboboxentry_action_set_altx_name( act, "altx-text" ); // Set Alt-X keyboard shortcut
g_signal_connect( G_OBJECT(act), "changed", G_CALLBACK(sp_text_fontfamily_value_changed), holder );
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
@@ -1474,7 +1263,13 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
"{\n"
" GtkComboBox::appears-as-list = 1\n"
"}\n"
- "widget \"*.TextFontFamilyAction_combobox\" style \"dropdown-as-list-style\"");
+ "widget \"*.TextFontFamilyAction_combobox\" style \"dropdown-as-list-style\""
+ "style \"fontfamily-separator-style\"\n"
+ "{\n"
+ " GtkWidget::wide-separators = 1\n"
+ " GtkWidget::separator-height = 6\n"
+ "}\n"
+ "widget \"*gtk-combobox-popup-window.GtkScrolledWindow.GtkTreeView\" style \"fontfamily-separator-style\"");
}
/* Font size */
@@ -1486,14 +1281,19 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
sp_text_set_sizes(model_size, unit);
- Glib::ustring tooltip = Glib::ustring::format("Font size (", sp_style_get_css_unit_string(unit), ")");
+ Glib::ustring tooltip = Glib::ustring::format(_("Font size"), " (", sp_style_get_css_unit_string(unit), ")");
Ink_ComboBoxEntry_Action* act = ink_comboboxentry_action_new( "TextFontSizeAction",
_("Font Size"),
_(tooltip.c_str()),
NULL,
GTK_TREE_MODEL(model_size),
- 4 ); // Width in characters
+ 4, // Width in characters
+ 0, // Extra list width
+ NULL, // Cell layout
+ NULL, // Separator
+ GTK_WIDGET(desktop->canvas)); // Focus widget
+
g_signal_connect( G_OBJECT(act), "changed", G_CALLBACK(sp_text_fontsize_value_changed), holder );
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
g_object_set_data( holder, "TextFontSizeAction", act );
@@ -1501,14 +1301,21 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
/* Font styles */
{
- GtkListStore* model_style = gtk_list_store_new( 1, G_TYPE_STRING );
+ Inkscape::FontLister* fontlister = Inkscape::FontLister::get_instance();
+ Glib::RefPtr<Gtk::ListStore> store = fontlister->get_style_list();
+ GtkListStore* model_style = store->gobj();
- Ink_ComboBoxEntry_Action* act = ink_comboboxentry_action_new( "TextFontStyleAction",
+ Ink_ComboBoxEntry_Action* act = ink_comboboxentry_action_new( "TextFontStyleAction",
_("Font Style"),
_("Font style"),
NULL,
GTK_TREE_MODEL(model_style),
- 12 ); // Width in characters
+ 12, // Width in characters
+ 0, // Extra list width
+ NULL, // Cell layout
+ NULL, // Separator
+ GTK_WIDGET(desktop->canvas)); // Focus widget
+
g_signal_connect( G_OBJECT(act), "changed", G_CALLBACK(sp_text_fontstyle_value_changed), holder );
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
g_object_set_data( holder, "TextFontStyleAction", act );
@@ -1835,17 +1642,17 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
sigc::connection *c_selection_changed =
new sigc::connection (sp_desktop_selection (desktop)->connectChanged
- (sigc::bind (sigc::ptr_fun (sp_text_toolbox_selection_changed), (GObject*)holder)));
+ (sigc::bind (sigc::ptr_fun (sp_text_toolbox_selection_changed), holder)));
pool->add_connection ("selection-changed", c_selection_changed);
sigc::connection *c_selection_modified =
new sigc::connection (sp_desktop_selection (desktop)->connectModified
- (sigc::bind (sigc::ptr_fun (sp_text_toolbox_selection_modified), (GObject*)holder)));
+ (sigc::bind (sigc::ptr_fun (sp_text_toolbox_selection_modified), holder)));
pool->add_connection ("selection-modified", c_selection_modified);
sigc::connection *c_subselection_changed =
new sigc::connection (desktop->connectToolSubselectionChanged
- (sigc::bind (sigc::ptr_fun (sp_text_toolbox_subselection_changed), (GObject*)holder)));
+ (sigc::bind (sigc::ptr_fun (sp_text_toolbox_subselection_changed), holder)));
pool->add_connection ("tool-subselection-changed", c_subselection_changed);
Inkscape::ConnectionPool::connect_destroy (G_OBJECT (holder), pool);