summaryrefslogtreecommitdiffstats
path: root/src/libnrtype
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2018-04-25 14:29:08 +0000
committerTavmjong Bah <tavmjong@free.fr>2018-04-25 14:29:08 +0000
commitc259adc37c0b0df32a28d70e51d7fde0968b4cdc (patch)
tree275c61d132acae5b1d90f45f2e7a6c38159aeebb /src/libnrtype
parentfix bug on compile (diff)
downloadinkscape-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/libnrtype')
-rw-r--r--src/libnrtype/font-lister.cpp133
-rw-r--r--src/libnrtype/font-lister.h16
2 files changed, 83 insertions, 66 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