From 7b9805c149bcab0fc50a960edd88ccc739a8d73c Mon Sep 17 00:00:00 2001 From: Anatolii Sakhnik Date: Sat, 5 Nov 2022 08:58:28 +0200 Subject: [PATCH] Fix layout failure when leading spaces before wide glyph (#53) --- src/GGrid.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/GGrid.cpp b/src/GGrid.cpp index 746596f..43e65cd 100644 --- a/src/GGrid.cpp +++ b/src/GGrid.cpp @@ -437,7 +437,24 @@ void GGrid::_UpdateLabels(Session *session) const std::string &pango_style = it == _pango_styles.end() ? _default_pango_style : it->second; - text += "" + XmlEscape(word.text) + ""; + text += ""; + // If a chunk starts with spaces and the first non-space character is + // has a wide glyph, spaces may be rendered too narrow. + // To cope with that, we could span spaces with explicit font. + auto spaces = word.text.find_first_not_of(" "); + if (spaces) + { + text += ""; + text += word.text.substr(0, spaces); + text += ""; + if (spaces != std::string::npos) + text += XmlEscape(word.text.substr(spaces)); + } + else + { + text += XmlEscape(word.text); + } + text += ""; } Texture t{row, Gtk::Label::new_("").g_obj()}; t.label.set_markup(text.c_str());