Fix incorrect hint about having too many subtitle lines in some cases (#2546).
[dcpomatic.git] / src / lib / hints.cc
index 027510eca8015dafa55c9e38c32b04a261fd7fe4..6c574d9916b85ede608e424cdfeccbc9f7134533 100644 (file)
 #include "audio_processor.h"
 #include "compose.hpp"
 #include "config.h"
+#include "constants.h"
 #include "content.h"
 #include "cross.h"
 #include "dcp_content_type.h"
 #include "film.h"
 #include "font.h"
-#include "font_data.h"
 #include "hints.h"
 #include "maths_util.h"
 #include "player.h"
 #include "ratio.h"
 #include "text_content.h"
-#include "types.h"
 #include "video_content.h"
 #include "writer.h"
 #include <dcp/cpl.h>
@@ -419,6 +418,8 @@ try
        struct timeval last_pulse;
        gettimeofday (&last_pulse, 0);
 
+       _writer->write (player->get_subtitle_fonts());
+
        while (!player->pass()) {
 
                struct timeval now;
@@ -438,7 +439,6 @@ try
                check_loudness ();
        }
 
-       _writer->write (player->get_subtitle_fonts());
 
        if (_long_subtitle && !_very_long_subtitle) {
                hint (_("At least one of your subtitle lines has more than 52 characters.  It is recommended to make each line 52 characters at most in length."));
@@ -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."));
        }