22 FontManager::FontManager() :
23 mSingletonHolder(this),
24 mXmlFontTagName(
"Font"),
25 mXmlPropertyTagName(
"Property"),
26 mXmlDefaultFontValue(
"Default")
30 void FontManager::initialise()
32 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() <<
" initialised twice");
33 MYGUI_LOG(Info,
"* Initialise: " << getClassTypeName());
35 ResourceManager::getInstance().registerLoadXmlDelegate(mXmlFontTagName) =
36 newDelegate(
this, &FontManager::_load);
38 const std::string& resourceCategory = ResourceManager::getInstance().getCategoryName();
39 FactoryManager::getInstance().registerFactory<ResourceManualFont>(resourceCategory);
40 FactoryManager::getInstance().registerFactory<ResourceTrueTypeFont>(resourceCategory);
42 mDefaultName =
"Default";
44 MYGUI_LOG(Info, getClassTypeName() <<
" successfully initialized");
48 void FontManager::shutdown()
50 MYGUI_ASSERT(mIsInitialise, getClassTypeName() <<
" is not initialised");
51 MYGUI_LOG(Info,
"* Shutdown: " << getClassTypeName());
53 MyGUI::ResourceManager::getInstance().unregisterLoadXmlDelegate(mXmlFontTagName);
55 const std::string& resourceCategory = ResourceManager::getInstance().getCategoryName();
56 FactoryManager::getInstance().unregisterFactory<ResourceManualFont>(resourceCategory);
57 FactoryManager::getInstance().unregisterFactory<ResourceTrueTypeFont>(resourceCategory);
59 MYGUI_LOG(Info, getClassTypeName() <<
" successfully shutdown");
60 mIsInitialise =
false;
63 void FontManager::_load(xml::ElementPtr _node, std::string_view _file, Version _version)
65#ifndef MYGUI_DONT_USE_OBSOLETE
66 loadOldFontFormat(_node, _file, _version, mXmlFontTagName);
69 for (
auto child : _node.node())
71 if (child.name() == mXmlPropertyTagName)
73 std::string_view key = child.attribute(
"key").value();
74 std::string_view value = child.attribute(
"value").value();
75#ifdef MYGUI_USE_FREETYPE
78 if (key ==
"DefaultGenerated")
85 void FontManager::setDefaultFont(std::string_view _value)
87 mDefaultName = _value;
90 IFont* FontManager::getByName(std::string_view _name)
const
92 IResource* result =
nullptr;
94 if (!_name.empty() && _name != mXmlDefaultFontValue)
95 result = ResourceManager::getInstance().getByName(_name,
false);
97 if (result ==
nullptr)
99 result = ResourceManager::getInstance().getByName(mDefaultName,
false);
100 if (!_name.empty() && _name != mXmlDefaultFontValue)
102 MYGUI_LOG(Error,
"Font '" << _name <<
"' not found. Replaced with default font.");
106 return result ? result->castType<IFont>(
false) : nullptr;
109 const std::string& FontManager::getDefaultFont()
const
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_LOG(level, text)
MYGUI_SINGLETON_DEFINITION(ClipboardManager)