39 #include <cairo-features.h> 41 #ifdef CAIRO_HAS_WIN32_FONT 43 #undef CAIRO_HAS_FT_FONT 46 #ifdef CAIRO_HAS_FT_FONT 47 #include <fontconfig/fontconfig.h> 50 #if !defined(CAIRO_HAS_FT_FONT) && !defined(CAIRO_HAS_WIN32_FONT) 51 #error unable to find font loading tools. 55 #define DBG_FT LOG_STREAM(debug, log_font) 56 #define LOG_FT LOG_STREAM(info, log_font) 57 #define WRN_FT LOG_STREAM(warn, log_font) 58 #define ERR_FT LOG_STREAM(err, log_font) 68 WRN_FT <<
"Failed opening font file '" << name <<
"': No such file or directory" << std::endl;
76 WRN_FT <<
"Failed opening font file '" << name <<
"': No such file or directory" << std::endl;
86 #ifdef CAIRO_HAS_WIN32_FONT 87 bool is_valid_font_file(
const std::string& file)
89 using namespace std::literals::string_literals;
90 static const std::array font_exts {
".ttf"s,
".ttc"s,
".otf"s };
92 for(
const std::string& ext : font_exts) {
120 if(cfg_path.empty()) {
121 ERR_FT <<
"could not resolve path to fonts.cfg, file not found\n";
128 ERR_FT <<
"could not read fonts.cfg:\n" 137 family_order_sans = fonts_config[
"family_order"];
138 family_order_mono = fonts_config[
"family_order_monospace"];
139 family_order_light = fonts_config[
"family_order_light"];
140 family_order_script = fonts_config[
"family_order_script"];
142 if(family_order_mono.empty()) {
143 ERR_FT <<
"No monospace font family order defined, falling back to sans serif order\n";
144 family_order_mono = family_order_sans;
147 if(family_order_light.empty()) {
148 ERR_FT <<
"No light font family order defined, falling back to sans serif order\n";
149 family_order_light = family_order_sans;
152 if(family_order_script.empty()) {
153 ERR_FT <<
"No script font family order defined, falling back to sans serif order\n";
154 family_order_script = family_order_sans;
164 return family_order_mono;
166 return family_order_light;
168 return family_order_script;
170 return family_order_sans;
180 #ifdef CAIRO_HAS_FT_FONT 182 if (!FcConfigAppFontAddDir(FcConfigGetCurrent(),
183 reinterpret_cast<const FcChar8 *>(font_path.c_str())))
185 ERR_FT <<
"Could not load the true type fonts" << std::endl;
186 throw font::error(
"font config lib failed to add the font path: '" + font_path +
"'");
189 std::string font_file = font_path +
"/fonts.conf";
190 if(!FcConfigParseAndLoad(FcConfigGetCurrent(),
191 reinterpret_cast<const FcChar8*>(font_file.c_str()),
194 ERR_FT <<
"Could not load local font configuration\n";
195 throw font::error(
"font config lib failed to find font.conf: '" + font_file +
"'");
199 LOG_FT <<
"Local font configuration loaded\n";
203 #ifdef CAIRO_HAS_WIN32_FONT 205 std::vector<std::string> files;
209 for(
const std::string& file : files) {
210 if(is_valid_font_file(file))
212 const std::wstring wfile =
unicode_cast<std::wstring>(file);
213 AddFontResourceExW(wfile.c_str(), FR_PRIVATE,
nullptr);
222 #ifdef CAIRO_HAS_FT_FONT 223 FcConfigAppFontClear(FcConfigGetCurrent());
226 #ifdef CAIRO_HAS_WIN32_FONT 228 std::vector<std::string> files;
231 for(
const std::string& file : files) {
232 if(is_valid_font_file(file))
234 const std::wstring wfile =
unicode_cast<std::wstring>(file);
235 RemoveFontResourceExW(wfile.c_str(), FR_PRIVATE,
nullptr);
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
family_class
Font classes for get_font_families().
bool check_font_file(std::string name)
Test if a font file exists.
Collection of helper functions relating to Pango formatting.
static bool file_exists(const bfs::path &fpath)
bool ends_with(const std::string &str, const std::string &suffix)
ucs4_convert_impl::enableif< TD, typename TS::value_type >::type unicode_cast(const TS &source)
Definitions for the interface to Wesnoth Markup Language (WML).
const t_string & get_font_families(family_class fclass)
Returns the currently defined fonts.
void read(config &cfg, std::istream &in, abstract_validator *validator)
void get_files_in_dir(const std::string &dir, std::vector< std::string > *files, std::vector< std::string > *dirs, name_mode mode, filter_mode filter, reorder_mode reorder, file_tree_checksum *checksum)
Get a list of all files and/or directories in a given directory.
bool is_directory(const std::string &fname)
Returns true if the given file is a directory.
std::unique_ptr< std::istream > scoped_istream
static lg::log_domain log_font("font")
const std::vector< std::string > & get_binary_paths(const std::string &type)
Returns a vector with all possible paths to a given type of binary, e.g.
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...
static map_location::DIRECTION s
Declarations for File-IO.
Standard logging facilities (interface).
A config object defines a single node in a WML file, with access to child nodes.
filesystem::scoped_istream preprocess_file(const std::string &fname, preproc_map *defines)
Function to use the WML preprocessor on a file.