#include "raw_convert.h"
#include "font_node.h"
#include "util.h"
+#include "font_asset.h"
+#include "dcp_assert.h"
#include <libxml++/libxml++.h>
#include <boost/foreach.hpp>
#include <cmath>
using std::list;
using std::string;
using std::cout;
+using std::cerr;
+using std::map;
using boost::shared_ptr;
+using boost::shared_array;
using boost::optional;
using boost::dynamic_pointer_cast;
using namespace dcp;
InteropSubtitleAsset::InteropSubtitleAsset ()
{
-
+
}
Glib::ustring
}
void
-InteropSubtitleAsset::add_font (string id, string uri)
+InteropSubtitleAsset::add_font (string load_id, boost::filesystem::path file)
{
- _load_font_nodes.push_back (shared_ptr<InteropLoadFontNode> (new InteropLoadFontNode (id, uri)));
+ _fonts.push_back (Font (load_id, make_uuid(), file));
+ _load_font_nodes.push_back (shared_ptr<InteropLoadFontNode> (new InteropLoadFontNode (load_id, file.leaf().string ())));
}
bool
if (!SubtitleAsset::equals (other_asset, options, note)) {
return false;
}
-
+
shared_ptr<const InteropSubtitleAsset> other = dynamic_pointer_cast<const InteropSubtitleAsset> (other_asset);
if (!other) {
return false;
return lf;
}
-/** Write this content to an XML file */
+/** Write this content to an XML file with its fonts alongside */
void
InteropSubtitleAsset::write (boost::filesystem::path p) const
{
if (!f) {
throw FileError ("Could not open file for writing", p, -1);
}
-
+
Glib::ustring const s = xml_as_string ();
fwrite (s.c_str(), 1, s.bytes(), f);
fclose (f);
_file = p;
+
+ BOOST_FOREACH (shared_ptr<InteropLoadFontNode> i, _load_font_nodes) {
+ boost::filesystem::path file = p.parent_path() / i->uri;
+ FILE* f = fopen_boost (file, "w");
+ if (!f) {
+ throw FileError ("could not open font file for writing", file, errno);
+ }
+ list<Font>::const_iterator j = _fonts.begin ();
+ while (j->load_id != i->id) {
+ ++j;
+ }
+ if (j != _fonts.end ()) {
+ fwrite (j->data.data.get(), 1, j->data.size, f);
+ j->file = file;
+ }
+ fclose (f);
+ }
+}
+
+void
+InteropSubtitleAsset::resolve_fonts (list<shared_ptr<Object> > objects)
+{
+ BOOST_FOREACH (shared_ptr<Object> i, objects) {
+ shared_ptr<FontAsset> font = dynamic_pointer_cast<FontAsset> (i);
+ if (!font) {
+ continue;
+ }
+
+ BOOST_FOREACH (shared_ptr<InteropLoadFontNode> j, _load_font_nodes) {
+ if (j->uri == font->file().leaf().string ()) {
+ _fonts.push_back (Font (j->id, i->id(), font->file ()));
+ }
+ }
+ }
+}
+
+void
+InteropSubtitleAsset::add_font_assets (list<shared_ptr<Asset> >& assets)
+{
+ BOOST_FOREACH (Font const & i, _fonts) {
+ DCP_ASSERT (i.file);
+ assets.push_back (shared_ptr<FontAsset> (new FontAsset (i.uuid, i.file.get ())));
+ }
}