X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Ffont_config.cc;h=5c9eebb3fb752f7d2cc4fbc104235d9f71d6bbc7;hp=c7361bc04823e7547a74b5117c5dfdbd732bd252;hb=280a456ae1da8fa648be1e9f68140f045b306e32;hpb=5a820bb8fae34591be5ac6d19a73461b9dab532a diff --git a/src/lib/font_config.cc b/src/lib/font_config.cc index c7361bc04..5c9eebb3f 100644 --- a/src/lib/font_config.cc +++ b/src/lib/font_config.cc @@ -22,6 +22,7 @@ #include "dcpomatic_assert.h" #include "font_config.h" #include +#include #include @@ -85,6 +86,33 @@ FontConfig::make_font_available(boost::filesystem::path font_file) } +optional +FontConfig::system_font_with_name(string name) +{ + optional path; + + auto pattern = FcNameParse(reinterpret_cast(name.c_str())); + auto object_set = FcObjectSetBuild(FC_FILE, nullptr); + auto font_set = FcFontList(_config, pattern, object_set); + if (font_set) { + for (int i = 0; i < font_set->nfont; ++i) { + auto font = font_set->fonts[i]; + FcChar8* file; + if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) { + path = boost::filesystem::path(reinterpret_cast(file)); + break; + } + } + FcFontSetDestroy(font_set); + } + + FcObjectSetDestroy(object_set); + FcPatternDestroy(pattern); + + return path; +} + + FontConfig * FontConfig::instance() {