Replace slightly weird add_font_assets() API.
[libdcp.git] / src / combine.cc
index c2cae54758645fcd0349beea201efe05e2bbc2d9..b728298ad2f3ba2c9f45cb587a6b2fc8f84b83bc 100644 (file)
 */
 
 
+/** @file  src/combine.cc
+ *  @brief Method to combine DCPs
+ */
+
+
 #include "asset.h"
 #include "combine.h"
 #include "cpl.h"
@@ -135,31 +140,22 @@ dcp::combine (
                                continue;
                        }
 
-                       optional<path> file = j->file();
-                       DCP_ASSERT (file);
-                       path new_path = make_unique(output / file->filename());
-
-                       shared_ptr<dcp::InteropSubtitleAsset> sub = dynamic_pointer_cast<dcp::InteropSubtitleAsset>(j);
+                       auto sub = dynamic_pointer_cast<dcp::InteropSubtitleAsset>(j);
                        if (sub) {
                                /* Interop fonts are really fiddly.  The font files are assets (in the ASSETMAP)
                                 * and also linked from the font XML by filename.  We have to fix both these things,
                                 * and re-write the font XML file since the font URI might have changed if it's a duplicate
                                 * with another DCP.
                                 */
-                               map<string, path> fonts = sub->font_filenames ();
-                               for (map<string, path>::const_iterator k = fonts.begin(); k != fonts.end(); ++k) {
-                                       sub->set_font_file (k->first, make_unique(output / k->second.filename()));
+                               auto fonts = sub->font_filenames ();
+                               for (auto const& k: fonts) {
+                                       sub->set_font_file (k.first, make_unique(output / k.second.filename()));
                                }
-                               sub->write (new_path);
-                       } else if (!dynamic_pointer_cast<dcp::FontAsset>(j)) {
-                               /* Take care of everything else that's not a Interop subtitle asset, Interop font file
-                                * or CPL.
-                                */
-                               optional<path> file = j->file();
+                               auto file = sub->file();
                                DCP_ASSERT (file);
                                path new_path = make_unique(output / file->filename());
-                               create_hard_link_or_copy (*file, new_path);
-                               j->set_file (new_path);
+                               sub->write (new_path);
+                               add_to_container(assets, sub->font_assets());
                        }
 
                        assets.push_back (j);
@@ -167,5 +163,21 @@ dcp::combine (
        }
 
        output_dcp.resolve_refs (assets);
-       output_dcp.write_xml (*standard, issuer, creator, issue_date, annotation_text, signer);
+
+       for (auto i: output_dcp.assets()) {
+               if (!dynamic_pointer_cast<dcp::FontAsset>(i) && !dynamic_pointer_cast<dcp::CPL>(i)) {
+                       auto file = i->file();
+                       DCP_ASSERT (file);
+                       path new_path = make_unique(output / file->filename());
+                       create_hard_link_or_copy (*file, new_path);
+                       i->set_file (new_path);
+               }
+       }
+
+       output_dcp.set_issuer(issuer);
+       output_dcp.set_creator(creator);
+       output_dcp.set_issue_date(issue_date);
+       output_dcp.set_annotation_text(annotation_text);
+
+       output_dcp.write_xml(signer);
 }