/src/serenity/Userland/Libraries/LibGfx/FontCascadeList.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibGfx/FontCascadeList.h> |
8 | | |
9 | | namespace Gfx { |
10 | | |
11 | | void FontCascadeList::add(NonnullRefPtr<Font> font) |
12 | 0 | { |
13 | 0 | m_fonts.append({ move(font), {} }); |
14 | 0 | } |
15 | | |
16 | | void FontCascadeList::add(NonnullRefPtr<Font> font, Vector<UnicodeRange> unicode_ranges) |
17 | 0 | { |
18 | 0 | m_fonts.append({ move(font), move(unicode_ranges) }); |
19 | 0 | } |
20 | | |
21 | | void FontCascadeList::extend(FontCascadeList const& other) |
22 | 0 | { |
23 | 0 | for (auto const& font : other.m_fonts) { |
24 | 0 | m_fonts.append({ font.font, font.unicode_ranges }); |
25 | 0 | } |
26 | 0 | } |
27 | | |
28 | | Gfx::Font const& FontCascadeList::font_for_code_point(u32 code_point) const |
29 | 0 | { |
30 | 0 | for (auto const& entry : m_fonts) { |
31 | 0 | if (!entry.unicode_ranges.has_value()) |
32 | 0 | return entry.font; |
33 | 0 | if (!entry.font->contains_glyph(code_point)) |
34 | 0 | continue; |
35 | 0 | for (auto const& range : *entry.unicode_ranges) { |
36 | 0 | if (range.contains(code_point)) |
37 | 0 | return entry.font; |
38 | 0 | } |
39 | 0 | } |
40 | 0 | VERIFY_NOT_REACHED(); |
41 | 0 | } |
42 | | |
43 | | bool FontCascadeList::equals(FontCascadeList const& other) const |
44 | 0 | { |
45 | 0 | if (m_fonts.size() != other.m_fonts.size()) |
46 | 0 | return false; |
47 | 0 | for (size_t i = 0; i < m_fonts.size(); ++i) { |
48 | 0 | if (m_fonts[i].font != other.m_fonts[i].font) |
49 | 0 | return false; |
50 | 0 | } |
51 | 0 | return true; |
52 | 0 | } |
53 | | |
54 | | } |