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/>.
20 #ifndef LIBDCP_SUBTITLE_ASSET_H
21 #define LIBDCP_SUBTITLE_ASSET_H
25 #include "subtitle_string.h"
27 #include <libcxml/cxml.h>
28 #include <boost/shared_array.hpp>
35 struct interop_dcp_font_test;
36 struct smpte_dcp_font_test;
47 /** @class SubtitleAsset
48 * @brief A parent for classes representing a file containing subtitles.
50 * This class holds a list of SubtitleString objects which it can extract
51 * from the appropriate part of either an Interop or SMPTE XML file.
52 * Its subclasses InteropSubtitleAsset and SMPTESubtitleAsset handle the
53 * differences between the two types.
55 class SubtitleAsset : public Asset
59 SubtitleAsset (boost::filesystem::path file);
62 boost::shared_ptr<const Asset>,
67 std::list<SubtitleString> subtitles_during (Time from, Time to, bool starting) const;
68 std::list<SubtitleString> const & subtitles () const {
72 virtual void add (SubtitleString);
73 virtual void add_font (std::string id, boost::filesystem::path file) = 0;
74 std::map<std::string, Data> fonts_with_load_ids () const;
76 virtual void write (boost::filesystem::path) const = 0;
77 virtual std::string xml_as_string () const = 0;
79 Time latest_subtitle_out () const;
81 virtual std::list<boost::shared_ptr<LoadFontNode> > load_font_nodes () const = 0;
84 friend struct ::interop_dcp_font_test;
85 friend struct ::smpte_dcp_font_test;
87 void parse_subtitles (
88 boost::shared_ptr<cxml::Document> xml,
89 std::list<boost::shared_ptr<FontNode> > font_nodes,
90 std::list<boost::shared_ptr<SubtitleNode> > subtitle_nodes
93 void subtitles_as_xml (xmlpp::Element* root, int time_code_rate, Standard standard) const;
95 /** All our subtitles, in no particular order */
96 std::list<SubtitleString> _subtitles;
101 Font (std::string load_id_, std::string uuid_, boost::filesystem::path file_)
108 Font (std::string load_id_, std::string uuid_, Data data_)
117 /** .ttf file that this data was last written to, if applicable */
118 mutable boost::optional<boost::filesystem::path> file;
121 std::list<Font> _fonts;
124 /** @struct ParseState
125 * @brief A struct to hold state when parsing a subtitle XML file.
128 std::list<boost::shared_ptr<FontNode> > font_nodes;
129 std::list<boost::shared_ptr<TextNode> > text_nodes;
130 std::list<boost::shared_ptr<SubtitleNode> > subtitle_nodes;
133 void maybe_add_subtitle (std::string text, ParseState const & parse_state);
136 boost::shared_ptr<const cxml::Node> xml,
137 std::list<boost::shared_ptr<FontNode> > const & font_nodes,
138 ParseState& parse_state
142 boost::shared_ptr<const cxml::Node> xml,
143 std::list<boost::shared_ptr<TextNode> > const & text_nodes,
144 ParseState& parse_state
148 boost::shared_ptr<const cxml::Node> xml,
149 std::list<boost::shared_ptr<SubtitleNode> > const & subtitle_nodes,
150 ParseState& parse_state