Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "MyGUI_Precompiled.h"
00024 #include "MyGUI_Common.h"
00025 #include "MyGUI_FactoryManager.h"
00026 #include "MyGUI_FontManager.h"
00027 #include "MyGUI_XmlDocument.h"
00028
00029 #include "MyGUI_ResourceManualFont.h"
00030 #include "MyGUI_ResourceTrueTypeFont.h"
00031
00032 namespace MyGUI
00033 {
00034 const std::string XML_TYPE("Font");
00035 const std::string XML_TYPE_RESOURCE("Resource");
00036 const std::string XML_TYPE_PROPERTY("Property");
00037 const std::string RESOURCE_DEFAULT_NAME("Default");
00038
00039 MYGUI_INSTANCE_IMPLEMENT(FontManager);
00040
00041 void FontManager::initialise()
00042 {
00043 MYGUI_ASSERT(false == mIsInitialise, INSTANCE_TYPE_NAME << " initialised twice");
00044 MYGUI_LOG(Info, "* Initialise: " << INSTANCE_TYPE_NAME);
00045
00046 ResourceManager::getInstance().registerLoadXmlDelegate(XML_TYPE) = newDelegate(this, &FontManager::_load);
00047
00048 FactoryManager::getInstance().registryFactory<ResourceManualFont>(XML_TYPE_RESOURCE);
00049 FactoryManager::getInstance().registryFactory<ResourceTrueTypeFont>(XML_TYPE_RESOURCE);
00050
00051
00052
00053
00054 MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully initialized");
00055 mIsInitialise = true;
00056 }
00057
00058 void FontManager::shutdown()
00059 {
00060 if (false == mIsInitialise) return;
00061 MYGUI_LOG(Info, "* Shutdown: " << INSTANCE_TYPE_NAME);
00062
00063 MyGUI::ResourceManager::getInstance().unregisterLoadXmlDelegate(XML_TYPE);
00064
00065 FactoryManager::getInstance().unregistryFactory<ResourceManualFont>(XML_TYPE_RESOURCE);
00066 FactoryManager::getInstance().unregistryFactory<ResourceTrueTypeFont>(XML_TYPE_RESOURCE);
00067
00068 MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully shutdown");
00069 mIsInitialise = false;
00070 }
00071
00072 bool FontManager::load(const std::string& _file)
00073 {
00074 return MyGUI::ResourceManager::getInstance()._loadImplement(_file, true, XML_TYPE, INSTANCE_TYPE_NAME);
00075 }
00076
00077 void FontManager::_load(xml::ElementPtr _node, const std::string& _file, Version _version)
00078 {
00079 xml::ElementEnumerator font = _node->getElementEnumerator();
00080 while (font.next())
00081 {
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 if (font->getName() == XML_TYPE_PROPERTY)
00194 {
00195 const std::string& key = font->findAttribute("key");
00196 const std::string& value = font->findAttribute("value");
00197 if (key == "Default")
00198 mDefaultName = value;
00199 }
00200 }
00201 }
00202
00203 void FontManager::setDefaultFont(const std::string& _value)
00204 {
00205 mDefaultName = _value;
00206 }
00207
00208 IFont* FontManager::getByName(const std::string& _name)
00209 {
00210 IResource* result = nullptr;
00211
00212 if (!_name.empty() && _name != RESOURCE_DEFAULT_NAME)
00213 result = ResourceManager::getInstance().getByName(_name, false);
00214
00215 if (result == nullptr)
00216 result = ResourceManager::getInstance().getByName(mDefaultName, false);
00217
00218 return result ? result->castType<IFont>(false) : nullptr;
00219 }
00220
00221 }