diff --git a/src/common/font_config.cpp b/src/common/font_config.cpp index b4487f1a..4768cbc6 100644 --- a/src/common/font_config.cpp +++ b/src/common/font_config.cpp @@ -29,6 +29,7 @@ #include "graphics/engine/text.h" +#include #include #include #include @@ -41,6 +42,20 @@ 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"; + m_font[Gfx::FONT_STUDIO] = "FontStudio"; + m_font[Gfx::FONT_STUDIO_BOLD] = "FontStudioBold"; + m_font[Gfx::FONT_SATCOM] = "FontSatCom"; } CFontConfig::~CFontConfig() @@ -78,90 +93,14 @@ bool CFontConfig::Init() std::string CFontConfig::GetFont(Gfx::FontType type) { - switch(type) + try { - case Gfx::FONT_COMMON: - { - try - { - std::string path = std::string("/fonts/") + m_propertyTree.get("FontCommon"); - 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 "/fonts/dvu_sans.ttf"; - } - } - case Gfx::FONT_COMMON_BOLD: - { - try - { - std::string path = std::string("/fonts/") + m_propertyTree.get("FontCommonBold"); - 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 "/fonts/dvu_sans_bold.ttf"; - } - } - case Gfx::FONT_COMMON_ITALIC: - { - try - { - std::string path = std::string("/fonts/") + m_propertyTree.get("FontCommonItalic"); - 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 "/fonts/dvu_sans_italic.ttf"; - } - } - case Gfx::FONT_STUDIO: - { - try - { - std::string path = std::string("/fonts/") + m_propertyTree.get("FontStudio"); - 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 "/fonts/dvu_sans_mono.ttf"; - } - } - case Gfx::FONT_STUDIO_BOLD: - { - try - { - std::string path = std::string("/fonts/") + m_propertyTree.get("FontStudioBold"); - 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 "/fonts/dvu_sans_mono_bold.ttf"; - } - } - case Gfx::FONT_SATCOM: - { - try - { - std::string path = std::string("/fonts/") + m_propertyTree.get("FontSatCom"); - 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 "/fonts/dvu_sans.ttf"; - } - } - default: - { - GetLogger()->Debug("Incorrect font type: %i.\n", type); - return nullptr; - } + std::string path = std::string("/fonts/") + m_propertyTree.get(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]; + } } diff --git a/src/common/font_config.h b/src/common/font_config.h index 594b4ce8..c28ea445 100644 --- a/src/common/font_config.h +++ b/src/common/font_config.h @@ -59,4 +59,5 @@ private: boost::property_tree::ptree m_propertyTree; bool m_needsSave; bool m_loaded; + std::map m_font, m_defaultFont; };