return (a.h == b.h && a.m == b.m && a.s == b.s && a.ms == b.ms);
}
+bool
+libdcp::operator<= (Time const & a, Time const & b)
+{
+ if (a.h != b.h) {
+ return a.h <= b.h;
+ }
+
+ if (a.m != b.m) {
+ return a.m <= b.m;
+ }
+
+ if (a.s != b.s) {
+ return a.s <= b.s;
+ }
+
+ if (a.ms != b.ms) {
+ return a.ms <= b.ms;
+ }
+
+ return true;
+}
+
ostream &
libdcp::operator<< (ostream& s, Time const & t)
{
};
extern bool operator== (Time const & a, Time const & b);
+extern bool operator<= (Time const & a, Time const & b);
extern std::ostream & operator<< (std::ostream & s, Time const & t);
}
#include "subtitle_asset.h"
+using namespace std;
+using namespace boost;
using namespace libdcp;
-SubtitleAsset::SubtitleAsset (std::string directory, std::string xml)
+SubtitleAsset::SubtitleAsset (string directory, string xml)
: Asset (directory, xml)
, XMLFile (path().string(), "DCSubtitle")
{
_text = content ();
_v_position = float_attribute ("VPosition");
}
+
+list<shared_ptr<Text> >
+SubtitleAsset::subtitles_at (Time t) const
+{
+ for (list<shared_ptr<Font> >::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) {
+ list<shared_ptr<Text> > s = (*i)->subtitles_at (t);
+ if (!s.empty ()) {
+ return s;
+ }
+ }
+
+ return list<shared_ptr<Text> > ();
+}
+
+list<shared_ptr<Text> >
+Font::subtitles_at (Time t) const
+{
+ for (list<shared_ptr<Subtitle> >::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
+ if ((*i)->in() <= t && t <= (*i)->out()) {
+ return (*i)->texts ();
+ }
+ }
+
+ return list<shared_ptr<Text> > ();
+}
return _subtitles;
}
+ std::list<boost::shared_ptr<Text> > subtitles_at (Time t) const;
+
private:
std::list<boost::shared_ptr<Subtitle> > _subtitles;
};
return _language;
}
+ std::list<boost::shared_ptr<Text> > subtitles_at (Time t) const;
+
std::list<boost::shared_ptr<Font> > const & fonts () const {
return _fonts;
}
BOOST_CHECK_EQUAL ((*i)->texts().size(), 1);
BOOST_CHECK_EQUAL ((*i)->texts().front()->v_position(), 15);
BOOST_CHECK_EQUAL ((*i)->texts().front()->text(), "And these are Roy Hattersley's jeans");
+
+ BOOST_CHECK_EQUAL (subs.subtitles_at (libdcp::Time (0, 0, 14, 042)).size(), 1);
+ BOOST_CHECK_EQUAL (subs.subtitles_at (libdcp::Time (0, 0, 14, 042)).front()->text(), "And these are Roy Hattersley's jeans");
}