#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"
_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");
auto root = doc.create_root_node ("DCSubtitle");
root->set_attribute ("Version", "1.0");
- root->add_child("SubtitleID")->add_child_text (_id);
- root->add_child("MovieTitle")->add_child_text (_movie_title);
- root->add_child("ReelNumber")->add_child_text (raw_convert<string> (_reel_number));
- root->add_child("Language")->add_child_text (_language);
+ cxml::add_text_child(root, "SubtitleID", _id);
+ cxml::add_text_child(root, "MovieTitle", _movie_title);
+ cxml::add_text_child(root, "ReelNumber", raw_convert<string> (_reel_number));
+ cxml::add_text_child(root, "Language", _language);
for (auto i: _load_font_nodes) {
- auto load_font = root->add_child("LoadFont");
+ auto load_font = cxml::add_child(root, "LoadFont");
load_font->set_attribute ("Id", i->id);
load_font->set_attribute ("URI", i->uri);
}
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;
/* Fonts */
for (auto i: _load_font_nodes) {
auto file = p.parent_path() / i->uri;
- auto j = _fonts.begin();
- while (j != _fonts.end() && j->load_id != i->id) {
- ++j;
- }
- if (j != _fonts.end ()) {
- j->data.write (file);
- j->file = file;
+ auto font_with_id = std::find_if(_fonts.begin(), _fonts.end(), [i](Font const& font) { return font.load_id == i->id; });
+ if (font_with_id != _fonts.end()) {
+ font_with_id->data.write(file);
+ font_with_id->file = file;
}
}
}
void
InteropSubtitleAsset::resolve_fonts (vector<shared_ptr<Asset>> assets)
{
- _fonts.clear();
-
for (auto asset: assets) {
auto font = dynamic_pointer_cast<FontAsset>(asset);
if (!font) {
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()));
+ }
}
}
}