2 Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef LIBDCP_SUBTITLE_ASSET_H
21 #define LIBDCP_SUBTITLE_ASSET_H
25 #include "subtitle_string.h"
26 #include <libcxml/cxml.h>
27 #include <boost/shared_array.hpp>
33 struct interop_dcp_font_test;
44 /** @class SubtitleAsset
45 * @brief A parent for classes representing a file containing subtitles.
47 * This class holds a list of SubtitleString objects which it can extract
48 * from the appropriate part of either an Interop or SMPTE XML file.
49 * Its subclasses InteropSubtitleAsset and SMPTESubtitleAsset handle the
50 * differences between the two types.
52 class SubtitleAsset : public Asset
56 SubtitleAsset (boost::filesystem::path file);
59 boost::shared_ptr<const Asset>,
64 std::list<SubtitleString> subtitles_during (Time from, Time to) const;
65 std::list<SubtitleString> const & subtitles () const {
69 void add (SubtitleString);
70 virtual void add_font (std::string id, boost::filesystem::path file) = 0;
72 virtual void write (boost::filesystem::path) const = 0;
73 virtual Glib::ustring xml_as_string () const = 0;
75 Time latest_subtitle_out () const;
77 virtual std::list<boost::shared_ptr<LoadFontNode> > load_font_nodes () const = 0;
80 friend struct ::interop_dcp_font_test;
82 void parse_subtitles (boost::shared_ptr<cxml::Document> xml, std::list<boost::shared_ptr<FontNode> > font_nodes);
83 void subtitles_as_xml (xmlpp::Element* root, int time_code_rate, std::string xmlns) const;
84 void add_font_data (std::string id, boost::filesystem::path file);
86 /** All our subtitles, in no particular order */
87 std::list<SubtitleString> _subtitles;
93 FontData (boost::shared_array<uint8_t> data_, boost::uintmax_t size_)
98 FontData (boost::shared_array<uint8_t> data_, boost::uintmax_t size_, boost::filesystem::path file_)
104 boost::shared_array<uint8_t> data;
105 boost::uintmax_t size;
106 mutable boost::filesystem::path file;
109 /** Font data, keyed by a subclass-dependent identifier.
110 * For Interop fonts, the string is the font ID from the subtitle file.
112 std::map<std::string, FontData> _fonts;
115 /** @struct ParseState
116 * @brief A struct to hold state when parsing a subtitle XML file.
119 std::list<boost::shared_ptr<FontNode> > font_nodes;
120 std::list<boost::shared_ptr<TextNode> > text_nodes;
121 std::list<boost::shared_ptr<SubtitleNode> > subtitle_nodes;
124 void maybe_add_subtitle (std::string text, ParseState const & parse_state);
126 void examine_font_nodes (
127 boost::shared_ptr<const cxml::Node> xml,
128 std::list<boost::shared_ptr<FontNode> > const & font_nodes,
129 ParseState& parse_state
132 void examine_text_nodes (
133 boost::shared_ptr<const cxml::Node> xml,
134 std::list<boost::shared_ptr<TextNode> > const & text_nodes,
135 ParseState& parse_state