std::shared_ptr
[dcpomatic.git] / src / lib / text_decoder.cc
index 313fbaa5c669ee3328768257d805525c9d2de20e..3f6afd710be6d32474a0f3260ddbf9c1b52e1ae5 100644 (file)
@@ -24,7 +24,6 @@
 #include "log.h"
 #include "compose.hpp"
 #include <sub/subtitle.h>
-#include <boost/shared_ptr.hpp>
 #include <boost/foreach.hpp>
 #include <boost/algorithm/string.hpp>
 #include <iostream>
@@ -34,7 +33,7 @@ using std::cout;
 using std::string;
 using std::min;
 using std::max;
-using boost::shared_ptr;
+using std::shared_ptr;
 using boost::optional;
 using boost::function;
 using namespace dcpomatic;
@@ -106,9 +105,8 @@ TextDecoder::emit_plain_start (ContentTime from, sub::Subtitle const & subtitle)
        bool needs_placement = false;
        optional<int> bottom_line;
        BOOST_FOREACH (sub::Line i, subtitle.lines) {
-               if (!i.vertical_position.reference || !i.vertical_position.lines || i.vertical_position.reference.get() == sub::TOP_OF_SUBTITLE) {
+               if (!i.vertical_position.reference || (i.vertical_position.line && !i.vertical_position.lines) || i.vertical_position.reference.get() == sub::TOP_OF_SUBTITLE) {
                        needs_placement = true;
-                       DCPOMATIC_ASSERT (i.vertical_position.line);
                        if (!bottom_line || bottom_line.get() < i.vertical_position.line.get()) {
                                bottom_line = i.vertical_position.line.get();
                        }
@@ -140,14 +138,28 @@ TextDecoder::emit_plain_start (ContentTime from, sub::Subtitle const & subtitle)
                        dcp::VAlign v_align;
                        if (needs_placement) {
                                DCPOMATIC_ASSERT (i.vertical_position.line);
-                               /* This 1.015 is an arbitrary value to lift the bottom sub off the bottom
-                                  of the screen a bit to a pleasing degree.
-                               */
-                               v_position = 1.015 -
-                                       (1 + bottom_line.get() - i.vertical_position.line.get())
-                                       * 1.2 * content()->line_spacing() * content()->y_scale() * j.font_size.proportional (72 * 11);
+                               double const multiplier = 1.2 * content()->line_spacing() * content()->y_scale() * j.font_size.proportional (72 * 11);
+                               switch (i.vertical_position.reference.get_value_or(sub::BOTTOM_OF_SCREEN)) {
+                               case sub::BOTTOM_OF_SCREEN:
+                               case sub::TOP_OF_SUBTITLE:
+                                       /* This 1.015 is an arbitrary value to lift the bottom sub off the bottom
+                                          of the screen a bit to a pleasing degree.
+                                          */
+                                       v_position = 1.015 -
+                                               (1 + bottom_line.get() - i.vertical_position.line.get()) * multiplier;
 
-                               v_align = dcp::VALIGN_TOP;
+                                       v_align = dcp::VALIGN_TOP;
+                                       break;
+                               case sub::TOP_OF_SCREEN:
+                                       /* This 0.1 is another fudge factor to bring the top line away from the top of the screen a little */
+                                       v_position = 0.12 + i.vertical_position.line.get() * multiplier;
+                                       v_align = dcp::VALIGN_TOP;
+                                       break;
+                               case sub::VERTICAL_CENTRE_OF_SCREEN:
+                                       v_position = i.vertical_position.line.get() * multiplier;
+                                       v_align = dcp::VALIGN_CENTER;
+                                       break;
+                               }
                        } else {
                                DCPOMATIC_ASSERT (i.vertical_position.reference);
                                if (i.vertical_position.proportional) {