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.
This commit is contained in:
parent
107549dc86
commit
67fe8d66b2
Notes:
github-actions[bot]
2024-09-06 12:31:52 +00:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/LadybirdBrowser/ladybird/commit/67fe8d66b29 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1297 Reviewed-by: https://github.com/trflynn89
3 changed files with 13 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
* Copyright (c) 2023-2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* 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<typename Callback>
|
||||
|
@ -43,7 +43,10 @@ public:
|
|||
Optional<Vector<UnicodeRange>> unicode_ranges;
|
||||
};
|
||||
|
||||
void set_last_resort_font(NonnullRefPtr<Font> font) { m_last_resort_font = move(font); }
|
||||
|
||||
private:
|
||||
RefPtr<Font const> m_last_resort_font;
|
||||
Vector<Entry> m_fonts;
|
||||
};
|
||||
|
||||
|
|
|
@ -2326,7 +2326,7 @@ RefPtr<Gfx::FontCascadeList const> 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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue