X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Finterop_subtitle_asset.cc;h=b0b9499540d58f6a62ca4ace99ca7661d05759c7;hb=5d6770aea92d798a31fdbda128411ce2001a4209;hp=5be4c53c8e834b04ae085bdab3570cfe6e40c965;hpb=e4b8bed37b4fcfb932e2b899003f2a95df908ba0;p=libdcp.git diff --git a/src/interop_subtitle_asset.cc b/src/interop_subtitle_asset.cc index 5be4c53c..b0b94995 100644 --- a/src/interop_subtitle_asset.cc +++ b/src/interop_subtitle_asset.cc @@ -1,20 +1,34 @@ /* Copyright (C) 2012-2015 Carl Hetherington - This program is free software; you can redistribute it and/or modify + This file is part of libdcp. + + libdcp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + libdcp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - + along with libdcp. If not, see . + + In addition, as a special exception, the copyright holders give + permission to link the code of portions of this program with the + OpenSSL library under certain conditions as described in each + individual source file, and distribute linked combinations + including the two. + + You must obey the GNU General Public License in all respects + for all of the code used other than OpenSSL. If you modify + file(s) with this exception, you may extend this exception to your + version of the file(s), but you are not obligated to do so. If you + do not wish to do so, delete this exception statement from your + version. If you delete this exception statement from all source + files in the program, then also delete it here. */ #include "interop_subtitle_asset.h" @@ -23,7 +37,7 @@ #include "raw_convert.h" #include "font_node.h" #include "util.h" -#include "font.h" +#include "font_asset.h" #include "dcp_assert.h" #include #include @@ -52,21 +66,25 @@ InteropSubtitleAsset::InteropSubtitleAsset (boost::filesystem::path file) _movie_title = xml->string_child ("MovieTitle"); _load_font_nodes = type_children (xml, "LoadFont"); - list f = xml->node_children ("Font"); list > font_nodes; - BOOST_FOREACH (cxml::NodePtr& i, f) { - font_nodes.push_back (shared_ptr (new FontNode (i, 250))); + BOOST_FOREACH (cxml::NodePtr const & i, xml->node_children ("Font")) { + font_nodes.push_back (shared_ptr (new FontNode (i, optional(), INTEROP))); + } + + list > subtitle_nodes; + BOOST_FOREACH (cxml::NodePtr const & i, xml->node_children ("Subtitle")) { + subtitle_nodes.push_back (shared_ptr (new SubtitleNode (i, optional(), INTEROP))); } - parse_subtitles (xml, font_nodes); + parse_subtitles (xml, font_nodes, subtitle_nodes); } InteropSubtitleAsset::InteropSubtitleAsset () { - + } -Glib::ustring +string InteropSubtitleAsset::xml_as_string () const { xmlpp::Document doc; @@ -84,16 +102,16 @@ InteropSubtitleAsset::xml_as_string () const load_font->set_attribute ("URI", (*i)->uri); } - subtitles_as_xml (root, 250, ""); + subtitles_as_xml (root, 250, INTEROP); return doc.write_to_string_formatted ("UTF-8"); } void -InteropSubtitleAsset::add_font (string id, boost::filesystem::path file) +InteropSubtitleAsset::add_font (string load_id, boost::filesystem::path file) { - add_font_data (id, file); - _load_font_nodes.push_back (shared_ptr (new InteropLoadFontNode (id, file.leaf().string ()))); + _fonts.push_back (Font (load_id, make_uuid(), file)); + _load_font_nodes.push_back (shared_ptr (new InteropLoadFontNode (load_id, file.leaf().string ()))); } bool @@ -102,7 +120,7 @@ InteropSubtitleAsset::equals (shared_ptr other_asset, EqualityOptio if (!SubtitleAsset::equals (other_asset, options, note)) { return false; } - + shared_ptr other = dynamic_pointer_cast (other_asset); if (!other) { return false; @@ -150,40 +168,44 @@ 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); + + string const s = xml_as_string (); + /* length() here gives bytes not characters */ + fwrite (s.c_str(), 1, s.length(), f); fclose (f); _file = p; BOOST_FOREACH (shared_ptr i, _load_font_nodes) { boost::filesystem::path file = p.parent_path() / i->uri; - FILE* f = fopen_boost (file, "w"); + FILE* f = fopen_boost (file, "wb"); if (!f) { throw FileError ("could not open font file for writing", file, errno); } - map::const_iterator j = _fonts.find (i->id); + list::const_iterator j = _fonts.begin (); + while (j != _fonts.end() && j->load_id != i->id) { + ++j; + } if (j != _fonts.end ()) { - fwrite (j->second.data.get(), 1, j->second.size, f); - j->second.file = file; + fwrite (j->data.data().get(), 1, j->data.size(), f); + j->file = file; } fclose (f); } } void -InteropSubtitleAsset::resolve_fonts (list > objects) +InteropSubtitleAsset::resolve_fonts (list > assets) { - BOOST_FOREACH (shared_ptr i, objects) { - shared_ptr font = dynamic_pointer_cast (i); + BOOST_FOREACH (shared_ptr i, assets) { + shared_ptr font = dynamic_pointer_cast (i); if (!font) { continue; } BOOST_FOREACH (shared_ptr j, _load_font_nodes) { if (j->uri == font->file().leaf().string ()) { - add_font_data (j->id, font->file ()); + _fonts.push_back (Font (j->id, i->id(), font->file ())); } } } @@ -192,8 +214,8 @@ InteropSubtitleAsset::resolve_fonts (list > objects) void InteropSubtitleAsset::add_font_assets (list >& assets) { - for (map::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) { - DCP_ASSERT (i->second.file); - assets.push_back (shared_ptr (new Font (i->second.file.get ()))); + BOOST_FOREACH (Font const & i, _fonts) { + DCP_ASSERT (i.file); + assets.push_back (shared_ptr (new FontAsset (i.uuid, i.file.get ()))); } }