From a011694a17e17377d08e35b5fd128129f2f72992 Mon Sep 17 00:00:00 2001 From: jsfer Date: Fri, 5 Nov 2021 16:14:49 -0400 Subject: [PATCH] Fix: Subsequent font changes to words in the same textbox now apply Extract clump of into a private function FontLister.font_family_row_update() Add call to FontLister.font_family_row_update() in function FontLister.selection_update() There are many issues related but here is the one I looked at: https://gitlab.com/inkscape/inkscape/issues/2056 --- src/libnrtype/font-lister.cpp | 57 +++++++++++++++++++---------------- src/libnrtype/font-lister.h | 2 ++ 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/libnrtype/font-lister.cpp b/src/libnrtype/font-lister.cpp index 75ff172c05..66d27fce09 100644 --- a/src/libnrtype/font-lister.cpp +++ b/src/libnrtype/font-lister.cpp @@ -367,32 +367,7 @@ void FontLister::update_font_list(SPDocument *document) } - /* Now we do a song and dance to find the correct row as the row corresponding - * to the current_family may have changed. We can't simply search for the - * family name in the list since it can occur twice, once in the document - * font family part and once in the system font family part. Above we determined - * which part it is in. - */ - if (current_family_row > -1) { - int start = 0; - if (row_is_system) - start = font_data.size(); - int length = font_list_store->children().size(); - for (int i = 0; i < length; ++i) { - int row = i + start; - if (row >= length) - row -= length; - Gtk::TreePath path; - path.push_back(row); - Gtk::TreeModel::iterator iter = font_list_store->get_iter(path); - if (iter) { - if (familyNamesAreEqual(current_family, (*iter)[FontList.family])) { - current_family_row = row; - break; - } - } - } - } + font_family_row_update(row_is_system ? font_data.size() : 0); // std::cout << " Out: row: " << current_family_row << " " << current_family << std::endl; font_list_store->thaw_notify(); @@ -526,6 +501,33 @@ std::pair FontLister::ui_from_fontspec(Glib::ustri return std::make_pair(Family, Style); } +/* Now we do a song and dance to find the correct row as the row corresponding + * to the current_family may have changed. We can't simply search for the + * family name in the list since it can occur twice, once in the document + * font family part and once in the system font family part. Above we determined + * which part it is in. + */ +void FontLister::font_family_row_update(int start) +{ + if (this->current_family_row > -1 && start > -1) { + int length = this->font_list_store->children().size(); + for (int i = 0; i < length; ++i) { + int row = i + start; + if (row >= length) + row -= length; + Gtk::TreePath path; + path.push_back(row); + Gtk::TreeModel::iterator iter = this->font_list_store->get_iter(path); + if (iter) { + if (familyNamesAreEqual(this->current_family, (*iter)[FontList.family])) { + this->current_family_row = row; + break; + } + } + } + } +} + std::pair FontLister::selection_update() { #ifdef DEBUG_FONT @@ -574,6 +576,9 @@ std::pair FontLister::selection_update() //std::cout << " fontspec from thin air :" << fontspec << ":" << std::endl; } + // Need to update font family row too + font_family_row_update(); + std::pair ui = ui_from_fontspec(fontspec); set_font_family(ui.first); set_font_style(ui.second); diff --git a/src/libnrtype/font-lister.h b/src/libnrtype/font-lister.h index 769f021723..9c279cf842 100644 --- a/src/libnrtype/font-lister.h +++ b/src/libnrtype/font-lister.h @@ -305,6 +305,8 @@ private: void update_font_data_recursive(SPObject& r, std::map> &font_data); + void font_family_row_update(int start=0); + Glib::RefPtr font_list_store; Glib::RefPtr style_list_store; -- GitLab