diff --git a/include/cairo/context.hpp b/include/cairo/context.hpp index 75ef4636..98623d38 100644 --- a/include/cairo/context.hpp +++ b/include/cairo/context.hpp @@ -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> fns(m_fonts.begin(), m_fonts.end()); - std::sort(fns.begin(), fns.end(), [&](const shared_ptr& a, const shared_ptr&) { - 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;