Try to add correct namespace for 3D CPLs.
[libdcp.git] / src / subtitle_asset.h
1 /*
2     Copyright (C) 2012 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 #include <libcxml/cxml.h>
21 #include "asset.h"
22 #include "dcp_time.h"
23
24 namespace libdcp
25 {
26
27 namespace parse
28 {
29         class Font;
30         class Text;
31         class Subtitle;
32         class LoadFont;
33 }
34
35 class Subtitle
36 {
37 public:
38         Subtitle (
39                 std::string font,
40                 bool italic,
41                 Color color,
42                 int size,
43                 Time in,
44                 Time out,
45                 float v_position,
46                 VAlign v_align,
47                 std::string text,
48                 Effect effect,
49                 Color effect_color,
50                 Time fade_up_time,
51                 Time fade_down_time
52                 );
53
54         std::string font () const {
55                 return _font;
56         }
57
58         bool italic () const {
59                 return _italic;
60         }
61
62         Color color () const {
63                 return _color;
64         }
65
66         Time in () const {
67                 return _in;
68         }
69
70         Time out () const {
71                 return _out;
72         }
73
74         std::string text () const {
75                 return _text;
76         }
77
78         float v_position () const {
79                 return _v_position;
80         }
81
82         VAlign v_align () const {
83                 return _v_align;
84         }
85
86         Effect effect () const {
87                 return _effect;
88         }
89
90         Color effect_color () const {
91                 return _effect_color;
92         }
93
94         Time fade_up_time () const {
95                 return _fade_up_time;
96         }
97
98         Time fade_down_time () const {
99                 return _fade_down_time;
100         }
101
102         int size () const {
103                 return _size;
104         }
105         
106         int size_in_pixels (int screen_height) const;
107
108 private:
109         std::string _font;
110         bool _italic;
111         Color _color;
112         int _size;
113         Time _in;
114         Time _out;
115         float _v_position;
116         VAlign _v_align;
117         std::string _text;
118         Effect _effect;
119         Color _effect_color;
120         Time _fade_up_time;
121         Time _fade_down_time;
122 };
123
124 bool operator== (Subtitle const & a, Subtitle const & b);
125 std::ostream& operator<< (std::ostream& s, Subtitle const & sub);
126
127 class SubtitleAsset : public Asset
128 {
129 public:
130         SubtitleAsset (std::string directory, std::string xml_file);
131         SubtitleAsset (std::string directory, std::string movie_title, std::string language);
132
133         void write_to_cpl (xmlpp::Node *, bool) const;
134         virtual bool equals (boost::shared_ptr<const Asset>, EqualityOptions, boost::function<void (NoteType, std::string)> note) const {
135                 /* XXX */
136                 note (ERROR, "subtitle assets not compared yet");
137                 return true;
138         }
139
140         std::string language () const {
141                 return _language;
142         }
143
144         std::list<boost::shared_ptr<Subtitle> > subtitles_at (Time t) const;
145         std::list<boost::shared_ptr<Subtitle> > const & subtitles () const {
146                 return _subtitles;
147         }
148
149         void add (boost::shared_ptr<Subtitle>);
150
151         void read_xml (std::string);
152         void write_xml () const;
153         void write_xml (std::ostream &) const;
154
155 private:
156         std::string font_id_to_name (std::string id) const;
157
158         struct ParseState {
159                 std::list<boost::shared_ptr<parse::Font> > font_nodes;
160                 std::list<boost::shared_ptr<parse::Text> > text_nodes;
161                 std::list<boost::shared_ptr<parse::Subtitle> > subtitle_nodes;
162         };
163
164         void maybe_add_subtitle (std::string text, ParseState const & parse_state);
165         
166         void examine_font_nodes (
167                 boost::shared_ptr<const cxml::Node> xml,
168                 std::list<boost::shared_ptr<parse::Font> > const & font_nodes,
169                 ParseState& parse_state
170                 );
171         
172         void examine_text_nodes (
173                 boost::shared_ptr<const cxml::Node> xml,
174                 std::list<boost::shared_ptr<parse::Text> > const & text_nodes,
175                 ParseState& parse_state
176                 );
177
178         std::string _movie_title;
179         /* strangely, this is sometimes a string */
180         std::string _reel_number;
181         std::string _language;
182         std::list<boost::shared_ptr<parse::LoadFont> > _load_font_nodes;
183
184         std::list<boost::shared_ptr<Subtitle> > _subtitles;
185         bool _need_sort;
186 };
187
188 }