diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-06-02 12:20:41 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-06-07 17:01:06 +0200 |
| commit | 280a456ae1da8fa648be1e9f68140f045b306e32 (patch) | |
| tree | 41647ec891fd5a8cbd2bae8279f72e86fbbba687 /src/lib/font_config.cc | |
| parent | 5a820bb8fae34591be5ac6d19a73461b9dab532a (diff) | |
Ask fontconfig to scan the system for fonts requested by text subtitle files (#2264).
Diffstat (limited to 'src/lib/font_config.cc')
| -rw-r--r-- | src/lib/font_config.cc | 28 |
1 files changed, 28 insertions, 0 deletions
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 <fontconfig/fontconfig.h> +#include <boost/filesystem.hpp> #include <boost/optional.hpp> @@ -85,6 +86,33 @@ FontConfig::make_font_available(boost::filesystem::path font_file) } +optional<boost::filesystem::path> +FontConfig::system_font_with_name(string name) +{ + optional<boost::filesystem::path> path; + + auto pattern = FcNameParse(reinterpret_cast<FcChar8 const*>(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<char*>(file)); + break; + } + } + FcFontSetDestroy(font_set); + } + + FcObjectSetDestroy(object_set); + FcPatternDestroy(pattern); + + return path; +} + + FontConfig * FontConfig::instance() { |
