diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-04-08 01:04:37 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2023-04-09 17:23:20 +0200 |
| commit | 1c73379ed8483dcf71c5ccfc459c2c22516a9aef (patch) | |
| tree | 2da4861633a408e4a1fef78cc5cb9f608794bd1d /src/lib/font_config.cc | |
| parent | 46193d2898321c70626a80785055884396f3e09d (diff) | |
Fix subtitle font handling with in-memory fonts from SMPTE (#2509).v2.16.52
Previously we would fail to make a font available if it came from
a SMPTE MXF. In that case we have a memory buffer containing the
TTF/OTF file but no file; here we add a hack/workaround so that
in-memory font files can be used by FontConfig.
Diffstat (limited to 'src/lib/font_config.cc')
| -rw-r--r-- | src/lib/font_config.cc | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/src/lib/font_config.cc b/src/lib/font_config.cc index 40b9770c7..d4a442fc1 100644 --- a/src/lib/font_config.cc +++ b/src/lib/font_config.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2023 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -21,12 +21,15 @@ #include "dcpomatic_assert.h" #include "dcpomatic_log.h" +#include "font.h" #include "font_config.h" +#include "util.h" #include <fontconfig/fontconfig.h> #include <boost/filesystem.hpp> #include <boost/optional.hpp> +using std::shared_ptr; using std::string; using boost::optional; @@ -41,14 +44,38 @@ FontConfig::FontConfig() } +FontConfig::~FontConfig() +{ + for (auto file: _temp_files) { + boost::system::error_code ec; + boost::filesystem::remove(file, ec); + } +} + + string -FontConfig::make_font_available(boost::filesystem::path font_file) +FontConfig::make_font_available(shared_ptr<dcpomatic::Font> font) { - auto existing = _available_fonts.find(font_file); + auto existing = _available_fonts.find(font->id()); if (existing != _available_fonts.end()) { return existing->second; } + boost::filesystem::path font_file = default_font_file(); + if (font->file()) { + font_file = *font->file(); + } else if (font->data()) { + /* This font only exists in memory (so far) but FontConfig doesn't have an API to add a font + * from a memory buffer (AFAICS). + * https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/12 + * As a workaround, write the font data to a temporary file and use that. + */ + font_file = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path(); + _temp_files.push_back(font_file); + font->data()->write(font_file); + } + + /* Make this font available to DCP-o-matic */ optional<string> font_name; FcConfigAppFontAddFile (_config, reinterpret_cast<FcChar8 const *>(font_file.string().c_str())); @@ -80,7 +107,7 @@ FontConfig::make_font_available(boost::filesystem::path font_file) DCPOMATIC_ASSERT(font_name); - _available_fonts[font_file] = *font_name; + _available_fonts[font->id()] = *font_name; FcConfigBuildFonts(_config); return *font_name; @@ -135,3 +162,11 @@ FontConfig::instance() return _instance; } + +void +FontConfig::drop() +{ + delete _instance; + _instance = nullptr; +} + |
