Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
FontManager.h
Go to the documentation of this file.
1/* Copyright (C) 2026 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_FONTMANAGER
19#define INCLUDED_FONTMANAGER
20
21#include "lib/code_annotation.h"
22#include "ps/CStrIntern.h"
23
24#include <array>
25#include <ft2build.h>
26#include FT_FREETYPE_H
27#include <memory>
28#include <unordered_map>
29
30class CConfigDBHook;
31class CFont;
32struct FT_LibraryRec_;
33
34namespace Renderer::Backend { class IDevice; }
35namespace Renderer::Backend { class IDeviceCommandContext; }
36
37/**
38 * Font manager: loads and caches bitmap fonts.
39 */
41{
42public:
46
47 CFont* LoadFont(CStrIntern fontName, CStrIntern locale);
49 Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
50
51private:
52 static void ftLibraryDeleter(FT_Library library)
53 {
54 FT_Done_FreeType(library);
55 }
56
57 std::unique_ptr<FT_LibraryRec_, decltype(&ftLibraryDeleter)> m_FreeType{nullptr, &ftLibraryDeleter};
58
59 std::unique_ptr<std::array<float, 256>> m_GammaCorrectionLUT;
60
61 using FontsMap = std::unordered_map<CStrIntern, CFont>;
63
64 float m_GUIScale{1.0f};
65 std::unique_ptr<CConfigDBHook> m_GUIScaleHook;
66
68
69 /*
70 * Most monitors today use 2.2 as the standard gamma.
71 * MacOS may use 2.2 or 1.8 in some cases.
72 * This method assumes your OS or GPU didn’t override the gamma ramp.
73 * Unless we need super-accurate gamma (e.g., for print preview or color grading), this is usually acceptable.
74 */
75 static constexpr float GAMMA_CORRECTION = 2.2f;
76};
77
78#endif // INCLUDED_FONTMANAGER
Definition: ConfigDB.h:229
Font manager: loads and caches bitmap fonts.
Definition: FontManager.h:41
static constexpr float GAMMA_CORRECTION
Definition: FontManager.h:75
std::unordered_map< CStrIntern, CFont > FontsMap
Definition: FontManager.h:61
std::unique_ptr< FT_LibraryRec_, decltype(&ftLibraryDeleter)> m_FreeType
Definition: FontManager.h:57
float m_GUIScale
Definition: FontManager.h:64
void UploadAtlasTexturesToGPU(Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
Definition: FontManager.cpp:263
static void ftLibraryDeleter(FT_Library library)
Definition: FontManager.h:52
std::unique_ptr< CConfigDBHook > m_GUIScaleHook
Definition: FontManager.h:65
NONCOPYABLE(CFontManager)
Renderer::Backend::IDevice * m_Device
Definition: FontManager.h:67
CFontManager(Renderer::Backend::IDevice *device)
Definition: FontManager.cpp:105
FontsMap m_Fonts
Definition: FontManager.h:62
CFont * LoadFont(CStrIntern fontName, CStrIntern locale)
Definition: FontManager.cpp:128
std::unique_ptr< std::array< float, 256 > > m_GammaCorrectionLUT
Definition: FontManager.h:59
Storage for a bitmap font.
Definition: Font.h:50
Interned 8-bit strings.
Definition: CStrIntern.h:42
Definition: IDeviceCommandContext.h:46
Definition: IDevice.h:64
Definition: Canvas2D.h:30
library
Definition: tests.py:24