Moved file font.ini to /fonts/ directory
Separated SatCom font from Colobot font1008-fix
parent
250c934b9e
commit
cf46c2457a
|
@ -44,11 +44,6 @@ CFontConfigFile::CFontConfigFile()
|
|||
|
||||
CFontConfigFile::~CFontConfigFile()
|
||||
{
|
||||
if (m_needsSave)
|
||||
{
|
||||
GetLogger()->Warn("Font config file was not properly saved! Saving now...\n");
|
||||
Save();
|
||||
}
|
||||
}
|
||||
|
||||
bool CFontConfigFile::Init()
|
||||
|
@ -59,13 +54,13 @@ bool CFontConfigFile::Init()
|
|||
bool good;
|
||||
if (m_useCurrentDirectory)
|
||||
{
|
||||
auto inputStream = MakeUnique<std::ifstream>("./fonts.ini");
|
||||
auto inputStream = MakeUnique<std::ifstream>("/fonts/fonts.ini");
|
||||
good = inputStream->good();
|
||||
stream = std::move(inputStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto inputStream = MakeUnique<CInputStream>("fonts.ini");
|
||||
auto inputStream = MakeUnique<CInputStream>("/fonts/fonts.ini");
|
||||
good = inputStream->is_open();
|
||||
stream = std::move(inputStream);
|
||||
}
|
||||
|
@ -73,6 +68,7 @@ bool CFontConfigFile::Init()
|
|||
if (good)
|
||||
{
|
||||
bp::ini_parser::read_ini(*stream, m_propertyTree);
|
||||
GetLogger()->Debug("Fonts config file loaded correctly. \n");
|
||||
m_loaded = true;
|
||||
}
|
||||
else
|
||||
|
@ -88,198 +84,92 @@ bool CFontConfigFile::Init()
|
|||
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()
|
||||
{
|
||||
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;
|
||||
}
|
||||
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());
|
||||
SetCommonFont("dvu_sans.ttf");
|
||||
return "/fonts/dvu_sans.ttf";
|
||||
}
|
||||
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()
|
||||
{
|
||||
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;
|
||||
}
|
||||
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());
|
||||
SetCommonBoldFont("dvu_sans_bold.ttf");
|
||||
return "/fonts/dvu_sans_bold.ttf";
|
||||
}
|
||||
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()
|
||||
{
|
||||
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;
|
||||
}
|
||||
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());
|
||||
SetCommonItalicFont("dvu_sans_italic.ttf");
|
||||
return "/fonts/dvu_sans_italic.ttf";
|
||||
}
|
||||
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()
|
||||
{
|
||||
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;
|
||||
}
|
||||
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());
|
||||
SetStudioFont("dvu_sans_mono.ttf");
|
||||
return "/fonts/dvu_sans_mono.ttf";
|
||||
}
|
||||
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()
|
||||
{
|
||||
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;
|
||||
}
|
||||
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());
|
||||
SetStudioBoldFont("dvu_sans_mono_bold.ttf");
|
||||
return "/fonts/dvu_sans_mono_bold.ttf";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
bool CFontConfigFile::SetStudioBoldFont(std::string filename)
|
||||
std::string CFontConfigFile::GetSatComFont()
|
||||
{
|
||||
try
|
||||
{
|
||||
m_propertyTree.put("FONT_STUDIO_BOLD", filename);
|
||||
m_needsSave = true;
|
||||
std::string path = std::string("/fonts/") + m_propertyTree.get<std::string>("FontSatCom");
|
||||
return path;
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
GetLogger()->Error("Error on editing config file: %s\n", e.what());
|
||||
return false;
|
||||
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 true;
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -47,99 +47,44 @@ public:
|
|||
* \return return true on success
|
||||
*/
|
||||
bool Init();
|
||||
|
||||
/** Saves fonts.ini
|
||||
* \return return true on success
|
||||
*/
|
||||
bool Save();
|
||||
|
||||
|
||||
/** Reads common font from file
|
||||
* \return return path to font file
|
||||
*/
|
||||
|
||||
std::string GetCommonFont();
|
||||
|
||||
/** Writes common font to file
|
||||
* \return return true on success
|
||||
*/
|
||||
|
||||
bool SetCommonFont(std::string filename);
|
||||
|
||||
|
||||
/** Reads common bold font from file
|
||||
* \return return path to font file
|
||||
*/
|
||||
|
||||
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
|
||||
* \return return path to font file
|
||||
*/
|
||||
|
||||
std::string GetCommonItalicFont();
|
||||
|
||||
/** Writes common italic font to file
|
||||
* \return return true on success
|
||||
*/
|
||||
|
||||
bool SetCommonItalicFont(std::string filename);
|
||||
|
||||
|
||||
/** Reads studio font from file
|
||||
* \return return path to font file
|
||||
*/
|
||||
|
||||
std::string GetStudioFont();
|
||||
|
||||
/** Writes studio font to file
|
||||
* \return return true on success
|
||||
*/
|
||||
|
||||
bool SetStudioFont(std::string filename);
|
||||
|
||||
/** Reads studio bold font from file
|
||||
* \return returns path to font file
|
||||
*/
|
||||
|
||||
std::string GetStudioBoldFont();
|
||||
|
||||
/** Writes studio bold font to file
|
||||
* \return return true on success
|
||||
/** Reads satcom font from file
|
||||
* \return returns path to font file
|
||||
*/
|
||||
|
||||
bool SetStudioBoldFont(std::string filename);
|
||||
std::string GetSatComFont();
|
||||
|
||||
private:
|
||||
boost::property_tree::ptree m_propertyTree;
|
||||
bool m_needsSave;
|
||||
bool m_useCurrentDirectory;
|
||||
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
|
||||
inline CFontConfigFile & GetFontConfigFile()
|
||||
{
|
||||
|
|
|
@ -131,6 +131,8 @@ bool CText::Create()
|
|||
m_fonts[FONT_COLOBOT] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetCommonFont());
|
||||
m_fonts[FONT_COLOBOT_BOLD] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetCommonBoldFont());
|
||||
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_BOLD] = MakeUnique<MultisizeFont>(GetFontConfigFile().GetStudioBoldFont());
|
||||
|
|
|
@ -88,7 +88,9 @@ enum FontType
|
|||
//! Alias for bold courier font
|
||||
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.
|
||||
FONT_BUTTON = 0x03,
|
||||
|
|
|
@ -383,7 +383,7 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc
|
|||
edit->SetState(STATE_SHADOW);
|
||||
edit->SetMultiFont(true);
|
||||
edit->SetMaxChar(10000);
|
||||
edit->SetFontType(Gfx::FONT_COLOBOT);
|
||||
edit->SetFontType(Gfx::FONT_SATCOM);
|
||||
edit->SetSoluceMode(bSoluce);
|
||||
edit->ReadText(filename.c_str());
|
||||
edit->HyperHome(filename.c_str());
|
||||
|
|
Loading…
Reference in New Issue