31 #include <fontconfig/fontconfig.h>
34 #define DBG_FT LOG_STREAM(debug, log_font)
35 #define LOG_FT LOG_STREAM(info, log_font)
36 #define WRN_FT LOG_STREAM(warn, log_font)
37 #define ERR_FT LOG_STREAM(err, log_font)
64 ERR_FT <<
"could not resolve path to fonts.cfg, file not found";
71 ERR_FT <<
"could not read fonts.cfg:\n" <<
e.message;
79 family_order_sans = fonts_config[
"family_order"];
80 family_order_mono = fonts_config[
"family_order_monospace"];
81 family_order_light = fonts_config[
"family_order_light"];
82 family_order_script = fonts_config[
"family_order_script"];
84 if(family_order_mono.empty()) {
85 ERR_FT <<
"No monospace font family order defined, falling back to sans serif order";
86 family_order_mono = family_order_sans;
89 if(family_order_light.empty()) {
90 ERR_FT <<
"No light font family order defined, falling back to sans serif order";
91 family_order_light = family_order_sans;
94 if(family_order_script.empty()) {
95 ERR_FT <<
"No script font family order defined, falling back to sans serif order";
96 family_order_script = family_order_sans;
106 return family_order_mono;
108 return family_order_light;
110 return family_order_script;
112 return family_order_sans;
123 if (!FcConfigAppFontAddDir(FcConfigGetCurrent(),
124 reinterpret_cast<const FcChar8 *
>(font_path.c_str())))
126 ERR_FT <<
"Could not load the true type fonts";
127 throw font::error(
"font config lib failed to add the font path: '" + font_path +
"'");
130 std::string font_file = font_path +
"/fonts.conf";
138 font_file_contents.insert(font_file_contents.find(
"</fontconfig>"),
"<cachedir>"+
filesystem::get_cache_dir()+
"</cachedir>\n");
141 if(!FcConfigParseAndLoadFromMemory(FcConfigGetCurrent(),
142 reinterpret_cast<const FcChar8*
>(font_file_contents.c_str()),
145 ERR_FT <<
"Could not load local font configuration";
146 throw font::error(
"font config lib failed to find font.conf: '" + font_file +
"'");
150 LOG_FT <<
"Local font configuration loaded";
156 FcConfigAppFontClear(FcConfigGetCurrent());
A config object defines a single node in a WML file, with access to child nodes.
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Equivalent to mandatory_child, but returns an empty optional if the nth child was not found.
Definitions for the interface to Wesnoth Markup Language (WML).
Declarations for File-IO.
static lg::log_domain log_font("font")
Standard logging facilities (interface).
std::string get_cache_dir()
utils::optional< std::string > get_wml_location(const std::string &path, const utils::optional< std::string > ¤t_dir)
Returns a translated path to the actual file or directory, if it exists.
std::string read_file(const std::string &fname)
Basic disk I/O - read file.
std::unique_ptr< std::istream > scoped_istream
family_class
Font classes for get_font_families().
const t_string & get_font_families(family_class fclass)
Returns the currently defined fonts.
filesystem::scoped_istream preprocess_file(const std::string &fname, preproc_map *defines)
Function to use the WML preprocessor on a file.
void read(config &cfg, std::istream &in, abstract_validator *validator)