Fix incorrect hint about having too many subtitle lines in some cases (#2546).
authorCarl Hetherington <cth@carlh.net>
Fri, 2 Jun 2023 21:38:16 +0000 (23:38 +0200)
committerCarl Hetherington <cth@carlh.net>
Fri, 2 Jun 2023 21:38:59 +0000 (23:38 +0200)
src/lib/hints.cc
test/data
test/hints_test.cc

index b628efc31534fd53be7c7c8d29350ceab88363c3..6c574d9916b85ede608e424cdfeccbc9f7134533 100644 (file)
@@ -584,7 +584,30 @@ Hints::open_subtitle (PlayerText text, DCPTimePeriod period)
                hint (_("At least one of your subtitles starts less than 2 frames after the previous one.  It is advisable to make the gap between subtitles at least 2 frames."));
        }
 
-       if (text.string.size() > 3 && !_too_many_subtitle_lines) {
+       struct VPos
+       {
+       public:
+               dcp::VAlign align;
+               float position;
+
+               bool operator<(VPos const& other) const {
+                       if (static_cast<int>(align) != static_cast<int>(other.align)) {
+                               return static_cast<int>(align) < static_cast<int>(other.align);
+                       }
+                       return position < other.position;
+               }
+       };
+
+       /* This is rather an approximate way to count distinct lines, but I guess it will do;
+        * to make it better we need to take into account font metrics, and the SMPTE alignment
+        * debacle, and so on.
+        */
+       std::set<VPos> lines;
+       for (auto const& line: text.string) {
+               lines.insert({ line.v_align(), line.v_position() });
+       }
+
+       if (lines.size() > 3 && !_too_many_subtitle_lines) {
                _too_many_subtitle_lines = true;
                hint (_("At least one of your subtitles has more than 3 lines.  It is advisable to use no more than 3 lines."));
        }
index ece8e470df37357b9a9c29360c15213b6e71ec30..53fd88a32ec14dfed9059095cf5019adb8de04f8 160000 (submodule)
--- a/test/data
+++ b/test/data
@@ -1 +1 @@
-Subproject commit ece8e470df37357b9a9c29360c15213b6e71ec30
+Subproject commit 53fd88a32ec14dfed9059095cf5019adb8de04f8
index 55e859e0dce56ebffe5cd1ef8b1d1924c7629ce4..5e59ef9241a7b60763eb5760b557e096d42106fc 100644 (file)
@@ -153,6 +153,12 @@ BOOST_AUTO_TEST_CASE (hint_many_subtitle_lines)
 }
 
 
+BOOST_AUTO_TEST_CASE(hint_many_subtitle_lines2)
+{
+       check(TextType::OPEN_SUBTITLE, "hint_many_subtitle_lines2");
+}
+
+
 BOOST_AUTO_TEST_CASE (hint_subtitle_too_long)
 {
        check (