Some maths operations with Time.
[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 "asset.h"
21 #include "xml.h"
22 #include "dcp_time.h"
23
24 namespace libdcp
25 {
26
27 class TextNode : public XMLNode
28 {
29 public:
30         TextNode () {}
31         TextNode (xmlpp::Node const * node);
32
33         float v_position;
34         VAlign v_align;
35         std::string text;
36         Time fade_up_time;
37         Time fade_down_time;
38
39 private:
40         Time fade_time (std::string name);
41         
42 };
43
44 class SubtitleNode : public XMLNode
45 {
46 public:
47         SubtitleNode () {}
48         SubtitleNode (xmlpp::Node const * node);
49
50         Time in;
51         Time out;
52         std::list<boost::shared_ptr<TextNode> > text_nodes;
53 };
54
55 class FontNode : public XMLNode
56 {
57 public:
58         FontNode () {}
59         FontNode (xmlpp::Node const * node);
60         FontNode (std::list<boost::shared_ptr<FontNode> > const & font_nodes);
61
62         std::string id;
63         int size;
64         boost::optional<bool> italic;
65         boost::optional<Color> color;
66         boost::optional<Effect> effect;
67         boost::optional<Color> effect_color;
68         
69         std::list<boost::shared_ptr<SubtitleNode> > subtitle_nodes;
70         std::list<boost::shared_ptr<FontNode> > font_nodes;
71 };
72
73 class LoadFontNode : public XMLNode
74 {
75 public:
76         LoadFontNode () {}
77         LoadFontNode (xmlpp::Node const * node);
78
79         std::string id;
80         std::string uri;
81 };
82
83 class Subtitle
84 {
85 public:
86         Subtitle (
87                 std::string font,
88                 bool italic,
89                 Color color,
90                 int size,
91                 Time in,
92                 Time out,
93                 float v_position,
94                 VAlign v_align,
95                 std::string text,
96                 Effect effect,
97                 Color effect_color,
98                 Time fade_up_time,
99                 Time fade_down_time
100                 );
101
102         std::string font () const {
103                 return _font;
104         }
105
106         bool italic () const {
107                 return _italic;
108         }
109
110         Color color () const {
111                 return _color;
112         }
113
114         Time in () const {
115                 return _in;
116         }
117
118         Time out () const {
119                 return _out;
120         }
121
122         std::string text () const {
123                 return _text;
124         }
125
126         float v_position () const {
127                 return _v_position;
128         }
129
130         VAlign v_align () const {
131                 return _v_align;
132         }
133
134         Effect effect () const {
135                 return _effect;
136         }
137
138         Color effect_color () const {
139                 return _effect_color;
140         }
141
142         Time fade_up_time () const {
143                 return _fade_up_time;
144         }
145
146         Time fade_down_time () const {
147                 return _fade_down_time;
148         }
149
150         int size_in_pixels (int screen_height) const;
151
152 private:
153         std::string _font;
154         bool _italic;
155         Color _color;
156         int _size;
157         Time _in;
158         Time _out;
159         float _v_position;
160         VAlign _v_align;
161         std::string _text;
162         Effect _effect;
163         Color _effect_color;
164         Time _fade_up_time;
165         Time _fade_down_time;
166 };
167
168 class SubtitleAsset : public Asset, public XMLFile
169 {
170 public:
171         SubtitleAsset (std::string directory, std::string xml);
172
173         void write_to_cpl (std::ostream&) const {}
174         virtual std::list<std::string> equals (boost::shared_ptr<const Asset>, EqualityOptions) const {
175                 /* XXX */
176                 return std::list<std::string> ();
177         }
178
179         std::string language () const {
180                 return _language;
181         }
182
183         std::list<boost::shared_ptr<Subtitle> > subtitles_at (Time t) const;
184
185 private:
186         std::string font_id_to_name (std::string id) const;
187         void examine_font_node (boost::shared_ptr<FontNode> font_node, std::list<boost::shared_ptr<FontNode> >& current_font_nodes);
188         
189         std::string _subtitle_id;
190         std::string _movie_title;
191         int64_t _reel_number;
192         std::string _language;
193         std::list<boost::shared_ptr<LoadFontNode> > _load_font_nodes;
194
195         std::list<boost::shared_ptr<Subtitle> > _subtitles;
196 };
197
198 }