From cee97dcaa96d31ad707a3a6c92ee0fb9184eec59 Mon Sep 17 00:00:00 2001 From: mikekov Date: Sun, 8 Dec 2019 09:32:39 -0800 Subject: [PATCH] Text and Font resizing improvements --- src/ui/dialog/text-edit.cpp | 20 +++++++++++++++++++- src/ui/widget/font-selector.cpp | 25 ++++++++++++++++++------- src/ui/widget/font-selector.h | 3 +++ src/ui/widget/font-variations.cpp | 6 +++++- src/ui/widget/font-variations.h | 5 ++++- 5 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp index d07223b9a3..1ef5ee4266 100644 --- a/src/ui/dialog/text-edit.cpp +++ b/src/ui/dialog/text-edit.cpp @@ -284,8 +284,26 @@ void TextEdit::setPreviewText (Glib::ustring font_spec, Glib::ustring font_featu return; } + // Limit number of lines in preview to arbitrary amount to prevent Text and Font dialog + // from growing taller than a desktop + const int max_lines = 4; + // Ignore starting empty lines; they would show up as nothing + auto start_pos = phrase.find_first_not_of(" \n\r\t"); + if (start_pos == Glib::ustring::npos) { + start_pos = 0; + } + // Now take up to max_lines + auto end_pos = Glib::ustring::npos; + auto from = start_pos; + for (int i = 0; i < max_lines; ++i) { + end_pos = phrase.find("\n", from); + if (end_pos == Glib::ustring::npos) { break; } + from = end_pos + 1; + } + Glib::ustring phrase_trimmed = phrase.substr(start_pos, end_pos != Glib::ustring::npos ? end_pos - start_pos : end_pos); + Glib::ustring font_spec_escaped = Glib::Markup::escape_text( font_spec ); - Glib::ustring phrase_escaped = Glib::Markup::escape_text( phrase ); + Glib::ustring phrase_escaped = Glib::Markup::escape_text(phrase_trimmed); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT); diff --git a/src/ui/widget/font-selector.cpp b/src/ui/widget/font-selector.cpp index d8897eb3a9..9a3ab5a97f 100644 --- a/src/ui/widget/font-selector.cpp +++ b/src/ui/widget/font-selector.cpp @@ -91,14 +91,17 @@ FontSelector::FontSelector (bool with_size, bool with_variations) set_name ("FontSelectorGrid"); set_row_spacing(4); set_column_spacing(4); - attach (family_frame, 0, 0, 1, 2); - attach (style_frame, 1, 0, 2, 1); + // Add extra columns to the "family frame" to change space distribution + // by prioritizing font family over styles + const int extra = 4; + attach (family_frame, 0, 0, 1 + extra, 2); + attach (style_frame, 1 + extra, 0, 2, 1); if (with_size) { // Glyph panel does not use size. - attach (size_label, 1, 1, 1, 1); - attach (size_combobox, 2, 1, 1, 1); + attach (size_label, 1 + extra, 1, 1, 1); + attach (size_combobox, 2 + extra, 1, 1, 1); } if (with_variations) { // Glyphs panel does not use variations. - attach (font_variations_scroll, 0, 2, 3, 1); + attach (font_variations_scroll, 0, 2, 3 + extra, 1); } // Add signals @@ -203,7 +206,7 @@ FontSelector::update_font () } Glib::ustring fontspec = font_lister->get_fontspec(); - font_variations.update( fontspec ); + update_variations(fontspec); signal_block = false; } @@ -368,7 +371,7 @@ FontSelector::on_style_changed() { // Update variations widget if new style selected from style widget. signal_block = true; Glib::ustring fontspec = get_fontspec( false ); - font_variations.update( fontspec ); + update_variations(fontspec); signal_block = false; // Let world know @@ -423,6 +426,14 @@ FontSelector::changed_emit() { signal_block = false; } +void FontSelector::update_variations(const Glib::ustring& fontspec) { + font_variations.update(fontspec); + + // Check if there are any variations available; if not, don't expand font_variations_scroll + bool hasContent = font_variations.variations_present(); + font_variations_scroll.set_vexpand(hasContent); +} + } // namespace Widget } // namespace UI } // namespace Inkscape diff --git a/src/ui/widget/font-selector.h b/src/ui/widget/font-selector.h index 9e4dec3bf8..137d4116bb 100644 --- a/src/ui/widget/font-selector.h +++ b/src/ui/widget/font-selector.h @@ -114,6 +114,9 @@ private: // Variables double font_size; + // control font variations update and UI element size + void update_variations(const Glib::ustring& fontspec); + public: /** diff --git a/src/ui/widget/font-variations.cpp b/src/ui/widget/font-variations.cpp index f585710c48..fae5cc3ad5 100644 --- a/src/ui/widget/font-variations.cpp +++ b/src/ui/widget/font-variations.cpp @@ -67,7 +67,7 @@ FontVariations::FontVariations () : // Update GUI based on query. void -FontVariations::update (Glib::ustring& font_spec) { +FontVariations::update (const Glib::ustring& font_spec) { font_instance* res = font_factory::Default()->FaceFromFontSpecification (font_spec.c_str()); @@ -159,6 +159,10 @@ FontVariations::on_variations_change() { signal_changed.emit (); } +bool FontVariations::variations_present() const { + return !axes.empty(); +} + } // namespace Widget } // namespace UI } // namespace Inkscape diff --git a/src/ui/widget/font-variations.h b/src/ui/widget/font-variations.h index 8ee7fd0881..a3d38962cc 100644 --- a/src/ui/widget/font-variations.h +++ b/src/ui/widget/font-variations.h @@ -72,7 +72,7 @@ public: /** * Update GUI. */ - void update( Glib::ustring& font_spec ); + void update(const Glib::ustring& font_spec); /** * Fill SPCSSAttr based on settings of buttons. @@ -96,6 +96,9 @@ public: return signal_changed.connect(slot); } + // return true if there are some variations present + bool variations_present() const; + private: std::vector axes; -- GitLab