Skip to content

Commit

Permalink
Fix layout failure when leading spaces before wide glyph (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakhnik committed Nov 5, 2022
1 parent 4f40c48 commit 7b9805c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/GGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,24 @@ void GGrid::_UpdateLabels(Session *session)
const std::string &pango_style = it == _pango_styles.end()
? _default_pango_style
: it->second;
text += "<span" + pango_style + ">" + XmlEscape(word.text) + "</span>";
text += "<span" + pango_style + ">";
// 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 += "<span font=\"" + _font.GetFamily() + "\">";
text += word.text.substr(0, spaces);
text += "</span>";
if (spaces != std::string::npos)
text += XmlEscape(word.text.substr(spaces));
}
else
{
text += XmlEscape(word.text);
}
text += "</span>";
}
Texture t{row, Gtk::Label::new_("").g_obj()};
t.label.set_markup(text.c_str());
Expand Down

0 comments on commit 7b9805c

Please sign in to comment.