From 9c8da4374de23fddc8268ddac4e55e82f3e8c868 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 25 May 2023 12:54:01 +0200 Subject: [PATCH] LibWeb: Try failed font lookups again without weight and slope If CSS requests a font that we have loaded, but we didn't associate it with a specific weight and/or slope, let's still use it if it matches the family name. This is a hack until we implement proper CSS font selection. --- Userland/Libraries/LibWeb/CSS/StyleComputer.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index f06d5e6809..8db216d532 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -1285,6 +1285,16 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele return found_font; } + // We couldn't find this font with a specific weight and slope, so try again without them. + // FIXME: This should be replaced by a proper CSS font selection algorithm. + key.weight = 0; + key.slope = 0; + if (auto it = m_loaded_fonts.find(key); it != m_loaded_fonts.end()) { + auto& loader = *it->value; + if (auto found_font = loader.font_with_point_size(font_size_in_pt)) + return found_font; + } + if (auto found_font = FontCache::the().get(font_selector)) return found_font;