diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-06-02 12:20:41 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-06-07 10:30:31 +0200 |
| commit | dbfcc0fa0dccbc8f0b9056bf47dbab36aa69e55c (patch) | |
| tree | 615324436d4986db85e8bc0f96e10e16b62c2684 | |
| parent | 0f18545a858d0351c60aa8ee366e44eefd01e27e (diff) | |
Ask fontconfig to scan the system for fonts requested by text subtitle files (#2264).
| -rw-r--r-- | src/lib/font_config.cc | 28 | ||||
| -rw-r--r-- | src/lib/font_config.h | 1 | ||||
| -rw-r--r-- | src/lib/string_text_file_content.cc | 18 |
3 files changed, 40 insertions, 7 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() { diff --git a/src/lib/font_config.h b/src/lib/font_config.h index 7527d9127..6dadbae8a 100644 --- a/src/lib/font_config.h +++ b/src/lib/font_config.h @@ -32,6 +32,7 @@ public: static FontConfig* instance(); std::string make_font_available(boost::filesystem::path font_file); + boost::optional<boost::filesystem::path> system_font_with_name(std::string name); private: FontConfig(); diff --git a/src/lib/string_text_file_content.cc b/src/lib/string_text_file_content.cc index 3750b0a50..eea9362bb 100644 --- a/src/lib/string_text_file_content.cc +++ b/src/lib/string_text_file_content.cc @@ -19,13 +19,15 @@ */ -#include "string_text_file_content.h" -#include "util.h" -#include "string_text_file.h" #include "film.h" #include "font.h" +#include "font_config.h" +#include "string_text_file.h" +#include "string_text_file_content.h" #include "text_content.h" +#include "util.h" #include <dcp/raw_convert.h> +#include <fontconfig/fontconfig.h> #include <libxml++/libxml++.h> #include <iostream> @@ -76,10 +78,12 @@ StringTextFileContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job } for (auto name: names) { - /* Make a font for each family name that somebody might later - * ask about. - */ - only_text()->add_font(make_shared<Font>(name)); + auto path = FontConfig::instance()->system_font_with_name(name); + if (path) { + only_text()->add_font(make_shared<Font>(name, *path)); + } else { + only_text()->add_font(make_shared<Font>(name)); + } } boost::mutex::scoped_lock lm (_mutex); |
