MyGUI 3.4.1
MyGUI_FontManager.cpp
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#include "MyGUI_Precompiled.h"
8#include "MyGUI_FontManager.h"
10#include "MyGUI_XmlDocument.h"
11
14
15namespace MyGUI
16{
17
19
21 mIsInitialise(false),
22 mXmlFontTagName("Font"),
23 mXmlPropertyTagName("Property"),
24 mXmlDefaultFontValue("Default"),
25 mSingletonHolder(this)
26 {
27 }
28
30 {
31 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
32 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
33
34 ResourceManager::getInstance().registerLoadXmlDelegate(mXmlFontTagName) = newDelegate(this, &FontManager::_load);
35
36 std::string resourceCategory = ResourceManager::getInstance().getCategoryName();
39
40 mDefaultName = "Default";
41
42 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
43 mIsInitialise = true;
44 }
45
47 {
48 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
49 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
50
52
53 std::string resourceCategory = ResourceManager::getInstance().getCategoryName();
56
57 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
58 mIsInitialise = false;
59 }
60
61 void FontManager::_load(xml::ElementPtr _node, const std::string& _file, Version _version)
62 {
63#ifndef MYGUI_DONT_USE_OBSOLETE
64 loadOldFontFormat(_node, _file, _version, mXmlFontTagName);
65#endif // MYGUI_DONT_USE_OBSOLETE
66
68 while (node.next())
69 {
70 if (node->getName() == mXmlPropertyTagName)
71 {
72 const std::string& key = node->findAttribute("key");
73 const std::string& value = node->findAttribute("value");
74#ifdef MYGUI_USE_FREETYPE
75 if (key == "Default")
76#else
77 if (key == "DefaultGenerated")
78#endif
79 mDefaultName = value;
80 }
81 }
82 }
83
84 void FontManager::setDefaultFont(const std::string& _value)
85 {
86 mDefaultName = _value;
87 }
88
89 IFont* FontManager::getByName(const std::string& _name) const
90 {
91 IResource* result = nullptr;
92 //FIXME для совместимости шрифт может иметь имя Default
93 if (!_name.empty() && _name != mXmlDefaultFontValue)
94 result = ResourceManager::getInstance().getByName(_name, false);
95
96 if (result == nullptr)
97 {
98 result = ResourceManager::getInstance().getByName(mDefaultName, false);
99 if (!_name.empty() && _name != mXmlDefaultFontValue)
100 {
101 MYGUI_LOG(Error, "Font '" << _name << "' not found. Replaced with default font.");
102 }
103 }
104
105 return result ? result->castType<IFont>(false) : nullptr;
106 }
107
108 const std::string& FontManager::getDefaultFont() const
109 {
110 return mDefaultName;
111 }
112
113} // namespace MyGUI
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_LOG(level, text)
void unregisterFactory(const std::string &_category, const std::string &_type)
static FactoryManager & getInstance()
void registerFactory(const std::string &_category, const std::string &_type, Delegate::IDelegate *_delegate)
IFont * getByName(const std::string &_name) const
void setDefaultFont(const std::string &_value)
const std::string & getDefaultFont() const
static const char * getClassTypeName()
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:18
void loadOldFontFormat(xml::ElementPtr _node, const std::string &_file, Version _version, const std::string &_tag)
const std::string & getCategoryName() const
IResource * getByName(const std::string &_name, bool _throw=true) const
void unregisterLoadXmlDelegate(const std::string &_key)
static ResourceManager & getInstance()
LoadXmlDelegate & registerLoadXmlDelegate(const std::string &_key)
ElementEnumerator getElementEnumerator()
const std::string & getName() const
bool findAttribute(const std::string &_name, std::string &_value)
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
MYGUI_SINGLETON_DEFINITION(ClipboardManager)