Compare LoadFont URIs and asset paths correctly (DoM #2402).
authorCarl Hetherington <cth@carlh.net>
Sat, 7 Jan 2023 23:22:55 +0000 (00:22 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 8 Jan 2023 13:24:44 +0000 (14:24 +0100)
src/interop_subtitle_asset.cc
test/combine_test.cc

index 1e0fe180636e71566bd747c3a8d4ab11f26a79bb..b815da555e411064f48f6997f73e513564e7b2b7 100644 (file)
@@ -241,7 +241,11 @@ InteropSubtitleAsset::resolve_fonts (vector<shared_ptr<Asset>> assets)
 
                for (auto load_font_node: _load_font_nodes) {
                        auto iter = std::find_if(_fonts.begin(), _fonts.end(), [load_font_node](Font const& font) { return font.load_id == load_font_node->id; });
-                       if (iter == _fonts.end() && font->file() && load_font_node->uri == font->file()->leaf().string()) {
+
+                       DCP_ASSERT(_file);
+                       auto const path_in_load_font_node = _file->parent_path() / load_font_node->uri;
+
+                       if (iter == _fonts.end() && font->file() && path_in_load_font_node == *font->file()) {
                                _fonts.push_back(Font(load_font_node->id, asset->id(), font->file().get()));
                        }
                }
index 709ec080fea71bd18222346b1702c9e79f98e067..9fea304a3cefcabc6d9c3c194f9852868ea109e4 100644 (file)
@@ -42,6 +42,7 @@
 #include "test.h"
 #include "types.h"
 #include "verify.h"
+#include "reel_interop_subtitle_asset.h"
 #include "reel_markers_asset.h"
 #include <boost/algorithm/string.hpp>
 #include <boost/optional.hpp>
@@ -434,5 +435,54 @@ BOOST_AUTO_TEST_CASE (check_cpls_unchanged_after_combine)
 }
 
 
+/** The combine process would write multiple fonts with the same ID (#2402) */
+BOOST_AUTO_TEST_CASE(combine_multi_reel_subtitles)
+{
+       boost::filesystem::path in = "build/test/combine_multi_reel_subtitles_in";
+       boost::filesystem::path out = "build/test/combine_multi_reel_subtitles_out";
+       remove_all(out);
+
+       auto dcp = make_simple(in, 2, 24, dcp::Standard::INTEROP);
+
+       dcp::ArrayData data1(4096);
+       memset(data1.data(), 0, data1.size());
+
+       auto subs1 = make_shared<dcp::InteropSubtitleAsset>();
+       subs1->add(simple_subtitle());
+       boost::filesystem::create_directory(in / "subs1");
+       subs1->add_font("afont1", data1);
+       subs1->write(in / "subs1" / "subs1.xml");
+
+       dcp::ArrayData data2(4096);
+       memset(data2.data(), 1, data1.size());
+
+       auto subs2 = make_shared<dcp::InteropSubtitleAsset>();
+       subs2->add(simple_subtitle());
+       boost::filesystem::create_directory(in / "subs2");
+       subs2->add_font("afont2", data2);
+       subs2->write(in / "subs2" / "subs2.xml");
+
+       auto reel_subs1 = make_shared<dcp::ReelInteropSubtitleAsset>(subs1, dcp::Fraction(24, 1), 240, 0);
+       dcp->cpls()[0]->reels()[0]->add(reel_subs1);
+
+       auto reel_subs2 = make_shared<dcp::ReelInteropSubtitleAsset>(subs2, dcp::Fraction(24, 1), 240, 0);
+       dcp->cpls()[0]->reels()[1]->add(reel_subs2);
+
+       dcp->write_xml();
+
+       dcp::combine({in}, out);
+
+       check_combined({in}, out);
+
+       auto notes = dcp::verify({out}, &stage, &progress, xsd_test);
+       vector<dcp::VerificationNote> filtered_notes;
+       std::copy_if(notes.begin(), notes.end(), std::back_inserter(filtered_notes), [](dcp::VerificationNote const& i) {
+               return i.code() != dcp::VerificationNote::Code::INVALID_STANDARD && i.code() != dcp::VerificationNote::Code::MISMATCHED_PKL_ANNOTATION_TEXT_WITH_CPL;
+       });
+       dump_notes(filtered_notes);
+       BOOST_CHECK(filtered_notes.empty());
+}
+
+
 /* XXX: same CPL names */
 /* XXX: Interop PNG subs */