| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#pragma once |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 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" |
| 22 |
|
| 23 |
#include <set> |
| 24 |
#include <utility> |
| 25 |
#include <vector> |
| 26 |
|
| 27 |
|
| 28 |
class CGUIFont; |
| 29 |
class CGUIFontTTF; |
| 30 |
class CXBMCTinyXML; |
| 31 |
class TiXmlNode; |
| 32 |
class CSetting; |
| 33 |
struct StringSettingOption; |
| 34 |
|
| 35 |
struct OrigFontInfo |
| 36 |
{ |
| 37 |
int size; |
| 38 |
float aspect; |
| 39 |
std::string fontFilePath; |
| 40 |
std::string fileName; |
| 41 |
RESOLUTION_INFO sourceRes; |
| 42 |
bool preserveAspect; |
| 43 |
bool border; |
| 44 |
}; |
| 45 |
|
| 46 |
struct FontMetadata |
| 47 |
{ |
| 48 |
FontMetadata(const std::string& filename, const std::set<std::string>& familyNames) |
| 49 |
: m_filename{filename}, m_familyNames{familyNames} |
| 50 |
{ |
| 51 |
} |
| 52 |
|
| 53 |
std::string m_filename; |
| 54 |
std::set<std::string> m_familyNames; |
| 55 |
}; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
class GUIFontManager : public IMsgTargetCallback |
| 62 |
{ |
| 63 |
public: |
| 64 |
GUIFontManager(); |
| 65 |
~GUIFontManager() override; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
void Initialize(); |
| 72 |
|
| 73 |
bool IsUpdating() const { return m_critSection.IsLocked(); } |
| 74 |
|
| 75 |
bool OnMessage(CGUIMessage& message) override; |
| 76 |
|
| 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 |
UTILS::COLOR::Color textColor, |
| 82 |
UTILS::COLOR::Color shadowColor, |
| 83 |
const int iSize, |
| 84 |
const int iStyle, |
| 85 |
bool border = false, |
| 86 |
float lineSpacing = 1.0f, |
| 87 |
float aspect = 1.0f, |
| 88 |
const RESOLUTION_INFO* res = nullptr, |
| 89 |
bool preserveAspect = false); |
| 90 |
CGUIFont* GetFont(const std::string& strFontName, bool fallback = true); |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
CGUIFont* GetDefaultFont(bool border = false); |
| 97 |
|
| 98 |
void Clear(); |
| 99 |
void FreeFontFile(CGUIFontTTF* pFont); |
| 100 |
|
| 101 |
static void SettingOptionsFontsFiller(const std::shared_ptr<const CSetting>& setting, |
| 102 |
std::vector<StringSettingOption>& list, |
| 103 |
std::string& current, |
| 104 |
void* data); |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
std::vector<std::string> GetUserFontsFamilyNames(); |
| 111 |
|
| 112 |
protected: |
| 113 |
void ReloadTTFFonts(); |
| 114 |
static void RescaleFontSizeAndAspect(CGraphicContext& context, |
| 115 |
float* size, |
| 116 |
float* aspect, |
| 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); |
| 122 |
|
| 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}; |
| 128 |
|
| 129 |
private: |
| 130 |
void LoadUserFonts(); |
| 131 |
bool LoadFontsFromFile(const std::string& fontsetFilePath, |
| 132 |
const std::string& fontSet, |
| 133 |
std::string& firstFontset); |
| 134 |
|
| 135 |
mutable CCriticalSection m_critSection; |
| 136 |
std::vector<FontMetadata> m_userFontsCache; |
| 137 |
}; |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
XBMC_GLOBAL_REF(GUIFontManager, g_fontManager); |
| 144 |
#define g_fontManager XBMC_GLOBAL_USE(GUIFontManager) |