fix(cairo): Fix font prioritization

In the previous implementation, std::find() returned fns.end() several times,
which caused an "Address boundary error" in std::sort if the preferred
font-index was set to m_fonts.size() + 1.

This commit reimplements the font prioritization with a simple swap.

Reproduction steps:

- Start polybar with the following config:

  [bar/top]
  font-0 = NotoSans-Regular:size=8;0
  font-1 = MaterialIcons:size=10;0

  modules-left = date

  [module/date]
  type = internal/date
  date = %Y-%m-%d
  label-font = 3 ; invalid index
This commit is contained in:
László Várady 2017-01-28 23:26:42 +01:00 committed by Michael Carlberg
parent 8a98fb78b6
commit 701102d44b
1 changed files with 5 additions and 9 deletions

View File

@ -145,16 +145,12 @@ namespace cairo {
double x, y;
position(&x, &y);
// Sort the fontlist so that the
// preferred font gets prioritized
// Prioritize the preferred font
vector<shared_ptr<font>> fns(m_fonts.begin(), m_fonts.end());
std::sort(fns.begin(), fns.end(), [&](const shared_ptr<font>& a, const shared_ptr<font>&) {
if (t.font > 0 && std::distance(fns.begin(), std::find(fns.begin(), fns.end(), a)) == t.font - 1) {
return -1;
} else {
return 0;
}
});
if (t.font > 0 && t.font <= std::distance(fns.begin(), fns.end())) {
std::iter_swap(fns.begin(), fns.begin() + t.font - 1);
}
string utf8 = string(t.contents);
utils::unicode_charlist chars;