LCOV - code coverage report
Current view: top level - source/graphics - FontManager.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 3 3 100.0 %
Date: 2026-12-03 01:19:39 Functions: 1 1 100.0 %

          Line data    Source code
       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             : 
      30             : class CConfigDBHook;
      31             : class CFont;
      32             : struct FT_LibraryRec_;
      33             : 
      34             : namespace Renderer::Backend { class IDevice; }
      35             : namespace Renderer::Backend { class IDeviceCommandContext; }
      36             : 
      37             : /**
      38             :  * Font manager: loads and caches bitmap fonts.
      39             :  */
      40             : class CFontManager
      41             : {
      42             : public:
      43             :     CFontManager(Renderer::Backend::IDevice* device);
      44             :     ~CFontManager();
      45             :     NONCOPYABLE(CFontManager);
      46             : 
      47             :     CFont* LoadFont(CStrIntern fontName, CStrIntern locale);
      48             :     void UploadAtlasTexturesToGPU(
      49             :         Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
      50             : 
      51             : private:
      52          10 :     static void ftLibraryDeleter(FT_Library library)
      53             :     {
      54          10 :         FT_Done_FreeType(library);
      55          10 :     }
      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>;
      62             :     FontsMap m_Fonts;
      63             : 
      64             :     float m_GUIScale{1.0f};
      65             :     std::unique_ptr<CConfigDBHook> m_GUIScaleHook;
      66             : 
      67             :     Renderer::Backend::IDevice* m_Device;
      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

Generated by: LCOV version 1.16