X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Ftext_decoder.cc;h=28dace7afbcf656c8827e3382d8f732fe4c6e65d;hb=bcc4e2f7dc4cd5658e199ddacb7202b00ec72cf1;hp=932a5756458f7d6a93e063f802922383164e8255;hpb=9cb73fbc0fa4643612f01665bc6d9fc430656f32;p=dcpomatic.git diff --git a/src/lib/text_decoder.cc b/src/lib/text_decoder.cc index 932a57564..28dace7af 100644 --- a/src/lib/text_decoder.cc +++ b/src/lib/text_decoder.cc @@ -33,17 +33,18 @@ using std::list; using std::cout; using std::string; using std::min; +using std::max; using boost::shared_ptr; using boost::optional; using boost::function; +using namespace dcpomatic; TextDecoder::TextDecoder ( Decoder* parent, shared_ptr c, - shared_ptr log, ContentTime first ) - : DecoderPart (parent, log) + : DecoderPart (parent) , _content (c) , _position (first) { @@ -60,7 +61,7 @@ TextDecoder::TextDecoder ( void TextDecoder::emit_bitmap_start (ContentTime from, shared_ptr image, dcpomatic::Rect rect) { - BitmapStart (ContentBitmapCaption (from, _content->type(), image, rect)); + BitmapStart (ContentBitmapText (from, image, rect)); _position = from; } @@ -94,7 +95,7 @@ TextDecoder::emit_plain_start (ContentTime from, list s) } } - PlainStart (ContentTextCaption (from, _content->type(), s)); + PlainStart (ContentStringText (from, s)); _position = from; } @@ -105,9 +106,8 @@ TextDecoder::emit_plain_start (ContentTime from, sub::Subtitle const & subtitle) bool needs_placement = false; optional bottom_line; BOOST_FOREACH (sub::Line i, subtitle.lines) { - if (!i.vertical_position.reference || 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(); } @@ -148,9 +148,14 @@ TextDecoder::emit_plain_start (ContentTime from, sub::Subtitle const & subtitle) v_align = dcp::VALIGN_TOP; } else { - DCPOMATIC_ASSERT (i.vertical_position.proportional); DCPOMATIC_ASSERT (i.vertical_position.reference); - v_position = i.vertical_position.proportional.get(); + if (i.vertical_position.proportional) { + v_position = i.vertical_position.proportional.get(); + } else { + DCPOMATIC_ASSERT (i.vertical_position.line); + DCPOMATIC_ASSERT (i.vertical_position.lines); + v_position = float(*i.vertical_position.line) / *i.vertical_position.lines; + } if (lowest_proportional) { /* Adjust line spacing */ @@ -174,15 +179,18 @@ TextDecoder::emit_plain_start (ContentTime from, sub::Subtitle const & subtitle) } dcp::HAlign h_align; + float h_position = i.horizontal_position.proportional; switch (i.horizontal_position.reference) { case sub::LEFT_OF_SCREEN: h_align = dcp::HALIGN_LEFT; + h_position = max(h_position, 0.05f); break; case sub::HORIZONTAL_CENTRE_OF_SCREEN: h_align = dcp::HALIGN_CENTER; break; case sub::RIGHT_OF_SCREEN: h_align = dcp::HALIGN_RIGHT; + h_position = max(h_position, 0.05f); break; default: h_align = dcp::HALIGN_CENTER; @@ -206,7 +214,7 @@ TextDecoder::emit_plain_start (ContentTime from, sub::Subtitle const & subtitle) dcp::Time (from.seconds(), 1000), /* XXX: hmm; this is a bit ugly (we don't know the to time yet) */ dcp::Time (), - i.horizontal_position.proportional, + h_position, h_align, v_position, v_align, @@ -233,7 +241,7 @@ TextDecoder::emit_plain_start (ContentTime from, sub::Subtitle const & subtitle) void TextDecoder::emit_stop (ContentTime to) { - Stop (to, _content->type()); + Stop (to); } void @@ -250,6 +258,17 @@ TextDecoder::emit_plain (ContentTimePeriod period, sub::Subtitle const & s) emit_stop (period.to); } +/* @param rect Area expressed as a fraction of the video frame that this subtitle + * is for (e.g. a width of 0.5 means the width of the subtitle is half the width + * of the video frame) + */ +void +TextDecoder::emit_bitmap (ContentTimePeriod period, shared_ptr image, dcpomatic::Rect rect) +{ + emit_bitmap_start (period.from, image, rect); + emit_stop (period.to); +} + void TextDecoder::seek () {