diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-03-05 00:47:24 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-03-05 23:52:14 +0100 |
| commit | e61cc4ff73a82ef0a6575ca5a6f960e1577af480 (patch) | |
| tree | 9f37c9c663f46919d1fd8fdec5ca08cdfd754eda | |
| parent | f3d37cc0ad95cc8e6d71246dd842e6e1d9e7b06c (diff) | |
Find missing fonts after finding missing content.
| -rw-r--r-- | src/lib/find_missing.cc | 37 | ||||
| -rw-r--r-- | test/2986_regression_test.cc | 65 | ||||
| -rw-r--r-- | test/wscript | 1 |
3 files changed, 103 insertions, 0 deletions
diff --git a/src/lib/find_missing.cc b/src/lib/find_missing.cc index 14394af04..ce8c65af3 100644 --- a/src/lib/find_missing.cc +++ b/src/lib/find_missing.cc @@ -86,6 +86,27 @@ search_by_name(Replacements& replacement_paths, boost::filesystem::path director static void +search_by_name(map<boost::filesystem::path, boost::filesystem::path>& replacements, boost::filesystem::path directory, int depth = 0) +{ + boost::system::error_code ec; + + for (auto candidate: dcp::filesystem::directory_iterator(directory, ec)) { + if (dcp::filesystem::is_regular_file(candidate.path())) { + for (auto& replacement: replacements) { + if (should_replace(replacement.first, candidate.path())) { + replacement.second = candidate.path(); + } + } + } else if (dcp::filesystem::is_directory(candidate.path()) && depth <= 2) { + search_by_name(replacements, candidate, depth + 1); + } + } +} + + + +static +void search_by_digest(Replacements& replacement_paths, boost::filesystem::path directory, int depth = 0) { boost::system::error_code ec; @@ -148,4 +169,20 @@ dcpomatic::find_missing (vector<shared_ptr<Content>> content_to_fix, boost::file } } } + + /* Check fonts */ + for (auto content: content_to_fix) { + map<boost::filesystem::path, boost::filesystem::path> fonts; + for (auto i: content->font_paths()) { + fonts[i] = i; + } + + search_by_name(fonts, is_directory(clue) ? clue : clue.parent_path()); + + for (auto const& font: fonts) { + if (font.first != font.second) { + content->replace_font_path(font.first, font.second); + } + } + } } diff --git a/test/2986_regression_test.cc b/test/2986_regression_test.cc new file mode 100644 index 000000000..29aabf8ad --- /dev/null +++ b/test/2986_regression_test.cc @@ -0,0 +1,65 @@ +/* + Copyright (C) 2025 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + + +#include "lib/content_factory.h" +#include "lib/film.h" +#include "lib/find_missing.h" +#include "lib/font.h" +#include "lib/player.h" +#include "lib/text_content.h" +#include "test.h" +#include <boost/filesystem.hpp> +#include <boost/test/unit_test.hpp> + + +using std::make_shared; + + +BOOST_AUTO_TEST_CASE(font_error_after_find_missing_test) +{ + boost::filesystem::path dir("build/test/font_error_after_find_missing_test_assets"); + boost::filesystem::remove_all(dir); + boost::filesystem::create_directories(dir); + + boost::filesystem::copy_file("test/data/15s.srt", dir / "15s.srt"); + boost::filesystem::copy_file("test/data/Inconsolata-VF.ttf", dir / "Inconsolata-VF.ttf"); + + { + auto content = content_factory(dir / "15s.srt"); + auto film = new_test_film("font_error_after_find_missing_test", content); + auto fonts = content[0]->text[0]->fonts(); + fonts.front()->set_file(dir / "Inconsolata-VF.ttf"); + film->write_metadata(); + } + + boost::filesystem::remove_all(dir); + + auto film2 = make_shared<Film>(boost::filesystem::path("build/test/font_error_after_find_missing_test")); + film2->read_metadata(); + + dcpomatic::find_missing(film2->content(), "test/data/15s.srt"); + + Player player(film2, Image::Alignment::PADDED, false); + player.set_always_burn_open_subtitles(); + for (int i = 0; i < 48; ++i) { + player.pass(); + } +} diff --git a/test/wscript b/test/wscript index 7b4e484d6..85bfccf56 100644 --- a/test/wscript +++ b/test/wscript @@ -45,6 +45,7 @@ def build(bld): obj.use = 'libdcpomatic2' obj.source = """ 2536_regression_test.cc + 2986_regression_test.cc 4k_test.cc analytics_test.cc atmos_test.cc |
