Pick up subtitle color.
[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         std::string text;
35 };
36
37 class SubtitleNode : public XMLNode
38 {
39 public:
40         SubtitleNode () {}
41         SubtitleNode (xmlpp::Node const * node);
42
43         Time in;
44         Time out;
45         std::list<boost::shared_ptr<TextNode> > text_nodes;
46 };
47
48 class FontNode : public XMLNode
49 {
50 public:
51         FontNode () {}
52         FontNode (xmlpp::Node const * node);
53         FontNode (std::list<boost::shared_ptr<FontNode> > const & font_nodes);
54
55         std::string id;
56         int size;
57         boost::optional<bool> italic;
58         boost::optional<Color> color;
59         
60         std::list<boost::shared_ptr<SubtitleNode> > subtitle_nodes;
61         std::list<boost::shared_ptr<FontNode> > font_nodes;
62 };
63
64 class LoadFontNode : public XMLNode
65 {
66 public:
67         LoadFontNode () {}
68         LoadFontNode (xmlpp::Node const * node);
69
70         std::string id;
71         std::string uri;
72 };
73
74 class Subtitle
75 {
76 public:
77         Subtitle (
78                 std::string font,
79                 bool italic,
80                 Color color,
81                 int size,
82                 Time in,
83                 Time out,
84                 float v_position,
85                 std::string text
86                 );
87
88         std::string font () const {
89                 return _font;
90         }
91
92         bool italic () const {
93                 return _italic;
94         }
95
96         Color color () const {
97                 return _color;
98         }
99
100         Time in () const {
101                 return _in;
102         }
103
104         Time out () const {
105                 return _out;
106         }
107
108         std::string text () const {
109                 return _text;
110         }
111
112         float v_position () const {
113                 return _v_position;
114         }
115
116         int size_in_pixels (int screen_height) const;
117
118 private:
119         std::string _font;
120         bool _italic;
121         Color _color;
122         int _size;
123         Time _in;
124         Time _out;
125         float _v_position;
126         std::string _text;
127 };
128
129 class SubtitleAsset : public Asset, public XMLFile
130 {
131 public:
132         SubtitleAsset (std::string directory, std::string xml);
133
134         void write_to_cpl (std::ostream&) const {}
135         virtual std::list<std::string> equals (boost::shared_ptr<const Asset>, EqualityOptions) const {
136                 /* XXX */
137                 return std::list<std::string> ();
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
146 private:
147         std::string font_id_to_name (std::string id) const;
148         void examine_font_node (boost::shared_ptr<FontNode> font_node, std::list<boost::shared_ptr<FontNode> >& current_font_nodes);
149         
150         std::string _subtitle_id;
151         std::string _movie_title;
152         int64_t _reel_number;
153         std::string _language;
154         std::list<boost::shared_ptr<LoadFontNode> > _load_font_nodes;
155
156         std::list<boost::shared_ptr<Subtitle> > _subtitles;
157 };
158
159 }