X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Finterop_subtitle_asset.cc;h=d250b752e9d1f0aa10d00a1398237073d8ab853c;hb=46766164d06e0aa58ea5064bec9b313ff5cd2399;hp=a2742b78b2716663f0bb772b4a4d89c6acdb0f71;hpb=ff896d5f5ec20e1371b423bb746c32fa55cc126a;p=libdcp.git diff --git a/src/interop_subtitle_asset.cc b/src/interop_subtitle_asset.cc index a2742b78..d250b752 100644 --- a/src/interop_subtitle_asset.cc +++ b/src/interop_subtitle_asset.cc @@ -1,32 +1,49 @@ /* - Copyright (C) 2012-2015 Carl Hetherington + Copyright (C) 2012-2018 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" #include "interop_load_font_node.h" +#include "subtitle_asset_internal.h" #include "xml.h" #include "raw_convert.h" -#include "font_node.h" #include "util.h" #include "font_asset.h" #include "dcp_assert.h" +#include "compose.hpp" +#include "subtitle_image.h" #include #include +#include #include #include @@ -50,19 +67,25 @@ InteropSubtitleAsset::InteropSubtitleAsset (boost::filesystem::path file) _reel_number = xml->string_child ("ReelNumber"); _language = xml->string_child ("Language"); _movie_title = xml->string_child ("MovieTitle"); - _load_font_nodes = type_children (xml, "LoadFont"); + _load_font_nodes = type_children (xml, "LoadFont"); - list > font_nodes; - BOOST_FOREACH (cxml::NodePtr const & i, xml->node_children ("Font")) { - font_nodes.push_back (shared_ptr (new FontNode (i, 250, "Id"))); - } + /* Now we need to drop down to xmlpp */ - list > subtitle_nodes; - BOOST_FOREACH (cxml::NodePtr const & i, xml->node_children ("Subtitle")) { - subtitle_nodes.push_back (shared_ptr (new SubtitleNode (i, 250, "Id"))); + list ps; + xmlpp::Node::NodeList c = xml->node()->get_children (); + for (xmlpp::Node::NodeList::const_iterator i = c.begin(); i != c.end(); ++i) { + xmlpp::Element const * e = dynamic_cast (*i); + if (e && (e->get_name() == "Font" || e->get_name() == "Subtitle")) { + parse_subtitles (e, ps, optional(), INTEROP); + } } - parse_subtitles (xml, font_nodes, subtitle_nodes); + BOOST_FOREACH (shared_ptr i, _subtitles) { + shared_ptr si = dynamic_pointer_cast(i); + if (si) { + si->read_png_file (file.parent_path() / String::compose("%1.png", si->id())); + } + } } InteropSubtitleAsset::InteropSubtitleAsset () @@ -90,7 +113,7 @@ InteropSubtitleAsset::xml_as_string () const subtitles_as_xml (root, 250, INTEROP); - return doc.write_to_string_formatted ("UTF-8"); + return doc.write_to_string ("UTF-8"); } void @@ -162,6 +185,15 @@ InteropSubtitleAsset::write (boost::filesystem::path p) const _file = p; + /* Image subtitles */ + BOOST_FOREACH (shared_ptr i, _subtitles) { + shared_ptr im = dynamic_pointer_cast (i); + if (im) { + im->write_png_file(p.parent_path() / String::compose("%1.png", im->id())); + } + } + + /* Fonts */ BOOST_FOREACH (shared_ptr i, _load_font_nodes) { boost::filesystem::path file = p.parent_path() / i->uri; FILE* f = fopen_boost (file, "wb"); @@ -180,6 +212,10 @@ InteropSubtitleAsset::write (boost::filesystem::path p) const } } +/** Look at a supplied list of assets and find the fonts. Then match these + * fonts up with anything requested by a so that _fonts contains + * a list of font ID, load ID and data. + */ void InteropSubtitleAsset::resolve_fonts (list > assets) { @@ -190,8 +226,16 @@ InteropSubtitleAsset::resolve_fonts (list > assets) } BOOST_FOREACH (shared_ptr j, _load_font_nodes) { - if (j->uri == font->file().leaf().string ()) { - _fonts.push_back (Font (j->id, i->id(), font->file ())); + bool got = false; + BOOST_FOREACH (Font const & k, _fonts) { + if (k.load_id == j->id) { + got = true; + break; + } + } + + if (!got && font->file() && j->uri == font->file()->leaf().string()) { + _fonts.push_back (Font (j->id, i->id(), font->file().get())); } } } @@ -205,3 +249,31 @@ InteropSubtitleAsset::add_font_assets (list >& assets) assets.push_back (shared_ptr (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 i, _subtitles) { + shared_ptr im = dynamic_pointer_cast (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, boost::filesystem::path root) const +{ + Asset::add_to_pkl (pkl, root); + + BOOST_FOREACH (shared_ptr i, _subtitles) { + shared_ptr im = dynamic_pointer_cast (i); + if (im) { + Data png_image = im->png_image (); + pkl->add_asset (im->id(), optional(), make_digest(png_image), png_image.size(), "image/png"); + } + } +}