2026-04-10 14:39:15 -07:00
|
|
|
|
/* Copyright (C) 2026 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
|
* This file is part of 0 A.D.
|
2009-04-18 10:00:33 -07:00
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2009-04-18 10:00:33 -07:00
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2009-04-18 10:00:33 -07:00
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
*
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-12-02 16:30:12 -08:00
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-18 10:00:33 -07:00
|
|
|
|
*/
|
|
|
|
|
|
|
2013-10-18 08:53:07 -07:00
|
|
|
|
#ifndef INCLUDED_FONTMANAGER
|
|
|
|
|
|
#define INCLUDED_FONTMANAGER
|
2004-08-27 15:08:30 -07:00
|
|
|
|
|
2025-07-06 11:15:27 -07:00
|
|
|
|
#include "lib/code_annotation.h"
|
2019-11-25 06:30:25 -08:00
|
|
|
|
#include "ps/CStrIntern.h"
|
|
|
|
|
|
|
2025-07-28 11:13:46 -07:00
|
|
|
|
#include <array>
|
2025-04-23 08:51:40 -07:00
|
|
|
|
#include <ft2build.h>
|
|
|
|
|
|
#include FT_FREETYPE_H
|
2025-07-06 11:15:27 -07:00
|
|
|
|
#include <memory>
|
2019-11-25 06:30:25 -08:00
|
|
|
|
#include <unordered_map>
|
2012-03-13 14:39:01 -07:00
|
|
|
|
|
2025-10-11 10:08:02 -07:00
|
|
|
|
class CConfigDBHook;
|
2013-10-18 08:53:07 -07:00
|
|
|
|
class CFont;
|
2025-07-16 11:25:46 -07:00
|
|
|
|
struct FT_LibraryRec_;
|
2004-08-27 15:08:30 -07:00
|
|
|
|
|
2026-04-10 14:39:15 -07:00
|
|
|
|
namespace Renderer::Backend { class IDevice; }
|
2025-09-17 05:31:16 -07:00
|
|
|
|
namespace Renderer::Backend { class IDeviceCommandContext; }
|
|
|
|
|
|
|
2013-10-18 08:53:07 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Font manager: loads and caches bitmap fonts.
|
|
|
|
|
|
*/
|
|
|
|
|
|
class CFontManager
|
2004-08-27 15:08:30 -07:00
|
|
|
|
{
|
|
|
|
|
|
public:
|
2026-04-10 14:39:15 -07:00
|
|
|
|
CFontManager(Renderer::Backend::IDevice* device);
|
2025-10-11 10:08:02 -07:00
|
|
|
|
~CFontManager();
|
2025-04-23 08:51:40 -07:00
|
|
|
|
NONCOPYABLE(CFontManager);
|
|
|
|
|
|
|
2025-10-11 10:08:02 -07:00
|
|
|
|
CFont* LoadFont(CStrIntern fontName, CStrIntern locale);
|
2025-09-17 05:31:16 -07:00
|
|
|
|
void UploadAtlasTexturesToGPU(
|
|
|
|
|
|
Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
|
2004-08-27 15:08:30 -07:00
|
|
|
|
|
|
|
|
|
|
private:
|
2025-09-17 03:32:12 -07:00
|
|
|
|
static void ftLibraryDeleter(FT_Library library)
|
|
|
|
|
|
{
|
2025-04-23 08:51:40 -07:00
|
|
|
|
FT_Done_FreeType(library);
|
|
|
|
|
|
}
|
2025-09-17 03:32:12 -07:00
|
|
|
|
|
2025-04-23 08:51:40 -07:00
|
|
|
|
std::unique_ptr<FT_LibraryRec_, decltype(&ftLibraryDeleter)> m_FreeType{nullptr, &ftLibraryDeleter};
|
|
|
|
|
|
|
2025-09-17 03:32:12 -07:00
|
|
|
|
std::unique_ptr<std::array<float, 256>> m_GammaCorrectionLUT;
|
2004-08-27 15:08:30 -07:00
|
|
|
|
|
2025-10-11 10:08:02 -07:00
|
|
|
|
using FontsMap = std::unordered_map<CStrIntern, CFont>;
|
2013-10-18 08:53:07 -07:00
|
|
|
|
FontsMap m_Fonts;
|
2025-04-23 08:51:40 -07:00
|
|
|
|
|
2025-10-11 10:08:02 -07:00
|
|
|
|
float m_GUIScale{1.0f};
|
|
|
|
|
|
std::unique_ptr<CConfigDBHook> m_GUIScaleHook;
|
|
|
|
|
|
|
2026-04-10 14:39:15 -07:00
|
|
|
|
Renderer::Backend::IDevice* m_Device;
|
|
|
|
|
|
|
2025-04-23 08:51:40 -07:00
|
|
|
|
/*
|
|
|
|
|
|
* Most monitors today use 2.2 as the standard gamma.
|
|
|
|
|
|
* MacOS may use 2.2 or 1.8 in some cases.
|
|
|
|
|
|
* This method assumes your OS or GPU didn’t override the gamma ramp.
|
|
|
|
|
|
* Unless we need super-accurate gamma (e.g., for print preview or color grading), this is usually acceptable.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static constexpr float GAMMA_CORRECTION = 2.2f;
|
2013-10-18 08:53:07 -07:00
|
|
|
|
};
|
2004-08-27 15:08:30 -07:00
|
|
|
|
|
2013-10-18 08:53:07 -07:00
|
|
|
|
#endif // INCLUDED_FONTMANAGER
|