Change how whitespace in subtitles is handled.
authorCarl Hetherington <cth@carlh.net>
Thu, 16 Feb 2023 20:56:22 +0000 (21:56 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 16 Feb 2023 20:56:22 +0000 (21:56 +0100)
Previously we would discard any whitespace subtitle content we found.
This had the side-effect of making a verification test fail (checking
that at least one subtitle is in each reel; blank subtitles are often
used to avoid this warning).

Here we take any subtitle content, whitespace or not, inside a
<Text> or <Image> node which I think is a little more correct.

src/subtitle_asset.cc
src/util.cc
src/util.h
test/data/subs5.xml [new file with mode: 0644]
test/verify_test.cc

index f707c6652fa1305e2cec62499904579cee213406..4baa7b06e8bf1a83ac5a89fd432315f23707c38d 100644 (file)
@@ -324,7 +324,11 @@ SubtitleAsset::parse_subtitles (xmlpp::Element const * node, vector<ParseState>&
 void
 SubtitleAsset::maybe_add_subtitle (string text, vector<ParseState> const & parse_state, float space_before, Standard standard)
 {
-       if (empty_or_white_space (text)) {
+       auto wanted = [](ParseState const& ps) {
+               return ps.type && (ps.type.get() == ParseState::Type::TEXT || ps.type.get() == ParseState::Type::IMAGE);
+       };
+
+       if (find_if(parse_state.begin(), parse_state.end(), wanted) == parse_state.end()) {
                return;
        }
 
index b58035eaf3b91dcf623694e71af58189ec6e7908..9cc35ad6094c68e4774c3ede8fc615f7ef6710d6 100644 (file)
@@ -158,19 +158,6 @@ dcp::make_digest (boost::filesystem::path filename, function<void (float)> progr
 }
 
 
-bool
-dcp::empty_or_white_space (string s)
-{
-       for (size_t i = 0; i < s.length(); ++i) {
-               if (s[i] != ' ' && s[i] != '\n' && s[i] != '\t') {
-                       return false;
-               }
-       }
-
-       return true;
-}
-
-
 void
 dcp::init (optional<boost::filesystem::path> given_resources_directory)
 {
index 451957d823fcae14da30cd252abc228126b70dee..8261a8125165900760ed95eef107ef86f43b773a 100644 (file)
@@ -84,11 +84,6 @@ extern std::string make_digest (boost::filesystem::path filename, boost::functio
 
 extern std::string make_digest (ArrayData data);
 
-/** @param s A string
- *  @return true if the string contains only space, newline or tab characters, or is empty
- */
-extern bool empty_or_white_space (std::string s);
-
 extern bool ids_equal (std::string a, std::string b);
 extern std::string remove_urn_uuid (std::string raw);
 
diff --git a/test/data/subs5.xml b/test/data/subs5.xml
new file mode 100644 (file)
index 0000000..d75583b
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<DCSubtitle Version="1.0">
+<SubtitleID>12345678-9abc-def0-1234-56789abcdef0</SubtitleID>
+<MovieTitle>Frobozz</MovieTitle>
+<ReelNumber>1</ReelNumber>
+<Language>English</Language>
+<LoadFont Id="Arial" URI="Arial.ttf"/>
+<Font Id="Arial">
+<Subtitle SpotNumber="1" TimeIn="00:00:04:100" TimeOut="00:00:05:199" FadeUpTime="0" FadeDownTime="0">
+    <Text HAlign="center" HPosition="0.00" VAlign="top" VPosition="40.00" Direction="horizontal"> </Text>
+</Subtitle>
+</Font>
+</DCSubtitle>
index cde498309fe7f52776611dd67f1cf9ea905ffb22..396a1ef5c439721419cb089e07575151ff6d159f 100644 (file)
@@ -825,6 +825,24 @@ BOOST_AUTO_TEST_CASE(verify_interop_subtitle_asset_with_no_subtitles)
 }
 
 
+BOOST_AUTO_TEST_CASE(verify_interop_subtitle_asset_with_single_space_subtitle)
+{
+       path const dir("build/test/verify_interop_subtitle_asset_with_single_space_subtitle");
+       prepare_directory(dir);
+       copy_file("test/data/subs5.xml", dir / "subs.xml");
+       auto asset = make_shared<dcp::InteropSubtitleAsset>(dir / "subs.xml");
+       auto reel_asset = make_shared<dcp::ReelInteropSubtitleAsset>(asset, dcp::Fraction(24, 1), 16 * 24, 0);
+       write_dcp_with_single_asset(dir, reel_asset, dcp::Standard::INTEROP);
+
+       check_verify_result (
+               { dir },
+               {
+                       { dcp::VerificationNote::Type::BV21_ERROR, dcp::VerificationNote::Code::INVALID_STANDARD },
+               });
+
+}
+
+
 BOOST_AUTO_TEST_CASE (verify_valid_smpte_subtitles)
 {
        path const dir("build/test/verify_valid_smpte_subtitles");