Merge branch 'master' of ssh://git.carlh.net/home/carl/git/dcpomatic
[dcpomatic.git] / src / lib / subtitle_decoder.cc
index a3eed637416b7d226e983c5cd3d8f9df7ab09bbe..32cae6accc0e40318ad495944bcb3ce2aedd6beb 100644 (file)
@@ -40,10 +40,12 @@ using boost::function;
 SubtitleDecoder::SubtitleDecoder (
        Decoder* parent,
        shared_ptr<const SubtitleContent> c,
-       shared_ptr<Log> log
+       shared_ptr<Log> log,
+       ContentTime first
        )
        : DecoderPart (parent, log)
        , _content (c)
+       , _position (first)
 {
 
 }
@@ -59,19 +61,37 @@ void
 SubtitleDecoder::emit_image_start (ContentTime from, shared_ptr<Image> image, dcpomatic::Rect<double> rect)
 {
        ImageStart (ContentImageSubtitle (from, image, rect));
+       _position = from;
 }
 
 void
 SubtitleDecoder::emit_text_start (ContentTime from, list<dcp::SubtitleString> s)
 {
-       /* We must escape < and > in strings, otherwise they might confuse our subtitle
-          renderer (which uses some HTML-esque markup to do bold/italic etc.)
-       */
        BOOST_FOREACH (dcp::SubtitleString& i, s) {
+               /* We must escape < and > in strings, otherwise they might confuse our subtitle
+                  renderer (which uses some HTML-esque markup to do bold/italic etc.)
+               */
                string t = i.text ();
                boost::algorithm::replace_all (t, "<", "&lt;");
                boost::algorithm::replace_all (t, ">", "&gt;");
                i.set_text (t);
+
+               /* Set any forced appearance */
+               if (content()->colour()) {
+                       i.set_colour (*content()->colour());
+               }
+               if (content()->effect_colour()) {
+                       i.set_effect_colour (*content()->effect_colour());
+               }
+               if (content()->effect()) {
+                       i.set_effect (*content()->effect());
+               }
+               if (content()->fade_in()) {
+                       i.set_fade_up_time (dcp::Time(content()->fade_in()->seconds(), 1000));
+               }
+               if (content()->fade_out()) {
+                       i.set_fade_down_time (dcp::Time(content()->fade_out()->seconds(), 1000));
+               }
        }
 
        TextStart (ContentTextSubtitle (from, s));
@@ -153,13 +173,6 @@ SubtitleDecoder::emit_text_start (ContentTime from, sub::Subtitle const & subtit
                                }
                        }
 
-                       dcp::Effect effect = dcp::NONE;
-                       if (content()->outline()) {
-                               effect = dcp::BORDER;
-                       } else if (content()->shadow()) {
-                               effect = dcp::SHADOW;
-                       }
-
                        dcp::HAlign h_align;
                        switch (i.horizontal_position.reference) {
                        case sub::LEFT_OF_SCREEN:
@@ -171,16 +184,23 @@ SubtitleDecoder::emit_text_start (ContentTime from, sub::Subtitle const & subtit
                        case sub::RIGHT_OF_SCREEN:
                                h_align = dcp::HALIGN_RIGHT;
                                break;
+                       default:
+                               h_align = dcp::HALIGN_CENTER;
+                               break;
                        }
 
+                       /* The idea here (rightly or wrongly) is that we set the appearance based on the
+                          values in the libsub objects, and these are overridden with values from the
+                          content by the other emit_text_start() above.
+                       */
+
                        out.push_back (
                                dcp::SubtitleString (
                                        string(TEXT_FONT_ID),
                                        j.italic,
                                        j.bold,
                                        j.underline,
-                                       /* force the colour to whatever is configured */
-                                       content()->colour(),
+                                       j.colour.dcp(),
                                        j.font_size.points (72 * 11),
                                        1.0,
                                        dcp::Time (from.seconds(), 1000),
@@ -192,10 +212,16 @@ SubtitleDecoder::emit_text_start (ContentTime from, sub::Subtitle const & subtit
                                        v_align,
                                        dcp::DIRECTION_LTR,
                                        j.text,
-                                       effect,
-                                       content()->effect_colour(),
-                                       dcp::Time (content()->fade_in().seconds(), 1000),
-                                       dcp::Time (content()->fade_out().seconds(), 1000)
+                                       dcp::NONE,
+                                       j.effect_colour.get_value_or(sub::Colour(0, 0, 0)).dcp(),
+                                       /* Hack: we should use subtitle.fade_up and subtitle.fade_down here
+                                          but the times of these often don't have a frame rate associated
+                                          with them so the sub::Time won't convert them to milliseconds without
+                                          throwing an exception.  Since only DCP subs fill those in (and we don't
+                                          use libsub for DCP subs) we can cheat by just putting 0 in here.
+                                       */
+                                       dcp::Time (),
+                                       dcp::Time ()
                                        )
                                );
                }