Rewritten loading of font config file
parent
3e06584956
commit
fde2b901bd
|
@ -20,6 +20,7 @@
|
||||||
#include "common/font_loader.h"
|
#include "common/font_loader.h"
|
||||||
|
|
||||||
#include "common/logger.h"
|
#include "common/logger.h"
|
||||||
|
#include "common/stringutils.h"
|
||||||
|
|
||||||
#include "common/resources/inputstream.h"
|
#include "common/resources/inputstream.h"
|
||||||
#include "common/resources/outputstream.h"
|
#include "common/resources/outputstream.h"
|
||||||
|
@ -32,9 +33,6 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <boost/property_tree/ini_parser.hpp>
|
|
||||||
|
|
||||||
namespace bp = boost::property_tree;
|
|
||||||
|
|
||||||
|
|
||||||
CFontLoader::CFontLoader()
|
CFontLoader::CFontLoader()
|
||||||
|
@ -56,7 +54,15 @@ bool CFontLoader::Init()
|
||||||
|
|
||||||
if (good)
|
if (good)
|
||||||
{
|
{
|
||||||
bp::ini_parser::read_ini(*stream, m_propertyTree);
|
std::string line;
|
||||||
|
|
||||||
|
while (std::getline(*stream, line))
|
||||||
|
{
|
||||||
|
auto parts = StrUtils::Split(line, " =");
|
||||||
|
|
||||||
|
m_fonts[parts[0]] = parts[1];
|
||||||
|
}
|
||||||
|
|
||||||
GetLogger()->Debug("Fonts config file loaded correctly. \n");
|
GetLogger()->Debug("Fonts config file loaded correctly. \n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -74,8 +80,10 @@ bool CFontLoader::Init()
|
||||||
|
|
||||||
std::optional<std::string> CFontLoader::GetFont(Gfx::FontType type) const
|
std::optional<std::string> CFontLoader::GetFont(Gfx::FontType type) const
|
||||||
{
|
{
|
||||||
auto font = m_propertyTree.get_optional<std::string>(ToString(type));
|
auto iterator = m_fonts.find(ToString(type));
|
||||||
if (font)
|
|
||||||
return std::string("/fonts/") + *font;
|
if (iterator == m_fonts.end())
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
else
|
||||||
|
return std::string("/fonts/") + iterator->second;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,9 @@
|
||||||
|
|
||||||
#include "graphics/engine/text.h"
|
#include "graphics/engine/text.h"
|
||||||
|
|
||||||
#include <boost/property_tree/ptree.hpp>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \class CFontLoader
|
* \class CFontLoader
|
||||||
|
@ -57,5 +56,5 @@ public:
|
||||||
std::optional<std::string> GetFont(Gfx::FontType type) const;
|
std::optional<std::string> GetFont(Gfx::FontType type) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::property_tree::ptree m_propertyTree;
|
std::unordered_map<std::string, std::string> m_fonts;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue