Switch subtitle string font specs to be the font ID; split SubtitleContent into Inter...
[libdcp.git] / src / subtitle_content.h
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef LIBDCP_SUBTITLE_CONTENT_H
21 #define LIBDCP_SUBTITLE_CONTENT_H
22
23 #include "content.h"
24 #include "dcp_time.h"
25 #include "subtitle_string.h"
26 #include <libcxml/cxml.h>
27
28 namespace dcp
29 {
30
31 class SubtitleString;   
32 class Font;
33 class Text;
34 class Subtitle;
35
36 /** @class SubtitleContent
37  *  @brief A parent for classes representing a file containing subtitles.
38  */
39 class SubtitleContent : public Content
40 {
41 public:
42         SubtitleContent () {}
43         SubtitleContent (boost::filesystem::path file);
44
45         bool equals (
46                 boost::shared_ptr<const Asset>,
47                 EqualityOptions,
48                 boost::function<void (NoteType, std::string)> note
49                 ) const {
50                 /* XXX */
51                 note (DCP_ERROR, "subtitle content not compared yet");
52                 return true;
53         }
54
55         std::string language () const {
56                 return _language;
57         }
58
59         std::list<SubtitleString> subtitles_at (Time t) const;
60         std::list<SubtitleString> const & subtitles () const {
61                 return _subtitles;
62         }
63
64         void add (SubtitleString);
65
66         void write_xml (boost::filesystem::path) const;
67         virtual Glib::ustring xml_as_string () const {
68                 /* XXX: this should be pure virtual when SMPTE writing is implemented */
69                 return "";
70         }
71
72         Time latest_subtitle_out () const;
73
74 protected:
75         void parse_common (boost::shared_ptr<cxml::Document> xml, std::list<boost::shared_ptr<dcp::Font> > font_nodes);
76         
77         std::string pkl_type (Standard) const {
78                 return "text/xml";
79         }
80
81         std::string asdcp_kind () const {
82                 return "Subtitle";
83         }
84         
85         /* strangely, this is sometimes a string */
86         std::string _reel_number;
87         std::string _language;
88
89         std::list<SubtitleString> _subtitles;
90
91 private:
92         struct ParseState {
93                 std::list<boost::shared_ptr<Font> > font_nodes;
94                 std::list<boost::shared_ptr<Text> > text_nodes;
95                 std::list<boost::shared_ptr<Subtitle> > subtitle_nodes;
96         };
97
98         void maybe_add_subtitle (std::string text, ParseState const & parse_state);
99         
100         void examine_font_nodes (
101                 boost::shared_ptr<const cxml::Node> xml,
102                 std::list<boost::shared_ptr<Font> > const & font_nodes,
103                 ParseState& parse_state
104                 );
105         
106         void examine_text_nodes (
107                 boost::shared_ptr<const cxml::Node> xml,
108                 std::list<boost::shared_ptr<Text> > const & text_nodes,
109                 ParseState& parse_state
110                 );
111 };
112
113 }
114
115 #endif