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)
47 WRN_FT <<
"Failed opening font file '" << name <<
"': No such file or directory";
55 WRN_FT <<
"Failed opening font file '" << name <<
"': No such file or directory";
84 if(cfg_path.empty()) {
85 ERR_FT <<
"could not resolve path to fonts.cfg, file not found";
92 ERR_FT <<
"could not read fonts.cfg:\n" <<
e.message;
100 family_order_sans = fonts_config[
"family_order"];
101 family_order_mono = fonts_config[
"family_order_monospace"];
102 family_order_light = fonts_config[
"family_order_light"];
103 family_order_script = fonts_config[
"family_order_script"];
105 if(family_order_mono.empty()) {
106 ERR_FT <<
"No monospace font family order defined, falling back to sans serif order";
107 family_order_mono = family_order_sans;
110 if(family_order_light.empty()) {
111 ERR_FT <<
"No light font family order defined, falling back to sans serif order";
112 family_order_light = family_order_sans;
115 if(family_order_script.empty()) {
116 ERR_FT <<
"No script font family order defined, falling back to sans serif order";
117 family_order_script = family_order_sans;
127 return family_order_mono;
129 return family_order_light;
131 return family_order_script;
133 return family_order_sans;
144 if (!FcConfigAppFontAddDir(FcConfigGetCurrent(),
145 reinterpret_cast<const FcChar8 *
>(font_path.c_str())))
147 ERR_FT <<
"Could not load the true type fonts";
148 throw font::error(
"font config lib failed to add the font path: '" + font_path +
"'");
151 std::string font_file = font_path +
"/fonts.conf";
159 font_file_contents.insert(font_file_contents.find(
"</fontconfig>"),
"<cachedir>"+
filesystem::get_cache_dir()+
"</cachedir>\n");
162 if(!FcConfigParseAndLoadFromMemory(FcConfigGetCurrent(),
163 reinterpret_cast<const FcChar8*
>(font_file_contents.c_str()),
166 ERR_FT <<
"Could not load local font configuration";
167 throw font::error(
"font config lib failed to find font.conf: '" + font_file +
"'");
171 LOG_FT <<
"Local font configuration loaded";
177 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)
Euivalent to mandatory_child, but returns an empty optional if the nth child was not found.
Declarations for File-IO.
static lg::log_domain log_font("font")
Standard logging facilities (interface).
std::string get_cache_dir()
static bool file_exists(const bfs::path &fpath)
std::string get_wml_location(const std::string &filename, const std::string ¤t_dir)
Returns a complete path to the actual WML file or directory or an empty string if the file isn't pres...
std::string read_file(const std::string &fname)
Basic disk I/O - read file.
std::unique_ptr< std::istream > scoped_istream
Collection of helper functions relating to Pango formatting.
family_class
Font classes for get_font_families().
bool check_font_file(std::string name)
Test if a font file exists.
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)