Some comments.
[libdcp.git] / src / subtitle_asset.cc
index 19697a7f8864b8221a623095c80053d4b8c45ea7..220982138aed30906031f0ede3309673f8bb036d 100644 (file)
 
 #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")
 {
@@ -44,11 +46,39 @@ Font::Font (xmlpp::Node const * node)
 Subtitle::Subtitle (xmlpp::Node const * node)
        : XMLNode (node)
 {
+       _in = time_attribute ("TimeIn");
+       _out = time_attribute ("TimeOut");
        _texts = sub_nodes<Text> ("Text");
 }
 
 Text::Text (xmlpp::Node const * node)
        : XMLNode (node)
 {
+       _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> > ();
 }