Bv2.1 7.2.3: Check that subtitle <StartTime> exists and is 0.
[libdcp.git] / src / interop_subtitle_asset.cc
index 6c9c6b42a3be235eb817a183a8f59452badbbe59..ac3dcc98e943e7aa077e99b0c7a6963117be9ebd 100644 (file)
@@ -52,10 +52,10 @@ using std::string;
 using std::cout;
 using std::cerr;
 using std::map;
-using boost::shared_ptr;
+using std::shared_ptr;
 using boost::shared_array;
 using boost::optional;
-using boost::dynamic_pointer_cast;
+using std::dynamic_pointer_cast;
 using namespace dcp;
 
 InteropSubtitleAsset::InteropSubtitleAsset (boost::filesystem::path file)
@@ -119,10 +119,11 @@ InteropSubtitleAsset::xml_as_string () const
 }
 
 void
-InteropSubtitleAsset::add_font (string load_id, boost::filesystem::path file)
+InteropSubtitleAsset::add_font (string load_id, dcp::ArrayData data)
 {
-       _fonts.push_back (Font (load_id, make_uuid(), file));
-       _load_font_nodes.push_back (shared_ptr<InteropLoadFontNode> (new InteropLoadFontNode (load_id, file.leaf().string ())));
+       _fonts.push_back (Font(load_id, make_uuid(), data));
+       string const uri = String::compose("font_%1.ttf", _load_font_nodes.size());
+       _load_font_nodes.push_back (shared_ptr<InteropLoadFontNode>(new InteropLoadFontNode(load_id, uri)));
 }
 
 bool
@@ -137,22 +138,24 @@ InteropSubtitleAsset::equals (shared_ptr<const Asset> other_asset, EqualityOptio
                return false;
        }
 
-       list<shared_ptr<InteropLoadFontNode> >::const_iterator i = _load_font_nodes.begin ();
-       list<shared_ptr<InteropLoadFontNode> >::const_iterator j = other->_load_font_nodes.begin ();
+       if (!options.load_font_nodes_can_differ) {
+               list<shared_ptr<InteropLoadFontNode> >::const_iterator i = _load_font_nodes.begin ();
+               list<shared_ptr<InteropLoadFontNode> >::const_iterator j = other->_load_font_nodes.begin ();
 
-       while (i != _load_font_nodes.end ()) {
-               if (j == other->_load_font_nodes.end ()) {
-                       note (DCP_ERROR, "<LoadFont> nodes differ");
-                       return false;
-               }
+               while (i != _load_font_nodes.end ()) {
+                       if (j == other->_load_font_nodes.end ()) {
+                               note (DCP_ERROR, "<LoadFont> nodes differ");
+                               return false;
+                       }
 
-               if (**i != **j) {
-                       note (DCP_ERROR, "<LoadFont> nodes differ");
-                       return false;
-               }
+                       if (**i != **j) {
+                               note (DCP_ERROR, "<LoadFont> nodes differ");
+                               return false;
+                       }
 
-               ++i;
-               ++j;
+                       ++i;
+                       ++j;
+               }
        }
 
        if (_movie_title != other->_movie_title) {
@@ -269,8 +272,26 @@ InteropSubtitleAsset::add_to_pkl (shared_ptr<PKL> pkl, boost::filesystem::path r
        BOOST_FOREACH (shared_ptr<dcp::Subtitle> i, _subtitles) {
                shared_ptr<dcp::SubtitleImage> im = dynamic_pointer_cast<dcp::SubtitleImage> (i);
                if (im) {
-                       Data png_image = im->png_image ();
+                       ArrayData png_image = im->png_image ();
                        pkl->add_asset (im->id(), optional<string>(), make_digest(png_image), png_image.size(), "image/png");
                }
        }
 }
+
+
+void
+InteropSubtitleAsset::set_font_file (string load_id, boost::filesystem::path file)
+{
+       BOOST_FOREACH (Font& i, _fonts) {
+               if (i.load_id == load_id) {
+                       i.file = file;
+               }
+       }
+
+       BOOST_FOREACH (shared_ptr<InteropLoadFontNode> i, _load_font_nodes) {
+               if (i->id == load_id) {
+                       i->uri = file.filename().string();
+               }
+       }
+}
+