diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2018-04-25 14:29:08 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2018-04-25 14:29:08 +0000 |
| commit | c259adc37c0b0df32a28d70e51d7fde0968b4cdc (patch) | |
| tree | 275c61d132acae5b1d90f45f2e7a6c38159aeebb /src | |
| parent | fix bug on compile (diff) | |
| download | inkscape-c259adc37c0b0df32a28d70e51d7fde0968b4cdc.tar.gz inkscape-c259adc37c0b0df32a28d70e51d7fde0968b4cdc.zip | |
Implement FontSelectorToolbar.
A version of FontSelector designed for the text toolbar.
This is meant as a replacement for Ink_ComboBoxEntry_Action.
It is not ready for use.
Also includes some code cleanup.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libnrtype/font-lister.cpp | 133 | ||||
| -rw-r--r-- | src/libnrtype/font-lister.h | 16 | ||||
| -rw-r--r-- | src/ui/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/ui/dialog/glyphs.cpp | 11 | ||||
| -rw-r--r-- | src/ui/dialog/text-edit.cpp | 8 | ||||
| -rw-r--r-- | src/ui/widget/font-selector-toolbar.cpp | 303 | ||||
| -rw-r--r-- | src/ui/widget/font-selector-toolbar.h | 119 | ||||
| -rw-r--r-- | src/ui/widget/font-selector.cpp | 88 | ||||
| -rw-r--r-- | src/ui/widget/font-selector.h | 9 |
9 files changed, 562 insertions, 127 deletions
diff --git a/src/libnrtype/font-lister.cpp b/src/libnrtype/font-lister.cpp index 20ab3786d..47a260714 100644 --- a/src/libnrtype/font-lister.cpp +++ b/src/libnrtype/font-lister.cpp @@ -142,6 +142,73 @@ void FontLister::ensureRowStyles(Glib::RefPtr<Gtk::TreeModel> model, Gtk::TreeMo } } +Glib::ustring FontLister::get_font_family_markup(Gtk::TreeIter const &iter) +{ + Gtk::TreeModel::Row row = *iter; + + Glib::ustring family = row[FontList.family]; + bool onSystem = row[FontList.onSystem]; + + Glib::ustring family_escaped = Glib::strescape( family ); + Glib::ustring markup; + + if (!onSystem) { + markup = "<span foreground='darkblue'>"; + + // See if font-family is on system (separately for each family in font stack). + std::vector<Glib::ustring> tokens = Glib::Regex::split_simple("\\s*,\\s*", family); + + for (auto token: tokens) { + bool found = false; + Gtk::TreeModel::Children children = get_font_list()->children(); + for (auto iter2: children) { + Gtk::TreeModel::Row row2 = *iter2; + Glib::ustring family2 = row2[FontList.family]; + bool onSystem2 = row2[FontList.onSystem]; + if (onSystem2 && familyNamesAreEqual(token, family2)) { + found = true; + break; + } + } + + if (found) { + markup += Glib::strescape (token); + markup += ", "; + } else { + markup += "<span strikethrough=\"true\" strikethrough_color=\"red\">"; + markup += Glib::strescape (token); + markup += "</span>"; + markup += ", "; + } + } + + // Remove extra comma and space from end. + if (markup.size() >= 2) { + markup.resize(markup.size() - 2); + } + markup += "</span>"; + + } else { + markup = family_escaped; + } + + 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"); + + markup += " <span foreground='gray' font_family='"; + markup += family_escaped; + markup += "'>"; + markup += sample; + markup += "</span>"; + } + + // std::cout << "Markup: " << markup << std::endl; + return markup; +} + // Example of how to use "foreach_iter" // bool // FontLister::print_document_font( const Gtk::TreeModel::iterator &iter ) { @@ -350,7 +417,7 @@ void FontLister::emit_update() if (block) return; block = true; - update_signal.emit (get_fontspec()); + update_signal.emit (); block = false; } @@ -1032,69 +1099,7 @@ gboolean font_lister_separator_func2(GtkTreeModel *model, GtkTreeIter *iter, gpo void font_lister_cell_data_func (Gtk::CellRenderer *renderer, Gtk::TreeIter const &iter) { Inkscape::FontLister* font_lister = Inkscape::FontLister::get_instance(); - Gtk::TreeModel::Row row = *iter; - - Glib::ustring family = row[font_lister->FontList.family]; - bool onSystem = row[font_lister->FontList.onSystem]; - - Glib::ustring family_escaped = Glib::strescape( family ); - Glib::ustring markup; - - if (!onSystem) { - markup = "<span foreground='darkblue'>"; - - // See if font-family is on system (separately for each family in font stack). - std::vector<Glib::ustring> tokens = Glib::Regex::split_simple("\\s*,\\s*", family); - - for (auto token: tokens) { - bool found = false; - Gtk::TreeModel::Children children = font_lister->get_font_list()->children(); - for (auto iter2: children) { - Gtk::TreeModel::Row row2 = *iter2; - Glib::ustring family2 = row2[font_lister->FontList.family]; - bool onSystem2 = row2[font_lister->FontList.onSystem]; - if (onSystem2 && familyNamesAreEqual(token, family)) { - found = true; - break; - } - } - - if (found) { - markup += Glib::strescape (token); - markup += ", "; - } else { - markup += "<span strikethrough=\"true\" strikethrough_color=\"red\">"; - markup += Glib::strescape (token); - markup += "</span>"; - markup += ", "; - } - } - - // Remove extra comma and space from end. - if (markup.size() >= 2) { - markup.resize(markup.size() - 2); - } - markup += "</span>"; - - } else { - markup = family_escaped; - } - - 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"); - - markup += " <span foreground='gray' font_family='"; - markup += family_escaped; - markup += "'>"; - markup += sample; - markup += "</span>"; - } - - // std::cout << "Markup: " << markup << std::endl; - + Glib::ustring markup = font_lister->get_font_family_markup(iter); renderer->set_property("markup", markup); } diff --git a/src/libnrtype/font-lister.h b/src/libnrtype/font-lister.h index 7125cc0f4..c505b3b18 100644 --- a/src/libnrtype/font-lister.h +++ b/src/libnrtype/font-lister.h @@ -58,6 +58,9 @@ namespace Inkscape { * then a generic font-family should be used (sans-serif -> Sans). * * This class is used by the UI interface (text-toolbar, font-select, etc.). + * Those items can change the selected font family and style here. When that + * happens. this class emits a signal for those items to update their displayed + * values. * * This class is a singleton (one instance per Inkscape session). Since fonts * used in a document are added to the list, there really should be one @@ -252,10 +255,14 @@ public: */ void fill_css(SPCSSAttr *css, Glib::ustring fontspec = ""); + Gtk::TreeModel::Row get_row_for_font() { return get_row_for_font (current_family); } + Gtk::TreeModel::Row get_row_for_font(Glib::ustring family); Gtk::TreePath get_path_for_font(Glib::ustring family); + Gtk::TreeModel::Row get_row_for_style() { return get_row_for_style (current_style); } + Gtk::TreeModel::Row get_row_for_style(Glib::ustring style); Gtk::TreePath get_path_for_style(Glib::ustring style); @@ -273,12 +280,17 @@ public: void ensureRowStyles(Glib::RefPtr<Gtk::TreeModel> model, Gtk::TreeModel::iterator const iter); /** + * Get markup for font-family. + */ + Glib::ustring get_font_family_markup(Gtk::TreeIter const &iter); + + /** * Let users of FontLister know to update GUI. * This is to allow synchronization of changes across multiple widgets. * Handlers should block signals. * Input is fontspec to set. */ - sigc::connection connectUpdate(sigc::slot<void, Glib::ustring> slot) { + sigc::connection connectUpdate(sigc::slot<void> slot) { return update_signal.connect(slot); } @@ -307,7 +319,7 @@ private: bool block; void emit_update(); - sigc::signal<void, Glib::ustring> update_signal; + sigc::signal<void> update_signal; }; } // namespace Inkscape diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 029c00126..75f84e429 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -138,6 +138,7 @@ set(ui_SRC widget/filter-effect-chooser.cpp widget/font-button.cpp widget/font-selector.cpp + widget/font-selector-toolbar.cpp widget/font-variants.cpp widget/frame.cpp widget/highlight-picker.cpp @@ -333,6 +334,7 @@ set(ui_SRC widget/filter-effect-chooser.h widget/font-button.h widget/font-selector.h + widget/font-selector-toolbar.h widget/font-variants.h widget/frame.h widget/highlight-picker.h diff --git a/src/ui/dialog/glyphs.cpp b/src/ui/dialog/glyphs.cpp index 07973b4c0..0a62fd8c1 100644 --- a/src/ui/dialog/glyphs.cpp +++ b/src/ui/dialog/glyphs.cpp @@ -336,9 +336,9 @@ GlyphsPanel::GlyphsPanel() : { fontSelector = new Inkscape::UI::Widget::FontSelector (false); - fontSelector->set_fontsize_visible (false); - fontSelector->set_size (12.0); fontSelector->set_name ("Glyphs"); + fontSelector->set_fontsize_visible (false); + fontSelector->update_size (12.0); sigc::connection conn = fontSelector->connectChanged(sigc::hide(sigc::mem_fun(*this, &GlyphsPanel::rebuild))); @@ -636,11 +636,8 @@ void GlyphsPanel::readSelection( bool updateStyle, bool updateContent ) // Update family/style based on selection. fontlister->selection_update(); - // Get fontspec for selection. - Glib::ustring fontspec = fontlister->get_fontspec(); - - // Update GUI. - fontSelector->set_fontspec (fontspec); + // Update GUI (based on fontlister values). + fontSelector->update_font (); } } diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp index 2c122da49..d283e6549 100644 --- a/src/ui/dialog/text-edit.cpp +++ b/src/ui/dialog/text-edit.cpp @@ -248,16 +248,16 @@ void TextEdit::onReadSelection ( gboolean dostyle, gboolean /*docontent*/ ) // Update family/style based on selection. font_lister->selection_update(); - - // Get fontspec for selection. Glib::ustring fontspec = font_lister->get_fontspec(); - font_selector.set_fontspec (fontspec); + + // Update Font Face. + font_selector.update_font (); // Update Size. Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT); double size = sp_style_css_size_px_to_units(query.font_size.computed, unit); - font_selector.set_size (size); + font_selector.update_size (size); // Update Preview setPreviewText (fontspec, phrase); diff --git a/src/ui/widget/font-selector-toolbar.cpp b/src/ui/widget/font-selector-toolbar.cpp new file mode 100644 index 000000000..c997e0920 --- /dev/null +++ b/src/ui/widget/font-selector-toolbar.cpp @@ -0,0 +1,303 @@ +/* + * Author: + * Tavmjong Bah <tavmjong@free.fr> + * + * Copyright (C) 2018 Tavmong Bah + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <glibmm/i18n.h> +#include <glibmm/regex.h> + +#include "font-selector-toolbar.h" + +#include "libnrtype/font-lister.h" +#include "libnrtype/font-instance.h" + +#include "ui/icon-names.h" + +// For updating from selection +#include "inkscape.h" +#include "desktop.h" +#include "object/sp-text.h" + +// TEMP TEMP TEMP +#include "widgets/text-toolbar.h" + +/* To do: + * Fix altx. Need to store + */ + +void family_cell_data_func(const Gtk::TreeModel::const_iterator iter, Gtk::CellRendererText* cell ) { + + Inkscape::FontLister* font_lister = Inkscape::FontLister::get_instance(); + Glib::ustring markup = font_lister->get_font_family_markup(iter); + // std::cout << "Markup: " << markup << std::endl; + + cell->set_property ("markup", markup); +} + +namespace Inkscape { +namespace UI { +namespace Widget { + +FontSelectorToolbar::FontSelectorToolbar () + : Gtk::Grid () + , family_combo (true) // true => with text entry. + , style_combo (true) + , signal_block (false) +{ + + Inkscape::FontLister* font_lister = Inkscape::FontLister::get_instance(); + + // Font family + family_combo.set_model (font_lister->get_font_list()); + family_combo.set_entry_text_column (0); + family_combo.set_name ("FontSelectorToolBar: Family"); + family_combo.set_row_separator_func (&font_lister_separator_func); + + family_combo.clear(); // Clears all CellRenderer mappings. + family_combo.set_cell_data_func (family_cell, + sigc::bind(sigc::ptr_fun(family_cell_data_func), &family_cell)); + family_combo.pack_start (family_cell); + + + Gtk::Entry* entry = family_combo.get_entry(); + entry->signal_icon_press().connect (sigc::mem_fun(*this, &FontSelectorToolbar::on_icon_pressed)); + entry->signal_key_press_event().connect (sigc::mem_fun(*this, &FontSelectorToolbar::on_key_press_event), false); // false => connect first + entry->set_data (Glib::Quark("altx-text"), entry); // Desktop will set focus to entry with Alt-x. + + + Glib::RefPtr<Gtk::EntryCompletion> completion = Gtk::EntryCompletion::create(); + completion->set_model (font_lister->get_font_list()); + completion->set_text_column (0); + completion->set_popup_completion (); + completion->set_inline_completion (false); + completion->set_inline_selection (); + // completion->signal_match_selected().connect(sigc::mem_fun(*this, &FontSelectorToolbar::on_match_selected), false); // false => connect before default handler. + entry->set_completion (completion); + + // Style + style_combo.set_model (font_lister->get_style_list()); + style_combo.set_name ("FontSelectorToolbar: Style"); + + // Grid + set_name ("FontSelectorToolbar: Grid"); + attach (family_combo, 0, 0, 1, 1); + attach (style_combo, 1, 0, 1, 1); + + // Add signals + family_combo.signal_changed().connect (sigc::mem_fun(*this, &FontSelectorToolbar::on_family_changed)); + style_combo.signal_changed().connect (sigc::mem_fun(*this, &FontSelectorToolbar::on_style_changed)); + + show_all_children(); + + // Initialize font family lists. (May already be done.) Should be done on document change. + font_lister->update_font_list(SP_ACTIVE_DESKTOP->getDocument()); + + // When FontLister is changed, update family and style shown in GUI. + font_lister->connectUpdate(sigc::mem_fun(*this, &FontSelectorToolbar::update_font)); +} + + +// Update GUI based on font-selector values. +void +FontSelectorToolbar::update_font () +{ + if (signal_block) return; + + signal_block = true; + + Inkscape::FontLister* font_lister = Inkscape::FontLister::get_instance(); + Gtk::TreeModel::Row row; + + // Set font family. + try { + row = font_lister->get_row_for_font (); + family_combo.set_active (row); + } catch (...) { + std::cerr << "FontSelectorToolbar::update_font: Couldn't find row for family: " + << font_lister->get_font_family() << std::endl; + } + + // Set style. + try { + row = font_lister->get_row_for_style (); + style_combo.set_active (row); + } catch (...) { + std::cerr << "FontSelectorToolbar::update_font: Couldn't find row for style: " + << font_lister->get_font_style() << std::endl; + } + + // Check for missing fonts. + Glib::ustring missing_fonts = get_missing_fonts(); + + // Add an icon to end of entry. + Gtk::Entry* entry = family_combo.get_entry(); + if (missing_fonts.empty()) { + // If no missing fonts, add icon for selecting all objects with this font-family. + entry->set_icon_from_icon_name (INKSCAPE_ICON("edit-select-all"), Gtk::ENTRY_ICON_SECONDARY); + entry->set_icon_tooltip_text (_("Select all text with this text family"), Gtk::ENTRY_ICON_SECONDARY); + } else { + // If missing fonts, add warning icon. + Glib::ustring warning = _("Font not found on system: ") + missing_fonts; + entry->set_icon_from_icon_name (INKSCAPE_ICON("dialog-warning"), Gtk::ENTRY_ICON_SECONDARY); + entry->set_icon_tooltip_text (warning, Gtk::ENTRY_ICON_SECONDARY); + } + + signal_block = false; +} + +// Get comma separated list of fonts in font-family that are not on system. +// To do, move to font-lister. +Glib::ustring +FontSelectorToolbar::get_missing_fonts () +{ + // Get font list in text entry which may be a font stack (with fallbacks). + Glib::ustring font_list = family_combo.get_entry_text(); + Glib::ustring missing_font_list; + Inkscape::FontLister* font_lister = Inkscape::FontLister::get_instance(); + + std::vector<Glib::ustring> tokens = Glib::Regex::split_simple("\\s*,\\s*", font_list); + + for (auto token: tokens) { + bool found = false; + Gtk::TreeModel::Children children = font_lister->get_font_list()->children(); + for (auto iter2: children) { + Gtk::TreeModel::Row row2 = *iter2; + Glib::ustring family2 = row2[font_lister->FontList.family]; + bool onSystem2 = row2[font_lister->FontList.onSystem]; + // CSS dictates that font family names are case insensitive. + // This should really implement full Unicode case unfolding. + if (onSystem2 && token.casefold().compare(family2.casefold()) == 0) { + found = true; + break; + } + } + + if (!found) { + missing_font_list += token; + missing_font_list += ", "; + } + } + + // Remove extra comma and space from end. + if (missing_font_list.size() >= 2) { + missing_font_list.resize(missing_font_list.size() - 2); + } + + return missing_font_list; +} + + +// Callbacks + +// Need to update style list +void +FontSelectorToolbar::on_family_changed() { + + if (signal_block) return; + signal_block = true; + + Glib::ustring family = family_combo.get_entry_text(); + + Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); + fontlister->set_font_family (family); + + signal_block = false; + + // Let world know + changed_emit(); +} + +void +FontSelectorToolbar::on_style_changed() { + + if (signal_block) return; + signal_block = true; + + Glib::ustring style = style_combo.get_entry_text(); + + Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); + fontlister->set_font_style (style); + + signal_block = false; + + // Let world know + changed_emit(); +} + +void +FontSelectorToolbar::on_icon_pressed (Gtk::EntryIconPosition icon_position, const GdkEventButton* event) { + std::cout << "FontSelectorToolbar::on_entry_icon_pressed" << std::endl; + std::cout << " .... Should select all items with same font-family. FIXME" << std::endl; + // Call equivalent of sp_text_toolbox_select_cb() in text-toolbar.cpp + // Should be action! (Maybe: select_all_fontfamily( Glib::ustring font_family );). + // Check how Find dialog works. +} + +// bool +// FontSelectorToolbar::on_match_selected (const Gtk::TreeModel::iterator& iter) +// { +// std::cout << "on_match_selected" << std::endl; +// std::cout << " FIXME" << std::endl; +// Inkscape::FontLister* font_lister = Inkscape::FontLister::get_instance(); +// Glib::ustring family = (*iter)[font_lister->FontList.family]; +// std::cout << " family: " << family << std::endl; +// return false; // Leave it to default handler to set entry text. +// } + +// Return focus to canvas. +bool +FontSelectorToolbar::on_key_press_event (GdkEventKey* key_event) +{ + bool consumed = false; + + unsigned int key = 0; + gdk_keymap_translate_keyboard_state( gdk_keymap_get_for_display( gdk_display_get_default() ), + key_event->hardware_keycode, + (GdkModifierType)key_event->state, + 0, &key, 0, 0, 0 ); + + switch ( key ) { + + case GDK_KEY_Escape: + case GDK_KEY_Return: + case GDK_KEY_KP_Enter: + { + // Defocus + std::cerr << "FontSelectorToolbar::on_key_press_event: Defocus: FIXME" << std::endl; + consumed = true; + } + break; + } + + return consumed; // Leave it to default handler if false. +} + +void +FontSelectorToolbar::changed_emit() { + signal_block = true; + changed_signal.emit (); + signal_block = false; +} + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8 : diff --git a/src/ui/widget/font-selector-toolbar.h b/src/ui/widget/font-selector-toolbar.h new file mode 100644 index 000000000..5600982c6 --- /dev/null +++ b/src/ui/widget/font-selector-toolbar.h @@ -0,0 +1,119 @@ +/* + * Author: + * Tavmjong Bah <tavmjong@free.fr> + * + * Copyright (C) 2018 Tavmong Bah + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + * + * + * The routines here create and manage a font selector widget with two parts, + * one each for font-family and font-style. + * + * This is esentially a toolbar version of the 'FontSelector' widget. Someday + * this may be merged with it. + * + * The main functions are: + * Create the font-selector toolbar widget. + * Update the lists when a new text selection is made. + * Update the Style list when a new font-family is selected, highlighting the + * best match to the original font style (as not all fonts have the same style options). + * Update the on-screen text. + * Provide the currently selected values. + */ + +#ifndef INKSCAPE_UI_WIDGET_FONT_SELECTOR_TOOLBAR_H +#define INKSCAPE_UI_WIDGET_FONT_SELECTOR_TOOLBAR_H + +#include <gtkmm/grid.h> +#include <gtkmm/treeview.h> +#include <gtkmm/comboboxtext.h> + +namespace Inkscape { +namespace UI { +namespace Widget { + +/** + * A container of widgets for selecting font faces. + * + * It is used by Text tool toolbar. The FontSelectorToolbar class utilizes the + * FontLister class to obtain a list of font-families and their associated styles for fonts either + * on the system or in the document. The FontLister class is also used by the Text toolbar. Fonts + * are kept track of by their "fontspecs" which are the same as the strings that Pango generates. + * + * The main functions are: + * Create the font-selector widget. + * Update the child widgets when a new text selection is made. + * Update the Style list when a new font-family is selected, highlighting the + * best match to the original font style (as not all fonts have the same style options). + * Emit a signal when any change is made to a child widget. + */ +class FontSelectorToolbar : public Gtk::Grid +{ + +public: + + /** + * Constructor + */ + FontSelectorToolbar (); + +protected: + + // Font family + Gtk::ComboBox family_combo; + Gtk::CellRendererText family_cell; + + // Font style + Gtk::ComboBoxText style_combo; + Gtk::CellRendererText style_cell; + +private: + + // Make a list of missing fonts for tooltip and for warning icon. + Glib::ustring get_missing_fonts (); + + // Signal handlers + void on_family_changed(); + void on_style_changed(); + void on_icon_pressed (Gtk::EntryIconPosition icon_position, const GdkEventButton* event); + // bool on_match_selected (const Gtk::TreeModel::iterator& iter); + bool on_key_press_event (GdkEventKey* key_event); + + // Signals + sigc::signal<void> changed_signal; + void changed_emit(); + bool signal_block; + +public: + + /** + * Update GUI based on font-selector values. + */ + void update_font (); + + /** + * Let others know that user has changed GUI settings. + */ + sigc::connection connectChanged(sigc::slot<void> slot) { + return changed_signal.connect(slot); + } +}; + + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +#endif // INKSCAPE_UI_WIDGET_FONT_SETTINGS_TOOLBAR_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8 : diff --git a/src/ui/widget/font-selector.cpp b/src/ui/widget/font-selector.cpp index 5873802d5..fcc51ddd1 100644 --- a/src/ui/widget/font-selector.cpp +++ b/src/ui/widget/font-selector.cpp @@ -99,7 +99,7 @@ FontSelector::FontSelector (bool with_size) // Initialize font family lists. (May already be done.) Should be done on document change. font_lister->update_font_list(SP_ACTIVE_DESKTOP->getDocument()); - font_lister->connectUpdate(sigc::mem_fun(*this, &FontSelector::set_fontspec)); + font_lister->connectUpdate(sigc::mem_fun(*this, &FontSelector::update_font)); } void @@ -135,60 +135,62 @@ FontSelector::set_fontsize_tooltip() size_combobox.set_tooltip_text (tooltip); } -// Update GUI. TODO: Rename function +// Update GUI. +// We keep a private copy of the style list as the font-family in widget is only temporary +// until the "Apply" button is set so the style list can be different from that in +// FontLister. void -FontSelector::set_fontspec (const Glib::ustring& fontspec) +FontSelector::update_font () { signal_block = true; - if (!fontspec.empty()) { - Inkscape::FontLister *font_lister = Inkscape::FontLister::get_instance(); - std::pair<Glib::ustring, Glib::ustring> ui = font_lister->ui_from_fontspec( fontspec ); - Glib::ustring family = ui.first; - Glib::ustring style = ui.second; - Gtk::TreePath path; - - // Set font family - try { - path = font_lister->get_row_for_font (family); - } catch (...) { - g_warning( "Couldn't find row for font-family: %s", family.c_str() ); - path.clear(); - path.push_back(0); - } - family_treeview.set_cursor (path); - family_treeview.scroll_to_row (path); - - // Get font-lister style list for selected family - Gtk::TreeModel::Row row = font_lister->get_row_for_font (family); - GList *styles; - row.get_value(1, styles); - - // Copy font-lister style list to private list store, searching for match. - Gtk::TreeModel::iterator match; - FontLister::FontStyleListClass FontStyleList; - Glib::RefPtr<Gtk::ListStore> local_style_list_store = Gtk::ListStore::create(FontStyleList); - for ( ; styles; styles = styles->next ) { - Gtk::TreeModel::iterator treeModelIter = local_style_list_store->append(); - (*treeModelIter)[FontStyleList.cssStyle] = ((StyleNames *)styles->data)->CssName; - (*treeModelIter)[FontStyleList.displayStyle] = ((StyleNames *)styles->data)->DisplayName; - if (style == ((StyleNames*)styles->data)->CssName) { - match = treeModelIter; - } - } + Inkscape::FontLister *font_lister = Inkscape::FontLister::get_instance(); + Gtk::TreePath path; + Glib::ustring family = font_lister->get_font_family(); + Glib::ustring style = font_lister->get_font_style(); + + // Set font family + try { + path = font_lister->get_row_for_font (family); + } catch (...) { + std::cerr << "FontSelector::update_font: Couldn't find row for font-family: " + << family << std::endl; + path.clear(); + path.push_back(0); + } + + family_treeview.set_cursor (path); + family_treeview.scroll_to_row (path); + + // Get font-lister style list for selected family + Gtk::TreeModel::Row row = *(family_treeview.get_model()->get_iter (path)); + GList *styles; + row.get_value(1, styles); - // Attach store to tree view and select row. - style_treeview.set_model (local_style_list_store); - if (match) { - style_treeview.get_selection()->select (match); + // Copy font-lister style list to private list store, searching for match. + Gtk::TreeModel::iterator match; + FontLister::FontStyleListClass FontStyleList; + Glib::RefPtr<Gtk::ListStore> local_style_list_store = Gtk::ListStore::create(FontStyleList); + for ( ; styles; styles = styles->next ) { + Gtk::TreeModel::iterator treeModelIter = local_style_list_store->append(); + (*treeModelIter)[FontStyleList.cssStyle] = ((StyleNames *)styles->data)->CssName; + (*treeModelIter)[FontStyleList.displayStyle] = ((StyleNames *)styles->data)->DisplayName; + if (style == ((StyleNames*)styles->data)->CssName) { + match = treeModelIter; } } + // Attach store to tree view and select row. + style_treeview.set_model (local_style_list_store); + if (match) { + style_treeview.get_selection()->select (match); + } + signal_block = false; } void -FontSelector::set_size (double size) +FontSelector::update_size (double size) { signal_block = true; diff --git a/src/ui/widget/font-selector.h b/src/ui/widget/font-selector.h index 2fd4eee72..7578dc693 100644 --- a/src/ui/widget/font-selector.h +++ b/src/ui/widget/font-selector.h @@ -35,11 +35,6 @@ #include <gtkmm/label.h> #include <gtkmm/comboboxtext.h> -// class SPDesktop; -// class SPObject; -class SPStyle; -class SPCSSAttr; - namespace Inkscape { namespace UI { namespace Widget { @@ -116,8 +111,8 @@ public: /** * Update GUI based on fontspec */ - void set_fontspec (const Glib::ustring& fontspec); - void set_size (double size); + void update_font (); + void update_size (double size); /** * Get fontspec based on current settings. (Does not handle size, yet.) |
