2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
12 \file GUIFontManager.h
16 #include "IMsgTargetCallback.h"
17 #include "threads/CriticalSection.h"
18 #include "threads/SingleLock.h"
19 #include "utils/ColorUtils.h"
20 #include "utils/GlobalsHandling.h"
21 #include "windowing/GraphicContext.h"
33 struct StringSettingOption
;
39 std::string fontFilePath
;
41 RESOLUTION_INFO sourceRes
;
48 FontMetadata(const std::string
& filename
, const std::set
<std::string
>& familyNames
)
49 : m_filename
{filename
}, m_familyNames
{familyNames
}
53 std::string m_filename
;
54 std::set
<std::string
> m_familyNames
;
61 class GUIFontManager
: public IMsgTargetCallback
65 ~GUIFontManager() override
;
68 * \brief Initialize the font manager.
69 * Checks that fonts cache are up to date, otherwise update it.
73 bool IsUpdating() const { return m_critSection
.IsLocked(); }
75 bool OnMessage(CGUIMessage
& message
) override
;
77 void Unload(const std::string
& strFontName
);
78 void LoadFonts(const std::string
& fontSet
);
79 CGUIFont
* LoadTTF(const std::string
& strFontName
,
80 const std::string
& strFilename
,
81 KODI::UTILS::COLOR::Color textColor
,
82 KODI::UTILS::COLOR::Color shadowColor
,
86 float lineSpacing
= 1.0f
,
88 const RESOLUTION_INFO
* res
= nullptr,
89 bool preserveAspect
= false);
90 CGUIFont
* GetFont(const std::string
& strFontName
, bool fallback
= true);
92 /*! \brief return a default font
93 \param border whether the font should be a font with an outline
94 \return the font. `nullptr` if no default font can be found.
96 CGUIFont
* GetDefaultFont(bool border
= false);
99 void FreeFontFile(CGUIFontTTF
* pFont
);
101 static void SettingOptionsFontsFiller(const std::shared_ptr
<const CSetting
>& setting
,
102 std::vector
<StringSettingOption
>& list
,
103 std::string
& current
,
107 * \brief Get the list of user fonts as family names from cache
108 * \return The list of available fonts family names
110 std::vector
<std::string
> GetUserFontsFamilyNames();
113 void ReloadTTFFonts();
114 static void RescaleFontSizeAndAspect(CGraphicContext
& context
,
117 const RESOLUTION_INFO
& sourceRes
,
118 bool preserveAspect
);
119 void LoadFonts(const TiXmlNode
* fontNode
);
120 CGUIFontTTF
* GetFontFile(const std::string
& fontIdent
);
121 static void GetStyle(const TiXmlNode
* fontNode
, int& iStyle
);
123 std::vector
<std::unique_ptr
<CGUIFont
>> m_vecFonts
;
124 std::vector
<std::unique_ptr
<CGUIFontTTF
>> m_vecFontFiles
;
125 std::vector
<OrigFontInfo
> m_vecFontInfo
;
126 RESOLUTION_INFO m_skinResolution
;
127 bool m_canReload
{true};
130 void LoadUserFonts();
131 bool LoadFontsFromFile(const std::string
& fontsetFilePath
,
132 const std::string
& fontSet
,
133 std::string
& firstFontset
);
135 mutable CCriticalSection m_critSection
;
136 std::vector
<FontMetadata
> m_userFontsCache
;
143 XBMC_GLOBAL_REF(GUIFontManager
, g_fontManager
);
144 #define g_fontManager XBMC_GLOBAL_USE(GUIFontManager)