From 67fe8d66b29c309f316fa4ae952b0ea5b39db431 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Thu, 5 Sep 2024 22:33:36 +0200 Subject: [PATCH] LibWeb: Skip font if it doesn't contain needed glyph in FontCascadeList Before this change, we were only checking for actual glyph containment in a font if unicode ranges were specified. However that is not sufficient for emoji support, where we want to continue searching for a font until one containing emojis is found. --- Userland/Libraries/LibGfx/FontCascadeList.cpp | 14 +++++++------- Userland/Libraries/LibGfx/FontCascadeList.h | 7 +++++-- Userland/Libraries/LibWeb/CSS/StyleComputer.cpp | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Userland/Libraries/LibGfx/FontCascadeList.cpp b/Userland/Libraries/LibGfx/FontCascadeList.cpp index b83f6364d60..4deafb0986d 100644 --- a/Userland/Libraries/LibGfx/FontCascadeList.cpp +++ b/Userland/Libraries/LibGfx/FontCascadeList.cpp @@ -28,16 +28,16 @@ void FontCascadeList::extend(FontCascadeList const& other) Gfx::Font const& FontCascadeList::font_for_code_point(u32 code_point) const { for (auto const& entry : m_fonts) { - if (!entry.unicode_ranges.has_value()) + if (entry.unicode_ranges.has_value()) { + for (auto const& range : *entry.unicode_ranges) { + if (range.contains(code_point) && entry.font->contains_glyph(code_point)) + return entry.font; + } + } else if (entry.font->contains_glyph(code_point)) { return entry.font; - if (!entry.font->contains_glyph(code_point)) - continue; - for (auto const& range : *entry.unicode_ranges) { - if (range.contains(code_point)) - return entry.font; } } - VERIFY_NOT_REACHED(); + return *m_last_resort_font; } bool FontCascadeList::equals(FontCascadeList const& other) const diff --git a/Userland/Libraries/LibGfx/FontCascadeList.h b/Userland/Libraries/LibGfx/FontCascadeList.h index 999ecf97dfb..681021e82c0 100644 --- a/Userland/Libraries/LibGfx/FontCascadeList.h +++ b/Userland/Libraries/LibGfx/FontCascadeList.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Aliaksandr Kalenik + * Copyright (c) 2023-2024, Aliaksandr Kalenik * * SPDX-License-Identifier: BSD-2-Clause */ @@ -19,7 +19,7 @@ public: } size_t size() const { return m_fonts.size(); } - bool is_empty() const { return m_fonts.is_empty(); } + bool is_empty() const { return m_fonts.is_empty() && !m_last_resort_font; } Font const& first() const { return *m_fonts.first().font; } template @@ -43,7 +43,10 @@ public: Optional> unicode_ranges; }; + void set_last_resort_font(NonnullRefPtr font) { m_last_resort_font = move(font); } + private: + RefPtr m_last_resort_font; Vector m_fonts; }; diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 554eff120a0..e65a3ffed76 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -2326,7 +2326,7 @@ RefPtr StyleComputer::compute_font_for_style_values( } auto found_font = StyleProperties::font_fallback(monospace, bold); - font_list->add(found_font->with_size(font_size_in_pt)); + font_list->set_last_resort_font(found_font->with_size(font_size_in_pt)); return font_list; }