Fix vertical alignment with subrip and embedded SSA \an codes. v2.15.90
authorCarl Hetherington <cth@carlh.net>
Mon, 20 Jul 2020 14:25:43 +0000 (16:25 +0200)
committerCarl Hetherington <cth@carlh.net>
Mon, 20 Jul 2020 14:25:43 +0000 (16:25 +0200)
src/lib/text_decoder.cc

index 28dace7afbcf656c8827e3382d8f732fe4c6e65d..8146d33aa416e3d6574c0be4b3898c377ecec2e7 100644 (file)
@@ -139,14 +139,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) {