Replaced multiple methods with one
parent
dd9439aed2
commit
52d9330114
|
@ -27,6 +27,8 @@
|
|||
|
||||
#include "common/system/system.h"
|
||||
|
||||
#include "graphics/engine/text.h"
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cstring>
|
||||
|
@ -84,92 +86,92 @@ bool CFontConfigFile::Init()
|
|||
return true;
|
||||
}
|
||||
|
||||
std::string CFontConfigFile::GetCommonFont()
|
||||
std::string CFontConfigFile::GetFont(Gfx::FontType type)
|
||||
{
|
||||
try
|
||||
switch(type)
|
||||
{
|
||||
std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("FontCommon");
|
||||
return path;
|
||||
case Gfx::FONT_COMMON:
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("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<std::string>("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<std::string>("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<std::string>("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<std::string>("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<std::string>("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;
|
||||
}
|
||||
}
|
||||
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";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string CFontConfigFile::GetCommonBoldFont()
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("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";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string CFontConfigFile::GetCommonItalicFont()
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("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";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string CFontConfigFile::GetStudioFont()
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("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";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string CFontConfigFile::GetStudioBoldFont()
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("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";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string CFontConfigFile::GetSatComFont()
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("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";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
#include "common/singleton.h"
|
||||
|
||||
#include "graphics/engine/text.h"
|
||||
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
#include <string>
|
||||
|
@ -48,35 +50,10 @@ public:
|
|||
*/
|
||||
bool Init();
|
||||
|
||||
/** Reads common font from file
|
||||
/** Reads given font from file
|
||||
* \return return path to font file
|
||||
*/
|
||||
std::string GetCommonFont();
|
||||
|
||||
/** Reads common bold font from file
|
||||
* \return return path to font file
|
||||
*/
|
||||
std::string GetCommonBoldFont();
|
||||
|
||||
/** Reads common italic font from file
|
||||
* \return return path to font file
|
||||
*/
|
||||
std::string GetCommonItalicFont();
|
||||
|
||||
/** Reads studio font from file
|
||||
* \return return path to font file
|
||||
*/
|
||||
std::string GetStudioFont();
|
||||
|
||||
/** Reads studio bold font from file
|
||||
* \return returns path to font file
|
||||
*/
|
||||
std::string GetStudioBoldFont();
|
||||
|
||||
/** Reads satcom font from file
|
||||
* \return returns path to font file
|
||||
*/
|
||||
std::string GetSatComFont();
|
||||
std::string GetFont(Gfx::FontType type);
|
||||
|
||||
private:
|
||||
boost::property_tree::ptree m_propertyTree;
|
||||
|
|
|
@ -127,16 +127,16 @@ bool CText::Create()
|
|||
m_error = std::string("TTF_Init error: ") + std::string(TTF_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
m_fonts[FONT_COMMON] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetCommonFont());
|
||||
m_fonts[FONT_COMMON_BOLD] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetCommonBoldFont());
|
||||
m_fonts[FONT_COMMON_ITALIC] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetCommonItalicFont());
|
||||
|
||||
m_fonts[FONT_SATCOM] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetSatComFont());
|
||||
|
||||
m_fonts[FONT_STUDIO] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetStudioFont());
|
||||
m_fonts[FONT_STUDIO_BOLD] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetStudioBoldFont());
|
||||
m_fonts[FONT_COMMON] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetFont(FONT_COMMON));
|
||||
m_fonts[FONT_COMMON_BOLD] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetFont(FONT_COMMON_BOLD));
|
||||
m_fonts[FONT_COMMON_ITALIC] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetFont(FONT_COMMON_ITALIC));
|
||||
|
||||
m_fonts[FONT_SATCOM] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetFont(FONT_SATCOM));
|
||||
|
||||
m_fonts[FONT_STUDIO] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetFont(FONT_STUDIO));
|
||||
m_fonts[FONT_STUDIO_BOLD] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetFont(FONT_STUDIO_BOLD));
|
||||
|
||||
for (auto it = m_fonts.begin(); it != m_fonts.end(); ++it)
|
||||
{
|
||||
FontType type = (*it).first;
|
||||
|
|
Loading…
Reference in New Issue