Fix font_id_map errors when importing DCP subtitles that have no
authorCarl Hetherington <cth@carlh.net>
Tue, 20 Sep 2022 10:22:02 +0000 (12:22 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 20 Sep 2022 19:24:16 +0000 (21:24 +0200)
font declarations / tags (#2339).

src/lib/dcp_subtitle_content.cc
src/lib/text_decoder.cc
test/data
test/subtitle_font_id_test.cc

index a6cfd8d93a42c1ebbe4e5f46695ad94bcda139a3..b111bdb2a242b9aee2ba7ecb4730a61418bd4368 100644 (file)
@@ -83,6 +83,10 @@ DCPSubtitleContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job)
                        only_text()->add_font(make_shared<Font>(node->id));
                }
        }
                        only_text()->add_font(make_shared<Font>(node->id));
                }
        }
+
+       if (only_text()->fonts().empty()) {
+               only_text()->add_font(make_shared<Font>(""));
+       }
 }
 
 DCPTime
 }
 
 DCPTime
index c691f795d2d5133f7b64e63a44275a72ce0abf30..fa5ed6c7a1025b441010e625bbdffa83e60f2ac8 100644 (file)
@@ -110,7 +110,7 @@ TextDecoder::emit_plain_start (ContentTime from, vector<dcp::SubtitleString> sub
                auto string_text = StringText(
                        subtitle,
                        content()->outline_width(),
                auto string_text = StringText(
                        subtitle,
                        content()->outline_width(),
-                       subtitle.font() ? content()->get_font(*subtitle.font()) : shared_ptr<Font>(),
+                       content()->get_font(subtitle.font().get_value_or("")),
                        valign_standard
                        );
                string_text.set_text(escape_text(string_text.text()));
                        valign_standard
                        );
                string_text.set_text(escape_text(string_text.text()));
index a92011d3c4ebe0e443b6ea37c749f27c9102c156..04fc3a153081196d7f67ccf3aea1dc04f5a8b519 160000 (submodule)
--- a/test/data
+++ b/test/data
@@ -1 +1 @@
-Subproject commit a92011d3c4ebe0e443b6ea37c749f27c9102c156
+Subproject commit 04fc3a153081196d7f67ccf3aea1dc04f5a8b519
index 51bccc70a78a3c9ed724e6e6444eb0a1e2db6592..5bcf454bd2f29942032732d667e9f68c2d1f7668 100644 (file)
@@ -24,6 +24,7 @@
 #include "lib/film.h"
 #include "lib/font.h"
 #include "lib/text_content.h"
 #include "lib/film.h"
 #include "lib/font.h"
 #include "lib/text_content.h"
+#include <dcp/smpte_subtitle_asset.h>
 #include "test.h"
 #include <boost/test/unit_test.hpp>
 
 #include "test.h"
 #include <boost/test/unit_test.hpp>
 
@@ -100,3 +101,25 @@ BOOST_AUTO_TEST_CASE(make_dcp_with_subs_from_mkv)
        make_and_verify_dcp(film, { dcp::VerificationNote::Code::INVALID_PICTURE_FRAME_RATE_FOR_2K });
 }
 
        make_and_verify_dcp(film, { dcp::VerificationNote::Code::INVALID_PICTURE_FRAME_RATE_FOR_2K });
 }
 
+
+BOOST_AUTO_TEST_CASE(make_dcp_with_subs_without_font_tag)
+{
+       auto subs = content_factory("test/data/no_font.xml");
+       auto film = new_test_film2("make_dcp_with_subs_without_font_tag", { subs });
+       subs[0]->text.front()->set_use(true);
+       make_and_verify_dcp(
+               film,
+               {
+                       dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
+                       dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
+                       dcp::VerificationNote::Code::MISSING_CPL_METADATA
+               });
+
+       auto check_file = subtitle_file(film);
+       dcp::SMPTESubtitleAsset check_asset(check_file);
+       BOOST_CHECK_EQUAL(check_asset.load_font_nodes().size(), 1U);
+       auto check_font_data = check_asset.font_data();
+       BOOST_CHECK_EQUAL(check_font_data.size(), 1U);
+       BOOST_CHECK(check_font_data.begin()->second == dcp::ArrayData(default_font_file()));
+}
+