-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathFontCascadeList.cpp
54 lines (46 loc) · 1.32 KB
/
FontCascadeList.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Copyright (c) 2023, Aliaksandr Kalenik <[email protected]>
*
* 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())
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();
}
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;
}
}