Moved file font.ini to /fonts/ directory

Separated SatCom font from Colobot font
1008-fix
tomangelo2 2017-10-11 17:02:09 +02:00
parent 250c934b9e
commit cf46c2457a
5 changed files with 27 additions and 188 deletions

View File

@ -44,11 +44,6 @@ CFontConfigFile::CFontConfigFile()
CFontConfigFile::~CFontConfigFile() CFontConfigFile::~CFontConfigFile()
{ {
if (m_needsSave)
{
GetLogger()->Warn("Font config file was not properly saved! Saving now...\n");
Save();
}
} }
bool CFontConfigFile::Init() bool CFontConfigFile::Init()
@ -59,13 +54,13 @@ bool CFontConfigFile::Init()
bool good; bool good;
if (m_useCurrentDirectory) if (m_useCurrentDirectory)
{ {
auto inputStream = MakeUnique<std::ifstream>("./fonts.ini"); auto inputStream = MakeUnique<std::ifstream>("/fonts/fonts.ini");
good = inputStream->good(); good = inputStream->good();
stream = std::move(inputStream); stream = std::move(inputStream);
} }
else else
{ {
auto inputStream = MakeUnique<CInputStream>("fonts.ini"); auto inputStream = MakeUnique<CInputStream>("/fonts/fonts.ini");
good = inputStream->is_open(); good = inputStream->is_open();
stream = std::move(inputStream); stream = std::move(inputStream);
} }
@ -73,6 +68,7 @@ bool CFontConfigFile::Init()
if (good) if (good)
{ {
bp::ini_parser::read_ini(*stream, m_propertyTree); bp::ini_parser::read_ini(*stream, m_propertyTree);
GetLogger()->Debug("Fonts config file loaded correctly. \n");
m_loaded = true; m_loaded = true;
} }
else else
@ -88,198 +84,92 @@ bool CFontConfigFile::Init()
return true; return true;
} }
bool CFontConfigFile::Save()
{
if (m_needsSave)
{
try
{
std::unique_ptr<std::ostream> stream;
bool good;
if (m_useCurrentDirectory)
{
auto outputStream = MakeUnique<std::ofstream>("./fonts.ini");
good = outputStream->good();
stream = std::move(outputStream);
}
else
{
auto outputStream = MakeUnique<COutputStream>("fonts.ini");
good = outputStream->is_open();
stream = std::move(outputStream);
}
if (good)
{
bp::ini_parser::write_ini(*stream, m_propertyTree);
m_needsSave = false;
}
else
{
GetLogger()->Error("Error on storing fonts config file: failed to open file\n");
return false;
}
}
catch (std::exception & e)
{
GetLogger()->Error("Error on storing fonts config file: %s\n", e.what());
return false;
}
}
return true;
}
std::string CFontConfigFile::GetCommonFont() std::string CFontConfigFile::GetCommonFont()
{ {
try try
{ {
std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("FONT_COMMON"); std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("FontCommon");
return path; return path;
} }
catch (std::exception & e) 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()); GetLogger()->Log(m_loaded ? LOG_INFO : LOG_TRACE, "Error on parsing config file: %s. Default font will be used instead.\n", e.what());
SetCommonFont("dvu_sans.ttf");
return "/fonts/dvu_sans.ttf"; return "/fonts/dvu_sans.ttf";
} }
return ""; return "";
} }
bool CFontConfigFile::SetCommonFont(std::string filename)
{
try
{
m_propertyTree.put("FONT_COMMON", filename);
m_needsSave = true;
}
catch (std::exception & e)
{
GetLogger()->Error("Error on editing config file: %s\n", e.what());
return false;
}
return true;
}
std::string CFontConfigFile::GetCommonBoldFont() std::string CFontConfigFile::GetCommonBoldFont()
{ {
try try
{ {
std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("FONT_COMMON_BOLD"); std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("FontCommonBold");
return path; return path;
} }
catch (std::exception & e) 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()); GetLogger()->Log(m_loaded ? LOG_INFO : LOG_TRACE, "Error on parsing config file: %s. Default font will be used instead.\n", e.what());
SetCommonBoldFont("dvu_sans_bold.ttf");
return "/fonts/dvu_sans_bold.ttf"; return "/fonts/dvu_sans_bold.ttf";
} }
return ""; return "";
} }
bool CFontConfigFile::SetCommonBoldFont(std::string filename)
{
try
{
m_propertyTree.put("FONT_COMMON_BOLD", filename);
m_needsSave = true;
}
catch (std::exception & e)
{
GetLogger()->Error("Error on editing config file: %s\n", e.what());
return false;
}
return true;
}
std::string CFontConfigFile::GetCommonItalicFont() std::string CFontConfigFile::GetCommonItalicFont()
{ {
try try
{ {
std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("FONT_COMMON_ITALIC"); std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("FontCommonItalic");
return path; return path;
} }
catch (std::exception & e) 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()); GetLogger()->Log(m_loaded ? LOG_INFO : LOG_TRACE, "Error on parsing config file: %s. Default font will be used instead.\n", e.what());
SetCommonItalicFont("dvu_sans_italic.ttf");
return "/fonts/dvu_sans_italic.ttf"; return "/fonts/dvu_sans_italic.ttf";
} }
return ""; return "";
} }
bool CFontConfigFile::SetCommonItalicFont(std::string filename)
{
try
{
m_propertyTree.put("FONT_COMMON_ITALIC", filename);
m_needsSave = true;
}
catch (std::exception & e)
{
GetLogger()->Error("Error on editing config file: %s\n", e.what());
return false;
}
return true;
}
std::string CFontConfigFile::GetStudioFont() std::string CFontConfigFile::GetStudioFont()
{ {
try try
{ {
std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("FONT_STUDIO"); std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("FontStudio");
return path; return path;
} }
catch (std::exception & e) 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()); GetLogger()->Log(m_loaded ? LOG_INFO : LOG_TRACE, "Error on parsing config file: %s. Default font will be used instead.\n", e.what());
SetStudioFont("dvu_sans_mono.ttf");
return "/fonts/dvu_sans_mono.ttf"; return "/fonts/dvu_sans_mono.ttf";
} }
return ""; return "";
} }
bool CFontConfigFile::SetStudioFont(std::string filename)
{
try
{
m_propertyTree.put("FONT_STUDIO", filename);
m_needsSave = true;
}
catch (std::exception & e)
{
GetLogger()->Error("Error on editing config file: %s\n", e.what());
return false;
}
return true;
}
std::string CFontConfigFile::GetStudioBoldFont() std::string CFontConfigFile::GetStudioBoldFont()
{ {
try try
{ {
std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("FONT_STUDIO_BOLD"); std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("FontStudioBold");
return path; return path;
} }
catch (std::exception & e) 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()); GetLogger()->Log(m_loaded ? LOG_INFO : LOG_TRACE, "Error on parsing config file: %s. Default font will be used instead.\n", e.what());
SetStudioBoldFont("dvu_sans_mono_bold.ttf");
return "/fonts/dvu_sans_mono_bold.ttf"; return "/fonts/dvu_sans_mono_bold.ttf";
} }
return ""; return "";
} }
bool CFontConfigFile::SetStudioBoldFont(std::string filename) std::string CFontConfigFile::GetSatComFont()
{ {
try try
{ {
m_propertyTree.put("FONT_STUDIO_BOLD", filename); std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("FontSatCom");
m_needsSave = true; return path;
} }
catch (std::exception & e) catch (std::exception & e)
{ {
GetLogger()->Error("Error on editing config file: %s\n", e.what()); GetLogger()->Log(m_loaded ? LOG_INFO : LOG_TRACE, "Error on parsing config file: %s. Default font will be used instead.\n", e.what());
return false; return "/fonts/dvu_sans.ttf";
} }
return true; return "";
} }

View File

@ -47,99 +47,44 @@ public:
* \return return true on success * \return return true on success
*/ */
bool Init(); bool Init();
/** Saves fonts.ini
* \return return true on success
*/
bool Save();
/** Reads common font from file /** Reads common font from file
* \return return path to font file * \return return path to font file
*/ */
std::string GetCommonFont(); std::string GetCommonFont();
/** Writes common font to file
* \return return true on success
*/
bool SetCommonFont(std::string filename);
/** Reads common bold font from file /** Reads common bold font from file
* \return return path to font file * \return return path to font file
*/ */
std::string GetCommonBoldFont(); std::string GetCommonBoldFont();
/** Writes common bold font to file
* \return return true on success
*/
bool SetCommonBoldFont(std::string filename);
/** Reads common italic font from file /** Reads common italic font from file
* \return return path to font file * \return return path to font file
*/ */
std::string GetCommonItalicFont(); std::string GetCommonItalicFont();
/** Writes common italic font to file
* \return return true on success
*/
bool SetCommonItalicFont(std::string filename);
/** Reads studio font from file /** Reads studio font from file
* \return return path to font file * \return return path to font file
*/ */
std::string GetStudioFont(); std::string GetStudioFont();
/** Writes studio font to file
* \return return true on success
*/
bool SetStudioFont(std::string filename);
/** Reads studio bold font from file /** Reads studio bold font from file
* \return returns path to font file * \return returns path to font file
*/ */
std::string GetStudioBoldFont(); std::string GetStudioBoldFont();
/** Writes studio bold font to file /** Reads satcom font from file
* \return return true on success * \return returns path to font file
*/ */
std::string GetSatComFont();
bool SetStudioBoldFont(std::string filename);
private: private:
boost::property_tree::ptree m_propertyTree; boost::property_tree::ptree m_propertyTree;
bool m_needsSave; bool m_needsSave;
bool m_useCurrentDirectory; bool m_useCurrentDirectory;
bool m_loaded; bool m_loaded;
/*std::string m_colobotFont;
std::string m_colobotFontb;
std::string m_colobotFonti;
std::string m_courierFont;
std::string m_courierFontb;*/
}; };
/**
* \enum Fonts
* \brief enum of types of fonts used in game
*//*
enum Fonts
{
FONT_COLOBOT = 0,
FONT_COLOBOT_BOLD = 1,
FONT_COLOBOT_ITALIC = 2,
FONT_COURIER = 3,
FONT_COURIER_BOLD = 4
};*/
//! Global function to get config file instance //! Global function to get config file instance
inline CFontConfigFile & GetFontConfigFile() inline CFontConfigFile & GetFontConfigFile()
{ {

View File

@ -131,6 +131,8 @@ bool CText::Create()
m_fonts[FONT_COLOBOT] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetCommonFont()); m_fonts[FONT_COLOBOT] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetCommonFont());
m_fonts[FONT_COLOBOT_BOLD] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetCommonBoldFont()); m_fonts[FONT_COLOBOT_BOLD] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetCommonBoldFont());
m_fonts[FONT_COLOBOT_ITALIC] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetCommonItalicFont()); m_fonts[FONT_COLOBOT_ITALIC] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetCommonItalicFont());
m_fonts[FONT_SATCOM] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetSatComFont());
m_fonts[FONT_COURIER] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetStudioFont()); m_fonts[FONT_COURIER] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetStudioFont());
m_fonts[FONT_COURIER_BOLD] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetStudioBoldFont()); m_fonts[FONT_COURIER_BOLD] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetStudioBoldFont());

View File

@ -88,7 +88,9 @@ enum FontType
//! Alias for bold courier font //! Alias for bold courier font
FONT_COURIER_BOLD = FONT_COURIER | FONT_BOLD, FONT_COURIER_BOLD = FONT_COURIER | FONT_BOLD,
// 0x02 left for possible another font //! SatCom font used for interface
FONT_SATCOM = 0x02,
//! Pseudo-font loaded from textures for buttons, icons, etc. //! Pseudo-font loaded from textures for buttons, icons, etc.
FONT_BUTTON = 0x03, FONT_BUTTON = 0x03,

View File

@ -383,7 +383,7 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc
edit->SetState(STATE_SHADOW); edit->SetState(STATE_SHADOW);
edit->SetMultiFont(true); edit->SetMultiFont(true);
edit->SetMaxChar(10000); edit->SetMaxChar(10000);
edit->SetFontType(Gfx::FONT_COLOBOT); edit->SetFontType(Gfx::FONT_SATCOM);
edit->SetSoluceMode(bSoluce); edit->SetSoluceMode(bSoluce);
edit->ReadText(filename.c_str()); edit->ReadText(filename.c_str());
edit->HyperHome(filename.c_str()); edit->HyperHome(filename.c_str());