xbmc
GUIFontManager.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
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 // Forward
28 class CGUIFont;
29 class CGUIFontTTF;
30 class CXBMCTinyXML;
31 class TiXmlNode;
32 class CSetting;
33 struct StringSettingOption;
34 
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 
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 
62 {
63 public:
65  ~GUIFontManager() override;
66 
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 
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 
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 
143 XBMC_GLOBAL_REF(GUIFontManager, g_fontManager);
144 #define g_fontManager XBMC_GLOBAL_USE(GUIFontManager)
Definition: XBMCTinyXML.h:33
Definition: GUIFontTTF.h:76
Setting base class containing all the properties which are common to all settings independent of the ...
Definition: Setting.h:46
Definition: GUIFontManager.h:35
Definition: IMsgTargetCallback.h:22
Definition: SettingDefinitions.h:85
Provide info of a resolution.
Definition: Resolution.h:66
Definition: GUIMessage.h:365
Definition: GUIFontManager.h:61
Definition: GUIFont.h:107
Definition: GraphicContext.h:60
Definition: GUIFontManager.h:46