#include "util.h"
#include "font_asset.h"
#include "dcp_assert.h"
+#include "compose.hpp"
#include "subtitle_image.h"
#include <libxml++/libxml++.h>
#include <boost/foreach.hpp>
+#include <boost/weak_ptr.hpp>
#include <cmath>
#include <cstdio>
InteropSubtitleAsset::InteropSubtitleAsset (boost::filesystem::path file)
: SubtitleAsset (file)
{
+ _raw_xml = dcp::file_to_string (file);
+
shared_ptr<cxml::Document> xml (new cxml::Document ("DCSubtitle"));
xml->read_file (file);
_id = xml->string_child ("SubtitleID");
parse_subtitles (e, ps, optional<int>(), INTEROP);
}
}
+
+ BOOST_FOREACH (shared_ptr<Subtitle> i, _subtitles) {
+ shared_ptr<SubtitleImage> si = dynamic_pointer_cast<SubtitleImage>(i);
+ if (si) {
+ si->read_png_file (file.parent_path() / String::compose("%1.png", si->id()));
+ }
+ }
}
InteropSubtitleAsset::InteropSubtitleAsset ()
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) {
_file = p;
/* Image subtitles */
- int n = 0;
BOOST_FOREACH (shared_ptr<dcp::Subtitle> i, _subtitles) {
shared_ptr<dcp::SubtitleImage> im = dynamic_pointer_cast<dcp::SubtitleImage> (i);
if (im) {
- im->png_image().write (p.parent_path() / image_subtitle_file (n++));
+ im->write_png_file(p.parent_path() / String::compose("%1.png", im->id()));
}
}
/* Fonts */
BOOST_FOREACH (shared_ptr<InteropLoadFontNode> i, _load_font_nodes) {
boost::filesystem::path file = p.parent_path() / i->uri;
- FILE* f = fopen_boost (file, "wb");
- if (!f) {
- throw FileError ("could not open font file for writing", file, errno);
- }
list<Font>::const_iterator j = _fonts.begin ();
while (j != _fonts.end() && j->load_id != i->id) {
++j;
}
if (j != _fonts.end ()) {
- fwrite (j->data.data().get(), 1, j->data.size(), f);
+ j->data.write (file);
j->file = file;
}
- fclose (f);
}
}
assets.push_back (shared_ptr<FontAsset> (new FontAsset (i.uuid, i.file.get ())));
}
}
+
+void
+InteropSubtitleAsset::write_to_assetmap (xmlpp::Node* node, boost::filesystem::path root) const
+{
+ Asset::write_to_assetmap (node, root);
+
+ BOOST_FOREACH (shared_ptr<dcp::Subtitle> i, _subtitles) {
+ shared_ptr<dcp::SubtitleImage> im = dynamic_pointer_cast<dcp::SubtitleImage> (i);
+ if (im) {
+ DCP_ASSERT (im->file());
+ write_file_to_assetmap (node, root, im->file().get(), im->id());
+ }
+ }
+}
+
+void
+InteropSubtitleAsset::add_to_pkl (shared_ptr<PKL> pkl, boost::filesystem::path root) const
+{
+ Asset::add_to_pkl (pkl, root);
+
+ 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 ();
+ 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();
+ }
+ }
+}
+