X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fsubrip_decoder.cc;h=6ed2e5254fb5c9be4847fd00c3df4eb31a42b865;hb=661de111c0dbc968ecb004eca5b26f8400b136f1;hp=2ae285b5ede17586143aa56728f37e2877a773b3;hpb=152b14ab5509678f3d68b52a1ed275cfdc38191b;p=dcpomatic.git diff --git a/src/lib/subrip_decoder.cc b/src/lib/subrip_decoder.cc index 2ae285b5e..6ed2e5254 100644 --- a/src/lib/subrip_decoder.cc +++ b/src/lib/subrip_decoder.cc @@ -23,7 +23,10 @@ using std::list; using std::vector; +using std::string; +using std::cout; using boost::shared_ptr; +using boost::optional; SubRipDecoder::SubRipDecoder (shared_ptr content) : SubtitleDecoder (content) @@ -39,15 +42,13 @@ SubRipDecoder::seek (ContentTime time, bool accurate) SubtitleDecoder::seek (time, accurate); _next = 0; - list::const_iterator i = _subtitles[_next].pieces.begin(); - while (i != _subtitles[_next].pieces.end() && _subtitles[_next].period.from < time) { - ++i; + while (_next < _subtitles.size() && ContentTime::from_seconds (_subtitles[_next].from.all_as_seconds ()) < time) { + ++_next; } - } bool -SubRipDecoder::pass () +SubRipDecoder::pass (PassReason) { if (_next >= _subtitles.size ()) { return true; @@ -56,25 +57,26 @@ SubRipDecoder::pass () /* XXX: we are ignoring positioning specified in the file */ list out; - for (list::const_iterator i = _subtitles[_next].pieces.begin(); i != _subtitles[_next].pieces.end(); ++i) { - out.push_back ( - dcp::SubtitleString ( - "Arial", - i->italic, - dcp::Color (255, 255, 255), - /* .srt files don't specify size, so this is an arbitrary value */ - 48, - dcp::Time (rint (_subtitles[_next].period.from.seconds() * 250)), - dcp::Time (rint (_subtitles[_next].period.to.seconds() * 250)), - 0.2, - dcp::BOTTOM, - i->text, - dcp::NONE, - dcp::Color (255, 255, 255), - 0, - 0 - ) - ); + for (list::const_iterator i = _subtitles[_next].lines.begin(); i != _subtitles[_next].lines.end(); ++i) { + for (list::const_iterator j = i->blocks.begin(); j != i->blocks.end(); ++j) { + out.push_back ( + dcp::SubtitleString ( + SubRipContent::font_id, + j->italic, + dcp::Colour (255, 255, 255), + j->font_size.points (72 * 11), + dcp::Time (_subtitles[_next].from.all_as_seconds()), + dcp::Time (_subtitles[_next].to.all_as_seconds()), + i->vertical_position.line.get() * (1.5 / 22) + 0.8, + dcp::TOP, + j->text, + dcp::NONE, + dcp::Colour (255, 255, 255), + 0, + 0 + ) + ); + } } text_subtitle (out); @@ -83,15 +85,27 @@ SubRipDecoder::pass () } list -SubRipDecoder::subtitles_during (ContentTimePeriod p, bool starting) const +SubRipDecoder::image_subtitles_during (ContentTimePeriod, bool) const +{ + return list (); +} + +list +SubRipDecoder::text_subtitles_during (ContentTimePeriod p, bool starting) const { /* XXX: inefficient */ list d; - for (vector::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) { - if ((starting && p.contains (i->period.from)) || (!starting && p.overlaps (i->period))) { - d.push_back (i->period); + for (vector::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) { + + ContentTimePeriod t ( + ContentTime::from_seconds (i->from.all_as_seconds()), + ContentTime::from_seconds (i->to.all_as_seconds()) + ); + + if ((starting && p.contains (t.from)) || (!starting && p.overlaps (t))) { + d.push_back (t); } }