1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/*
Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
This program 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,
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.
*/
#ifndef LIBDCP_SUBTITLE_ASSET_H
#define LIBDCP_SUBTITLE_ASSET_H
#include "asset.h"
#include "dcp_time.h"
#include "subtitle_string.h"
#include "data.h"
#include <libcxml/cxml.h>
#include <boost/shared_array.hpp>
namespace xmlpp {
class Element;
}
struct interop_dcp_font_test;
struct smpte_dcp_font_test;
namespace dcp
{
class SubtitleString;
class FontNode;
class TextNode;
class SubtitleNode;
class LoadFontNode;
/** @class SubtitleAsset
* @brief A parent for classes representing a file containing subtitles.
*
* This class holds a list of SubtitleString objects which it can extract
* from the appropriate part of either an Interop or SMPTE XML file.
* Its subclasses InteropSubtitleAsset and SMPTESubtitleAsset handle the
* differences between the two types.
*/
class SubtitleAsset : public Asset
{
public:
SubtitleAsset ();
SubtitleAsset (boost::filesystem::path file);
bool equals (
boost::shared_ptr<const Asset>,
EqualityOptions,
NoteHandler note
) const;
std::list<SubtitleString> subtitles_during (Time from, Time to) const;
std::list<SubtitleString> const & subtitles () const {
return _subtitles;
}
void add (SubtitleString);
virtual void add_font (std::string id, boost::filesystem::path file) = 0;
virtual void write (boost::filesystem::path) const = 0;
virtual Glib::ustring xml_as_string () const = 0;
Time latest_subtitle_out () const;
virtual std::list<boost::shared_ptr<LoadFontNode> > load_font_nodes () const = 0;
protected:
friend struct ::interop_dcp_font_test;
friend struct ::smpte_dcp_font_test;
void parse_subtitles (boost::shared_ptr<cxml::Document> xml, std::list<boost::shared_ptr<FontNode> > font_nodes);
void subtitles_as_xml (xmlpp::Element* root, int time_code_rate, std::string xmlns) const;
/** All our subtitles, in no particular order */
std::list<SubtitleString> _subtitles;
private:
/** @struct ParseState
* @brief A struct to hold state when parsing a subtitle XML file.
*/
struct ParseState {
std::list<boost::shared_ptr<FontNode> > font_nodes;
std::list<boost::shared_ptr<TextNode> > text_nodes;
std::list<boost::shared_ptr<SubtitleNode> > subtitle_nodes;
};
void maybe_add_subtitle (std::string text, ParseState const & parse_state);
void examine_font_nodes (
boost::shared_ptr<const cxml::Node> xml,
std::list<boost::shared_ptr<FontNode> > const & font_nodes,
ParseState& parse_state
);
void examine_text_nodes (
boost::shared_ptr<const cxml::Node> xml,
std::list<boost::shared_ptr<TextNode> > const & text_nodes,
ParseState& parse_state
);
};
}
#endif
|