X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fsubtitle_decoder.cc;h=90bedf0ce8996925bc1c52d90704b43a4565b98e;hb=67a404fff364c6e1fa02eab270755895ba0e1fe8;hp=43ee4c457c040c658f415180aef2db4536b58549;hpb=ba8a5a15cc27988e2bbc6acd470d8532f1d8e99f;p=dcpomatic.git diff --git a/src/lib/subtitle_decoder.cc b/src/lib/subtitle_decoder.cc index 43ee4c457..90bedf0ce 100644 --- a/src/lib/subtitle_decoder.cc +++ b/src/lib/subtitle_decoder.cc @@ -40,10 +40,12 @@ using boost::function; SubtitleDecoder::SubtitleDecoder ( Decoder* parent, shared_ptr c, - shared_ptr log + shared_ptr log, + ContentTime first ) : DecoderPart (parent, log) , _content (c) + , _position (first) { } @@ -64,14 +66,25 @@ SubtitleDecoder::emit_image_start (ContentTime from, shared_ptr image, dc void SubtitleDecoder::emit_text_start (ContentTime from, list 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, "<", "<"); boost::algorithm::replace_all (t, ">", ">"); 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()); + } + i.set_effect (content()->effect()); + i.set_fade_up_time (dcp::Time(content()->fade_in().seconds(), 1000)); + i.set_fade_down_time (dcp::Time(content()->fade_out().seconds(), 1000)); } TextStart (ContentTextSubtitle (from, s)); @@ -81,7 +94,7 @@ SubtitleDecoder::emit_text_start (ContentTime from, list s) void SubtitleDecoder::emit_text_start (ContentTime from, sub::Subtitle const & subtitle) { - /* See if our next subtitle needs to be placed on screen by us */ + /* See if our next subtitle needs to be vertically placed on screen by us */ bool needs_placement = false; optional bottom_line; BOOST_FOREACH (sub::Line i, subtitle.lines) { @@ -141,7 +154,7 @@ SubtitleDecoder::emit_text_start (ContentTime from, sub::Subtitle const & subtit case sub::TOP_OF_SCREEN: v_align = dcp::VALIGN_TOP; break; - case sub::CENTRE_OF_SCREEN: + case sub::VERTICAL_CENTRE_OF_SCREEN: v_align = dcp::VALIGN_CENTER; break; case sub::BOTTOM_OF_SCREEN: @@ -153,36 +166,55 @@ 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: + h_align = dcp::HALIGN_LEFT; + break; + case sub::HORIZONTAL_CENTRE_OF_SCREEN: + h_align = dcp::HALIGN_CENTER; + break; + 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), /* XXX: hmm; this is a bit ugly (we don't know the to time yet) */ dcp::Time (), - 0, - dcp::HALIGN_CENTER, + i.horizontal_position.proportional, + h_align, v_position, 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 () ) ); } @@ -210,3 +242,9 @@ SubtitleDecoder::emit_text (ContentTimePeriod period, sub::Subtitle const & s) emit_text_start (period.from, s); emit_stop (period.to); } + +void +SubtitleDecoder::seek () +{ + _position = ContentTime (); +}