2 Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libdcp is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libdcp. If not, see <http://www.gnu.org/licenses/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
34 #ifndef LIBDCP_SUBTITLE_ASSET_H
35 #define LIBDCP_SUBTITLE_ASSET_H
39 #include "subtitle_string.h"
41 #include <libcxml/cxml.h>
42 #include <boost/shared_array.hpp>
49 struct interop_dcp_font_test;
50 struct smpte_dcp_font_test;
61 /** @class SubtitleAsset
62 * @brief A parent for classes representing a file containing subtitles.
64 * This class holds a list of SubtitleString objects which it can extract
65 * from the appropriate part of either an Interop or SMPTE XML file.
66 * Its subclasses InteropSubtitleAsset and SMPTESubtitleAsset handle the
67 * differences between the two types.
69 class SubtitleAsset : public Asset
73 explicit SubtitleAsset (boost::filesystem::path file);
76 boost::shared_ptr<const Asset>,
81 std::list<SubtitleString> subtitles_during (Time from, Time to, bool starting) const;
82 std::list<SubtitleString> const & subtitles () const {
86 virtual void add (SubtitleString);
87 virtual void add_font (std::string id, boost::filesystem::path file) = 0;
88 std::map<std::string, Data> fonts_with_load_ids () const;
90 virtual void write (boost::filesystem::path) const = 0;
91 virtual std::string xml_as_string () const = 0;
93 Time latest_subtitle_out () const;
95 virtual std::list<boost::shared_ptr<LoadFontNode> > load_font_nodes () const = 0;
98 friend struct ::interop_dcp_font_test;
99 friend struct ::smpte_dcp_font_test;
101 void parse_subtitles (
102 boost::shared_ptr<cxml::Document> xml,
103 std::list<boost::shared_ptr<FontNode> > font_nodes,
104 std::list<boost::shared_ptr<SubtitleNode> > subtitle_nodes
107 void subtitles_as_xml (xmlpp::Element* root, int time_code_rate, Standard standard) const;
109 /** All our subtitles, in no particular order */
110 std::list<SubtitleString> _subtitles;
115 Font (std::string load_id_, std::string uuid_, boost::filesystem::path file_)
122 Font (std::string load_id_, std::string uuid_, Data data_)
131 /** .ttf file that this data was last written to, if applicable */
132 mutable boost::optional<boost::filesystem::path> file;
135 std::list<Font> _fonts;
138 /** @struct ParseState
139 * @brief A struct to hold state when parsing a subtitle XML file.
142 std::list<boost::shared_ptr<FontNode> > font_nodes;
143 std::list<boost::shared_ptr<TextNode> > text_nodes;
144 std::list<boost::shared_ptr<SubtitleNode> > subtitle_nodes;
147 void maybe_add_subtitle (std::string text, ParseState const & parse_state);
150 boost::shared_ptr<const cxml::Node> xml,
151 std::list<boost::shared_ptr<FontNode> > const & font_nodes,
152 ParseState& parse_state
156 boost::shared_ptr<const cxml::Node> xml,
157 std::list<boost::shared_ptr<TextNode> > const & text_nodes,
158 ParseState& parse_state
162 boost::shared_ptr<const cxml::Node> xml,
163 std::list<boost::shared_ptr<SubtitleNode> > const & subtitle_nodes,
164 ParseState& parse_state