/* * This file is part of the Colobot: Gold Edition source code * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam * http://epsitec.ch; http://colobot.info; http://github.com/colobot * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see http://gnu.org/licenses */ #include "common/font_config.h" #include "common/logger.h" #include "common/make_unique.h" #include "common/resources/inputstream.h" #include "common/resources/outputstream.h" #include "common/system/system.h" #include #include #include #include #include namespace bp = boost::property_tree; CFontConfigFile::CFontConfigFile() : m_needsSave(false) , m_useCurrentDirectory(false) , m_loaded(false) { } CFontConfigFile::~CFontConfigFile() { } bool CFontConfigFile::Init() { try { std::unique_ptr stream; bool good; if (m_useCurrentDirectory) { auto inputStream = MakeUnique("/fonts/fonts.ini"); good = inputStream->good(); stream = std::move(inputStream); } else { auto inputStream = MakeUnique("/fonts/fonts.ini"); good = inputStream->is_open(); stream = std::move(inputStream); } if (good) { bp::ini_parser::read_ini(*stream, m_propertyTree); GetLogger()->Debug("Fonts config file loaded correctly. \n"); m_loaded = true; } else { return false; } } catch (std::exception & e) { GetLogger()->Error("Error on parsing config file: %s\n", e.what()); return false; } return true; } std::string CFontConfigFile::GetCommonFont() { try { std::string path = std::string("/fonts/") + m_propertyTree.get("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"; } return ""; } std::string CFontConfigFile::GetCommonBoldFont() { try { std::string path = std::string("/fonts/") + m_propertyTree.get("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("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("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("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("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 ""; }