From 0ad29b463567262c562c845cd9cdc07971afde28 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 18 Mar 2019 11:15:33 +0100 Subject: Keep font variations widget in sync with CSS style widget. --- src/ui/widget/font-selector.cpp | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'src/ui/widget/font-selector.cpp') diff --git a/src/ui/widget/font-selector.cpp b/src/ui/widget/font-selector.cpp index dd33940fc..2263862a0 100644 --- a/src/ui/widget/font-selector.cpp +++ b/src/ui/widget/font-selector.cpp @@ -219,8 +219,10 @@ FontSelector::update_size (double size) } +// If use_variations is true (default), we get variation values from variations widget otherwise we +// get values from CSS widget (we need to be able to keep the two widgets synchronized both ways). Glib::ustring -FontSelector::get_fontspec() { +FontSelector::get_fontspec(bool use_variations) { // Build new fontspec from GUI settings Glib::ustring family = "Sans"; // Default...family list may not have been constructed. @@ -243,18 +245,23 @@ FontSelector::get_fontspec() { std::cerr << "FontSelector::get_fontspec: empty style!" << std::endl; } - // Clip any font_variation data in 'style' as we'll replace it. - if (auto pos = style.find('@') != Glib::ustring::npos) { - style.erase (pos, style.length()-1); - } + Glib::ustring fontspec = family + " "; - Glib::ustring variations = font_variations.get_pango_string(); + if (use_variations) { + // Clip any font_variation data in 'style' as we'll replace it. + if (auto pos = style.find('@') != Glib::ustring::npos) { + style.erase (pos, style.length()-1); + } - Glib::ustring fontspec = family + " "; - if (variations.empty()) { - fontspec += style; + Glib::ustring variations = font_variations.get_pango_string(); + + if (variations.empty()) { + fontspec += style; + } else { + fontspec += variations; + } } else { - fontspec += variations; + fontspec += style; } return fontspec; @@ -350,9 +357,14 @@ FontSelector::on_family_changed() { void FontSelector::on_style_changed() { - if (signal_block) return; + // Update variations widget if new style selected from style widget. + signal_block = true; + Glib::ustring fontspec = get_fontspec( false ); + font_variations.update( fontspec ); + signal_block = false; + // Let world know changed_emit(); } -- cgit v1.2.3