diff --git a/Userland/Libraries/LibGfx/Font/Font.h b/Userland/Libraries/LibGfx/Font/Font.h index 21e3c37812..7049e80658 100644 --- a/Userland/Libraries/LibGfx/Font/Font.h +++ b/Userland/Libraries/LibGfx/Font/Font.h @@ -148,6 +148,8 @@ public: enum class AllowInexactSizeMatch { No, Yes, + Larger, + Smaller, }; virtual NonnullRefPtr clone() const = 0; diff --git a/Userland/Libraries/LibGfx/Font/Typeface.cpp b/Userland/Libraries/LibGfx/Font/Typeface.cpp index 922749bb82..56a1a47762 100644 --- a/Userland/Libraries/LibGfx/Font/Typeface.cpp +++ b/Userland/Libraries/LibGfx/Font/Typeface.cpp @@ -73,16 +73,22 @@ RefPtr Typeface::get_font(float point_size, Font::AllowInexactSizeMatch al for (auto font : m_bitmap_fonts) { if (font->presentation_size() == size) return font; - if (allow_inexact_size_match == Font::AllowInexactSizeMatch::Yes) { + if (allow_inexact_size_match != Font::AllowInexactSizeMatch::No) { int delta = static_cast(font->presentation_size()) - static_cast(size); - if (abs(delta) < best_delta) { + if (abs(delta) == best_delta) { + if (allow_inexact_size_match == Font::AllowInexactSizeMatch::Larger && delta > 0) { + best_match = font; + } else if (allow_inexact_size_match == Font::AllowInexactSizeMatch::Smaller && delta < 0) { + best_match = font; + } + } else if (abs(delta) < best_delta) { best_match = font; best_delta = abs(delta); } } } - if (allow_inexact_size_match == Font::AllowInexactSizeMatch::Yes && best_match) + if (allow_inexact_size_match != Font::AllowInexactSizeMatch::No && best_match) return best_match; return {};