X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Finterop_subtitle_asset.cc;h=d250b752e9d1f0aa10d00a1398237073d8ab853c;hb=868078a89decdbc9a9149684364a8ed11e28d309;hp=54c27ff5225223ff21ae2489561459864bfb4c16;hpb=adc78d62964377960c907cdb538a5bc3a224dafc;p=libdcp.git diff --git a/src/interop_subtitle_asset.cc b/src/interop_subtitle_asset.cc index 54c27ff5..d250b752 100644 --- a/src/interop_subtitle_asset.cc +++ b/src/interop_subtitle_asset.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2015 Carl Hetherington + Copyright (C) 2012-2018 Carl Hetherington This file is part of libdcp. @@ -33,13 +33,17 @@ #include "interop_subtitle_asset.h" #include "interop_load_font_node.h" +#include "subtitle_asset_internal.h" #include "xml.h" #include "raw_convert.h" #include "util.h" #include "font_asset.h" #include "dcp_assert.h" +#include "compose.hpp" +#include "subtitle_image.h" #include #include +#include #include #include @@ -63,7 +67,7 @@ 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"); /* Now we need to drop down to xmlpp */ @@ -75,6 +79,13 @@ InteropSubtitleAsset::InteropSubtitleAsset (boost::filesystem::path file) parse_subtitles (e, ps, optional(), INTEROP); } } + + 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 () @@ -174,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"); @@ -192,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) { @@ -209,7 +233,7 @@ InteropSubtitleAsset::resolve_fonts (list > assets) break; } } - + if (!got && font->file() && j->uri == font->file()->leaf().string()) { _fonts.push_back (Font (j->id, i->id(), font->file().get())); } @@ -225,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"); + } + } +}