Changed defaultFont to const map

1008-fix
tomangelo2 2017-10-18 20:40:07 +02:00
parent 76a8335501
commit 1539e94b09
2 changed files with 22 additions and 19 deletions

View File

@ -42,14 +42,6 @@ CFontConfig::CFontConfig()
: m_needsSave(false)
, m_loaded(false)
{
//default fonts
m_defaultFont[Gfx::FONT_COMMON] = "/fonts/dvu_sans.ttf";
m_defaultFont[Gfx::FONT_COMMON_BOLD] = "/fonts/dvu_sans_bold.ttf";
m_defaultFont[Gfx::FONT_COMMON_ITALIC] = "/fonts/dvu_sans_italic.ttf";
m_defaultFont[Gfx::FONT_STUDIO] = "/fonts/dvu_sans_mono.ttf";
m_defaultFont[Gfx::FONT_STUDIO_BOLD] = "/fonts/dvu_sans_mono_bold.ttf";
m_defaultFont[Gfx::FONT_SATCOM] = "/fonts/dvu_sans.ttf";
m_font[Gfx::FONT_COMMON] = "FontCommon";
m_font[Gfx::FONT_COMMON_BOLD] = "FontCommonBold";
m_font[Gfx::FONT_COMMON_ITALIC] = "FontCommonItalic";
@ -93,14 +85,10 @@ bool CFontConfig::Init()
std::string CFontConfig::GetFont(Gfx::FontType type)
{
try
{
std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>(m_font[type]);
return path;
}
catch (std::exception & e)
{
GetLogger()->Log(m_loaded ? LOG_INFO : LOG_TRACE, "Error on parsing config file: %s. Default font will be used instead.\n", e.what());
return m_defaultFont[type];
}
return std::string("/fonts/") + m_propertyTree.get<std::string>(m_font[type], GetDefaultFont(type));
}
std::string CFontConfig::GetDefaultFont(Gfx::FontType type) const
{
return defaultFont.at(type);
}

View File

@ -39,6 +39,16 @@
*
*/
const std::map<Gfx::FontType, std::string> defaultFont =
{
{ Gfx::FONT_COMMON, "dvu_sans.ttf" },
{ Gfx::FONT_COMMON_BOLD, "dvu_sans_bold.ttf" },
{ Gfx::FONT_COMMON_ITALIC, "dvu_sans_italic.ttf" },
{ Gfx::FONT_STUDIO, "dvu_sans_mono.ttf" },
{ Gfx::FONT_STUDIO_BOLD, "dvu_sans_mono_bold.ttf" },
{ Gfx::FONT_SATCOM, "dvu_sans.ttf" },
};
class CFontConfig
{
public:
@ -55,9 +65,14 @@ public:
*/
std::string GetFont(Gfx::FontType type);
/** Const type method to read filenames of fonts from defaultFont map
* used as a fallback if it wasn't possible to read font from fonts.ini
* \return return filename of default path
*/
std::string GetDefaultFont(Gfx::FontType type) const;
private:
boost::property_tree::ptree m_propertyTree;
bool m_needsSave;
bool m_loaded;
std::map<Gfx::FontType, std::string> m_font, m_defaultFont;
std::map<Gfx::FontType, std::string> m_font;
};