X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fsubrip_decoder.cc;h=2ae285b5ede17586143aa56728f37e2877a773b3;hb=152b14ab5509678f3d68b52a1ed275cfdc38191b;hp=deee82847e642778dfd26185836778170e1c9e8b;hpb=86214f4619476b1a4951e15f002a93743b5f7a1e;p=dcpomatic.git diff --git a/src/lib/subrip_decoder.cc b/src/lib/subrip_decoder.cc index deee82847..2ae285b5e 100644 --- a/src/lib/subrip_decoder.cc +++ b/src/lib/subrip_decoder.cc @@ -17,14 +17,16 @@ */ +#include #include "subrip_decoder.h" +#include "subrip_content.h" using std::list; +using std::vector; using boost::shared_ptr; -SubRipDecoder::SubRipDecoder (shared_ptr film, shared_ptr content) - : Decoder (film) - , SubtitleDecoder (film) +SubRipDecoder::SubRipDecoder (shared_ptr content) + : SubtitleDecoder (content) , SubRip (content) , _next (0) { @@ -32,23 +34,43 @@ SubRipDecoder::SubRipDecoder (shared_ptr film, shared_ptr::const_iterator i = _subtitles[_next].pieces.begin(); + while (i != _subtitles[_next].pieces.end() && _subtitles[_next].period.from < time) { + ++i; + } + +} + +bool SubRipDecoder::pass () { - list out; + if (_next >= _subtitles.size ()) { + return true; + } + + /* 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 ( - libdcp::Subtitle ( + dcp::SubtitleString ( "Arial", i->italic, - libdcp::Color (255, 255, 255), - 72, - _subtitles[_next].from, - _subtitles[_next].to, - 0.9, - libdcp::BOTTOM, + 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, - libdcp::NONE, - libdcp::Color (255, 255, 255), + dcp::NONE, + dcp::Color (255, 255, 255), 0, 0 ) @@ -56,11 +78,22 @@ SubRipDecoder::pass () } text_subtitle (out); - _next++; + ++_next; + return false; } -bool -SubRipDecoder::done () const +list +SubRipDecoder::subtitles_during (ContentTimePeriod p, bool starting) const { - return _next == _subtitles.size (); + /* 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); + } + } + + return d; }