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 <utility>
24 #include <vector>
25 
26 // Forward
27 class CGUIFont;
28 class CGUIFontTTF;
29 class CXBMCTinyXML;
30 class TiXmlNode;
31 class CSetting;
32 struct StringSettingOption;
33 
35 {
36  int size;
37  float aspect;
38  std::string fontFilePath;
39  std::string fileName;
40  RESOLUTION_INFO sourceRes;
41  bool preserveAspect;
42  bool border;
43 };
44 
46 {
47  FontMetadata(const std::string& filename, const std::string& familyName)
48  : m_filename{filename}, m_familyName{familyName}
49  {
50  }
51 
52  std::string m_filename;
53  std::string m_familyName;
54 };
55 
61 {
62 public:
64  ~GUIFontManager() override;
65 
70  void Initialize();
71 
72  bool IsUpdating() const { return m_critSection.IsLocked(); }
73 
74  bool OnMessage(CGUIMessage& message) override;
75 
76  void Unload(const std::string& strFontName);
77  void LoadFonts(const std::string& fontSet);
78  CGUIFont* LoadTTF(const std::string& strFontName,
79  const std::string& strFilename,
80  UTILS::COLOR::Color textColor,
81  UTILS::COLOR::Color shadowColor,
82  const int iSize,
83  const int iStyle,
84  bool border = false,
85  float lineSpacing = 1.0f,
86  float aspect = 1.0f,
87  const RESOLUTION_INFO* res = nullptr,
88  bool preserveAspect = false);
89  CGUIFont* GetFont(const std::string& strFontName, bool fallback = true);
90 
95  CGUIFont* GetDefaultFont(bool border = false);
96 
97  void Clear();
98  void FreeFontFile(CGUIFontTTF* pFont);
99 
100  static void SettingOptionsFontsFiller(const std::shared_ptr<const CSetting>& setting,
101  std::vector<StringSettingOption>& list,
102  std::string& current,
103  void* data);
104 
109  std::vector<std::string> GetUserFontsFamilyNames();
110 
111 protected:
112  void ReloadTTFFonts();
113  static void RescaleFontSizeAndAspect(CGraphicContext& context,
114  float* size,
115  float* aspect,
116  const RESOLUTION_INFO& sourceRes,
117  bool preserveAspect);
118  void LoadFonts(const TiXmlNode* fontNode);
119  CGUIFontTTF* GetFontFile(const std::string& fontIdent);
120  static void GetStyle(const TiXmlNode* fontNode, int& iStyle);
121 
122  std::vector<std::unique_ptr<CGUIFont>> m_vecFonts;
123  std::vector<std::unique_ptr<CGUIFontTTF>> m_vecFontFiles;
124  std::vector<OrigFontInfo> m_vecFontInfo;
125  RESOLUTION_INFO m_skinResolution;
126  bool m_canReload{true};
127 
128 private:
129  void LoadUserFonts();
130 
131  mutable CCriticalSection m_critSection;
132  std::vector<FontMetadata> m_userFontsCache;
133 };
134 
139 XBMC_GLOBAL_REF(GUIFontManager, g_fontManager);
140 #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:34
Definition: IMsgTargetCallback.h:22
Definition: SettingDefinitions.h:85
Provide info of a resolution.
Definition: Resolution.h:66
Definition: GUIMessage.h:365
Definition: GUIFontManager.h:60
Definition: GUIFont.h:107
Definition: GraphicContext.h:60
Definition: GUIFontManager.h:45