give better error messages for font initialization failure
This commit is contained in:
parent
5c86a1bd76
commit
545800f9f8
5 changed files with 44 additions and 13 deletions
29
src/font/error.hpp
Normal file
29
src/font/error.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
Copyright (C) 2016 by Chris Beck<render787@gmail.com>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
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 2 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.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef FONT_ERROR_HPP
|
||||
#define FONT_ERROR_HPP
|
||||
|
||||
#include "exceptions.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace font {
|
||||
|
||||
struct error : public game::error {
|
||||
error(std::string str = "Font initialization failed") : game::error(str) {}
|
||||
};
|
||||
|
||||
} // end namespace font
|
||||
|
||||
#endif
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include "font_config.hpp"
|
||||
#include "font_description.hpp"
|
||||
#include "font/error.hpp"
|
||||
#include "sdl_ttf.hpp"
|
||||
|
||||
#include "config.hpp"
|
||||
|
@ -183,18 +184,21 @@ const t_string& get_font_families(family_class fclass)
|
|||
manager::manager()
|
||||
{
|
||||
#ifdef CAIRO_HAS_FT_FONT
|
||||
std::string font_path = game_config::path + "/fonts";
|
||||
if (!FcConfigAppFontAddDir(FcConfigGetCurrent(),
|
||||
reinterpret_cast<const FcChar8 *>((game_config::path + "/fonts").c_str())))
|
||||
reinterpret_cast<const FcChar8 *>(font_path.c_str())))
|
||||
{
|
||||
ERR_FT << "Could not load the true type fonts" << std::endl;
|
||||
throw error();
|
||||
throw font::error("font config lib failed to add the font path: '" + font_path + "'");
|
||||
}
|
||||
|
||||
std::string font_file = font_path + "/fonts.conf";
|
||||
if(!FcConfigParseAndLoad(FcConfigGetCurrent(),
|
||||
reinterpret_cast<const FcChar8*>((game_config::path + "/fonts/fonts.conf").c_str()),
|
||||
reinterpret_cast<const FcChar8*>(font_file.c_str()),
|
||||
FcFalse))
|
||||
{
|
||||
ERR_FT << "Could not load local font configuration\n";
|
||||
throw font::error("font config lib failed to find font.conf: '" + font_file + "'");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
* sdl_ttf raii object.
|
||||
*/
|
||||
|
||||
#include "exceptions.hpp"
|
||||
#include "font_options.hpp"
|
||||
#include "sdl_ttf.hpp"
|
||||
|
||||
|
@ -43,9 +42,6 @@ struct manager {
|
|||
manager(const manager &) = delete;
|
||||
manager & operator = (const manager &) = delete;
|
||||
|
||||
struct error : public game::error {
|
||||
error() : game::error("Font initialization failed") {}
|
||||
};
|
||||
private:
|
||||
|
||||
/** Initialize sdl_ttf concurrent with font::manager lifetime */
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include "sdl_ttf.hpp"
|
||||
|
||||
#include "font/error.hpp"
|
||||
#include "font_config.hpp"
|
||||
#include "font_id.hpp"
|
||||
#include "text_cache.hpp"
|
||||
|
@ -490,7 +491,7 @@ sdl_ttf::sdl_ttf() {
|
|||
const int res = TTF_Init();
|
||||
if(res == -1) {
|
||||
ERR_FT << "Could not initialize SDL_TTF" << std::endl;
|
||||
throw manager::error();
|
||||
throw font::error("SDL_TTF could not initialize, TTF_INIT returned: " + std::to_string(res));
|
||||
} else {
|
||||
LOG_FT << "Initialized true type fonts\n";
|
||||
}
|
||||
|
|
|
@ -23,17 +23,18 @@
|
|||
#include "filesystem.hpp" // for filesystem::file_exists, filesystem::io_exception, etc
|
||||
#include "floating_label.hpp"
|
||||
#include "font/font_config.hpp" // for load_font_config, etc
|
||||
#include "formula/formula.hpp" // for formula_error
|
||||
#include "font/error.hpp" // for error
|
||||
#include "formula/formula.hpp" // for formula_error
|
||||
#include "game_config.hpp" // for path, debug, debug_lua, etc
|
||||
#include "game_config_manager.hpp" // for game_config_manager, etc
|
||||
#include "game_end_exceptions.hpp"
|
||||
#include "game_launcher.hpp" // for game_launcher, etc
|
||||
#include "game_launcher.hpp" // for game_launcher, etc
|
||||
#include "gettext.hpp"
|
||||
#include "gui/core/event/handler.hpp" // for tmanager
|
||||
#include "gui/core/event/handler.hpp" // for tmanager
|
||||
#include "gui/dialogs/end_credits.hpp"
|
||||
#include "gui/dialogs/loadscreen.hpp"
|
||||
#include "gui/dialogs/title_screen.hpp" // for ttitle_screen, etc
|
||||
#include "gui/dialogs/message.hpp" // for show_error_message
|
||||
#include "gui/dialogs/message.hpp" // for show_error_message
|
||||
#include "gui/widgets/helper.hpp" // for init
|
||||
#include "image.hpp" // for flush_cache, etc
|
||||
#include "log.hpp" // for LOG_STREAM, general, logger, etc
|
||||
|
@ -1058,7 +1059,7 @@ int main(int argc, char** argv)
|
|||
} catch(CVideo::error & e) {
|
||||
std::cerr << "Could not initialize video.\n\n" << e.what() << "\n\nExiting.\n";
|
||||
error_exit(1);
|
||||
} catch(font::manager::error & e) {
|
||||
} catch(font::error & e) {
|
||||
std::cerr << "Could not initialize fonts.\n\n" << e.what() << "\n\nExiting.\n";
|
||||
error_exit(1);
|
||||
} catch(config::error& e) {
|
||||
|
|
Loading…
Add table
Reference in a new issue