/src/serenity/Userland/Libraries/LibGfx/Font/VectorFont.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2023, Andreas Kling <kling@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibGfx/Font/ScaledFont.h> |
8 | | #include <LibGfx/Font/VectorFont.h> |
9 | | |
10 | | namespace Gfx { |
11 | | |
12 | 195 | VectorFont::VectorFont() = default; |
13 | 195 | VectorFont::~VectorFont() = default; |
14 | | |
15 | | NonnullRefPtr<ScaledFont> VectorFont::scaled_font(float point_size) const |
16 | 0 | { |
17 | 0 | auto it = m_scaled_fonts.find(point_size); |
18 | 0 | if (it != m_scaled_fonts.end()) |
19 | 0 | return *it->value; |
20 | | |
21 | | // FIXME: It might be nice to have a global cap on the number of fonts we cache |
22 | | // instead of doing it at the per-VectorFont level like this. |
23 | 0 | constexpr size_t max_cached_font_size_count = 128; |
24 | 0 | if (m_scaled_fonts.size() > max_cached_font_size_count) |
25 | 0 | m_scaled_fonts.remove(m_scaled_fonts.begin()); |
26 | |
|
27 | 0 | auto scaled_font = adopt_ref(*new ScaledFont(*this, point_size, point_size)); |
28 | 0 | m_scaled_fonts.set(point_size, scaled_font); |
29 | 0 | return scaled_font; |
30 | 0 | } |
31 | | } |