In-line run of subs_in_out so that it gets the environment more easily.
[libdcp.git] / src / interop_subtitle_asset.cc
index 0116c11c539a1a2d0390a6ac1003a6af9f8427b5..32c3f66a4268649985fb0c031313b54c5b9123cc 100644 (file)
@@ -39,6 +39,8 @@
 
 #include "compose.hpp"
 #include "dcp_assert.h"
+#include "equality_options.h"
+#include "filesystem.h"
 #include "font_asset.h"
 #include "file.h"
 #include "interop_load_font_node.h"
@@ -74,7 +76,7 @@ InteropSubtitleAsset::InteropSubtitleAsset (boost::filesystem::path file)
        _raw_xml = dcp::file_to_string (file);
 
        auto xml = make_shared<cxml::Document>("DCSubtitle");
-       xml->read_file (file);
+       xml->read_file(dcp::filesystem::fix_long_path(file));
        _id = xml->string_child ("SubtitleID");
        _reel_number = xml->string_child ("ReelNumber");
        _language = xml->string_child ("Language");
@@ -140,7 +142,7 @@ InteropSubtitleAsset::add_font (string load_id, dcp::ArrayData data)
 
 
 bool
-InteropSubtitleAsset::equals (shared_ptr<const Asset> other_asset, EqualityOptions options, NoteHandler note) const
+InteropSubtitleAsset::equals(shared_ptr<const Asset> other_asset, EqualityOptions const& options, NoteHandler note) const
 {
        if (!SubtitleAsset::equals (other_asset, options, note)) {
                return false;
@@ -230,8 +232,6 @@ InteropSubtitleAsset::write (boost::filesystem::path p) const
 void
 InteropSubtitleAsset::resolve_fonts (vector<shared_ptr<Asset>> assets)
 {
-       _fonts.clear();
-
        for (auto asset: assets) {
                auto font = dynamic_pointer_cast<FontAsset>(asset);
                if (!font) {
@@ -243,7 +243,12 @@ InteropSubtitleAsset::resolve_fonts (vector<shared_ptr<Asset>> assets)
                for (auto load_font_node: _load_font_nodes) {
                        auto const path_in_load_font_node = _file->parent_path() / load_font_node->uri;
                        if (font->file() && path_in_load_font_node == *font->file()) {
-                               _fonts.push_back(Font(load_font_node->id, asset->id(), font->file().get()));
+                               auto existing = std::find_if(_fonts.begin(), _fonts.end(), [load_font_node](Font const& font) { return font.load_id == load_font_node->id; });
+                               if (existing != _fonts.end()) {
+                                       *existing = Font(load_font_node->id, asset->id(), font->file().get());
+                               } else {
+                                       _fonts.push_back(Font(load_font_node->id, asset->id(), font->file().get()));
+                               }
                        }
                }
        }