mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
67fe8d66b2
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.
54 lines
1.4 KiB
C++
54 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibGfx/FontCascadeList.h>
|
|
|
|
namespace Gfx {
|
|
|
|
void FontCascadeList::add(NonnullRefPtr<Font> font)
|
|
{
|
|
m_fonts.append({ move(font), {} });
|
|
}
|
|
|
|
void FontCascadeList::add(NonnullRefPtr<Font> font, Vector<UnicodeRange> unicode_ranges)
|
|
{
|
|
m_fonts.append({ move(font), move(unicode_ranges) });
|
|
}
|
|
|
|
void FontCascadeList::extend(FontCascadeList const& other)
|
|
{
|
|
for (auto const& font : other.m_fonts) {
|
|
m_fonts.append({ font.font, font.unicode_ranges });
|
|
}
|
|
}
|
|
|
|
Gfx::Font const& FontCascadeList::font_for_code_point(u32 code_point) const
|
|
{
|
|
for (auto const& entry : m_fonts) {
|
|
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;
|
|
}
|
|
}
|
|
return *m_last_resort_font;
|
|
}
|
|
|
|
bool FontCascadeList::equals(FontCascadeList const& other) const
|
|
{
|
|
if (m_fonts.size() != other.m_fonts.size())
|
|
return false;
|
|
for (size_t i = 0; i < m_fonts.size(); ++i) {
|
|
if (m_fonts[i].font != other.m_fonts[i].font)
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
}
|