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