Bump libcxml for comment-in-node-data fix.
[libdcp.git] / src / subtitle_asset_internal.h
1 /*
2     Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     libdcp is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
18
19     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34 #ifndef LIBDCP_SUBTITLE_ASSET_INTERNAL_H
35 #define LIBDCP_SUBTITLE_ASSET_INTERNAL_H
36
37 #include "raw_convert.h"
38 #include "types.h"
39 #include "dcp_time.h"
40 #include <libxml++/libxml++.h>
41 #include <boost/foreach.hpp>
42
43 struct take_intersection_test;
44 struct take_difference_test;
45 struct pull_fonts_test1;
46 struct pull_fonts_test2;
47 struct pull_fonts_test3;
48
49 namespace dcp {
50
51 class SubtitleString;
52
53 namespace order {
54
55 struct Context
56 {
57         std::string xmlns () const;
58
59         int time_code_rate;
60         Standard standard;
61         int spot_number;
62 };
63
64 class Font
65 {
66 public:
67         Font () {}
68
69         Font (SubtitleString const & s, Standard standard);
70
71         xmlpp::Element* as_xml (xmlpp::Element* parent, Context& context) const;
72
73         void take_intersection (Font other);
74         void take_difference (Font other);
75         bool empty () const;
76         void clear ();
77         bool operator== (Font const & other) const;
78
79 private:
80         friend struct ::take_intersection_test;
81         friend struct ::take_difference_test;
82         friend struct ::pull_fonts_test1;
83         friend struct ::pull_fonts_test2;
84         friend struct ::pull_fonts_test3;
85
86         std::map<std::string, std::string> _values;
87 };
88
89 class Part
90 {
91 public:
92         Part (boost::shared_ptr<Part> parent_)
93                 : parent (parent_)
94         {}
95
96         Part (boost::shared_ptr<Part> parent_, Font font_)
97                 : parent (parent_)
98                 , font (font_)
99         {}
100
101         virtual ~Part () {}
102
103         virtual xmlpp::Element* as_xml (xmlpp::Element* parent, Context &) const;
104         void write_xml (xmlpp::Element* parent, order::Context& context) const;
105
106         boost::shared_ptr<Part> parent;
107         Font font;
108         std::list<boost::shared_ptr<Part> > children;
109 };
110
111 class String : public Part
112 {
113 public:
114         String (boost::shared_ptr<Part> parent, Font font, std::string text_)
115                 : Part (parent, font)
116                 , text (text_)
117         {}
118
119         virtual xmlpp::Element* as_xml (xmlpp::Element* parent, Context &) const;
120
121         std::string text;
122 };
123
124 class Text : public Part
125 {
126 public:
127         Text (boost::shared_ptr<Part> parent, HAlign h_align, float h_position, VAlign v_align, float v_position, Direction direction)
128                 : Part (parent)
129                 , _h_align (h_align)
130                 , _h_position (h_position)
131                 , _v_align (v_align)
132                 , _v_position (v_position)
133                 , _direction (direction)
134         {}
135
136         xmlpp::Element* as_xml (xmlpp::Element* parent, Context& context) const;
137
138 private:
139         HAlign _h_align;
140         float _h_position;
141         VAlign _v_align;
142         float _v_position;
143         Direction _direction;
144 };
145
146 class Subtitle : public Part
147 {
148 public:
149         Subtitle (boost::shared_ptr<Part> parent, Time in, Time out, Time fade_up, Time fade_down)
150                 : Part (parent)
151                 , _in (in)
152                 , _out (out)
153                 , _fade_up (fade_up)
154                 , _fade_down (fade_down)
155         {}
156
157         xmlpp::Element* as_xml (xmlpp::Element* parent, Context& context) const;
158
159 private:
160         Time _in;
161         Time _out;
162         Time _fade_up;
163         Time _fade_down;
164 };
165
166 }
167 }
168
169 #endif