31 #include <fontconfig/fontconfig.h>
33 #include <pango/pangocairo.h>
37 #define DBG_FT LOG_STREAM(debug, log_font)
38 #define LOG_FT LOG_STREAM(info, log_font)
39 #define WRN_FT LOG_STREAM(warn, log_font)
40 #define ERR_FT LOG_STREAM(err, log_font)
50 font_families() =
default;
53 :
sans(
cfg[
"family_order"].t_str())
54 ,
mono(
cfg[
"family_order_monospace"].t_str())
55 ,
script(
cfg[
"family_order_script"].t_str())
58 ERR_FT <<
"No monospace font family defined, falling back to sans serif";
63 ERR_FT <<
"No script font family defined, falling back to sans serif";
73 font_families families;
87 }
catch(
const utils::bad_optional_access&) {
88 ERR_FT <<
"could not resolve path to fonts.cfg, file not found";
92 ERR_FT <<
"could not read fonts.cfg:\n" <<
e.message;
100 return families.mono;
102 return families.script;
104 return families.sans;
115 if (!FcConfigAppFontAddDir(FcConfigGetCurrent(),
116 reinterpret_cast<const FcChar8 *
>(font_path.c_str())))
118 ERR_FT <<
"Could not load the true type fonts";
119 throw font::error(
"font config lib failed to add the font path: '" + font_path +
"'");
122 std::string font_file = font_path +
"/fonts.conf";
130 font_file_contents.insert(font_file_contents.find(
"</fontconfig>"),
"<cachedir>"+
filesystem::get_cache_dir()+
"</cachedir>\n");
133 if(!FcConfigParseAndLoadFromMemory(FcConfigGetCurrent(),
134 reinterpret_cast<const FcChar8*
>(font_file_contents.c_str()),
137 ERR_FT <<
"Could not load local font configuration";
138 throw font::error(
"font config lib failed to find font.conf: '" + font_file +
"'");
142 LOG_FT <<
"Local font configuration loaded";
153 PangoFontMap* fc_font_map = pango_cairo_font_map_new_for_font_type(CAIRO_FONT_TYPE_FT);
155 pango_cairo_font_map_set_default(PANGO_CAIRO_FONT_MAP(fc_font_map));
156 g_object_unref(fc_font_map);
158 ERR_FT <<
"Could not create a fontconfig-backed Pango font map";
165 FcConfigAppFontClear(FcConfigGetCurrent());
A config object defines a single node in a WML file, with access to child nodes.
config & mandatory_child(std::string_view key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
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.
const t_string & get_font_families(family_class fclass)
Returns the currently defined fonts.
config read(std::istream &in, abstract_validator *validator)
filesystem::scoped_istream preprocess_file(const std::string &fname, preproc_map &defines)
Function to use the WML preprocessor on a file.
std::unique_ptr< MIX_Audio, decltype(&MIX_DestroyAudio)> value