From 418f9ceadda62bb40584f92fddc3582593d3fbd4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 24 Aug 2023 20:05:55 +0200 Subject: [PATCH] LibWeb: Invalidate font cache when web fonts are downloaded In case we've looked up the family name before and cached the result of font fallback, we now invalidate any cached entries with the same family name so that the next lookup may consider the newly downloaded font. --- Userland/Libraries/LibWeb/CSS/StyleComputer.cpp | 3 ++- Userland/Libraries/LibWeb/FontCache.cpp | 7 +++++++ Userland/Libraries/LibWeb/FontCache.h | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 0c9f1c8dae..4567edee64 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -2794,8 +2794,9 @@ CSSPixelRect StyleComputer::viewport_rect() const return {}; } -void StyleComputer::did_load_font([[maybe_unused]] FlyString const& family_name) +void StyleComputer::did_load_font(FlyString const& family_name) { + m_font_cache.did_load_font({}, family_name); document().invalidate_style(); } diff --git a/Userland/Libraries/LibWeb/FontCache.cpp b/Userland/Libraries/LibWeb/FontCache.cpp index 3d293cc718..76b0c9a3c3 100644 --- a/Userland/Libraries/LibWeb/FontCache.cpp +++ b/Userland/Libraries/LibWeb/FontCache.cpp @@ -39,4 +39,11 @@ void FontCache::set(FontSelector const& font_selector, NonnullRefPtr, FlyString const& family_name) +{ + m_fonts.remove_all_matching([&family_name](auto& key, auto&) -> bool { + return key.family == family_name; + }); +} + } diff --git a/Userland/Libraries/LibWeb/FontCache.h b/Userland/Libraries/LibWeb/FontCache.h index abe4e0f0f5..fedb577193 100644 --- a/Userland/Libraries/LibWeb/FontCache.h +++ b/Userland/Libraries/LibWeb/FontCache.h @@ -35,6 +35,8 @@ public: NonnullRefPtr scaled_font(Gfx::Font const&, float scale_factor); + void did_load_font(Badge, FlyString const& family_name); + private: mutable HashMap> m_fonts; };