Rewritten loading of font config file

dev
Tomasz Kapuściński 2023-08-15 11:16:51 +02:00
parent 3e06584956
commit fde2b901bd
2 changed files with 18 additions and 11 deletions

View File

@ -20,6 +20,7 @@
#include "common/font_loader.h"
#include "common/logger.h"
#include "common/stringutils.h"
#include "common/resources/inputstream.h"
#include "common/resources/outputstream.h"
@ -32,9 +33,6 @@
#include <memory>
#include <utility>
#include <cstring>
#include <boost/property_tree/ini_parser.hpp>
namespace bp = boost::property_tree;
CFontLoader::CFontLoader()
@ -56,7 +54,15 @@ bool CFontLoader::Init()
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");
}
else
@ -74,8 +80,10 @@ bool CFontLoader::Init()
std::optional<std::string> CFontLoader::GetFont(Gfx::FontType type) const
{
auto font = m_propertyTree.get_optional<std::string>(ToString(type));
if (font)
return std::string("/fonts/") + *font;
return std::nullopt;
auto iterator = m_fonts.find(ToString(type));
if (iterator == m_fonts.end())
return std::nullopt;
else
return std::string("/fonts/") + iterator->second;
}

View File

@ -28,10 +28,9 @@
#include "graphics/engine/text.h"
#include <boost/property_tree/ptree.hpp>
#include <string>
#include <optional>
#include <unordered_map>
/**
* \class CFontLoader
@ -57,5 +56,5 @@ public:
std::optional<std::string> GetFont(Gfx::FontType type) const;
private:
boost::property_tree::ptree m_propertyTree;
std::unordered_map<std::string, std::string> m_fonts;
};