Recurse into font nodes and pick up details of italics.
[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
54         std::string id;
55         int size;
56         boost::optional<bool> italic;
57         
58         std::list<boost::shared_ptr<SubtitleNode> > subtitle_nodes;
59         std::list<boost::shared_ptr<FontNode> > font_nodes;
60 };
61
62 class LoadFontNode : public XMLNode
63 {
64 public:
65         LoadFontNode () {}
66         LoadFontNode (xmlpp::Node const * node);
67
68         std::string id;
69         std::string uri;
70 };
71
72 class Subtitle
73 {
74 public:
75         Subtitle (
76                 std::string font,
77                 bool italic,
78                 int size,
79                 Time in,
80                 Time out,
81                 float v_position,
82                 std::string text
83                 );
84
85         std::string font () const {
86                 return _font;
87         }
88
89         bool italic () const {
90                 return _italic;
91         }
92
93         Time in () const {
94                 return _in;
95         }
96
97         Time out () const {
98                 return _out;
99         }
100
101         std::string text () const {
102                 return _text;
103         }
104
105         float v_position () const {
106                 return _v_position;
107         }
108
109         int size_in_pixels (int screen_height) const;
110
111 private:
112         std::string _font;
113         bool _italic;
114         int _size;
115         Time _in;
116         Time _out;
117         float _v_position;
118         std::string _text;
119 };
120
121 class SubtitleAsset : public Asset, public XMLFile
122 {
123 public:
124         SubtitleAsset (std::string directory, std::string xml);
125
126         void write_to_cpl (std::ostream&) const {}
127         virtual std::list<std::string> equals (boost::shared_ptr<const Asset>, EqualityOptions) const {
128                 /* XXX */
129                 return std::list<std::string> ();
130         }
131
132         std::string language () const {
133                 return _language;
134         }
135
136         std::list<boost::shared_ptr<Subtitle> > subtitles_at (Time t) const;
137
138 private:
139         std::string font_id_to_name (std::string id) const;
140         void examine_font_node (boost::shared_ptr<FontNode> font_node, std::list<boost::shared_ptr<FontNode> >& current_font_nodes);
141         std::string id_from_font_nodes (std::list<boost::shared_ptr<FontNode> > const & font_nodes) const;
142         int size_from_font_nodes (std::list<boost::shared_ptr<FontNode> > const & font_nodes) const;
143         bool italic_from_font_nodes (std::list<boost::shared_ptr<FontNode> > const & font_nodes) const;
144         
145         std::string _subtitle_id;
146         std::string _movie_title;
147         int64_t _reel_number;
148         std::string _language;
149         std::list<boost::shared_ptr<LoadFontNode> > _load_font_nodes;
150
151         std::list<boost::shared_ptr<Subtitle> > _subtitles;
152 };
153
154 }