Switch to UUIDs for Interop image subtitle identification (rather than indices)....
[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 "data.h"
41 #include <libxml++/libxml++.h>
42 #include <boost/foreach.hpp>
43
44 struct take_intersection_test;
45 struct take_difference_test;
46 struct pull_fonts_test1;
47 struct pull_fonts_test2;
48 struct pull_fonts_test3;
49
50 namespace dcp {
51
52 class SubtitleString;
53
54 namespace order {
55
56 struct Context
57 {
58         std::string xmlns () const;
59
60         int time_code_rate;
61         Standard standard;
62         int spot_number;
63 };
64
65 class Font
66 {
67 public:
68         Font () {}
69
70         Font (boost::shared_ptr<SubtitleString> s, Standard standard);
71
72         xmlpp::Element* as_xml (xmlpp::Element* parent, Context& context) const;
73
74         void take_intersection (Font other);
75         void take_difference (Font other);
76         bool empty () const;
77         void clear ();
78         bool operator== (Font const & other) const;
79
80 private:
81         friend struct ::take_intersection_test;
82         friend struct ::take_difference_test;
83         friend struct ::pull_fonts_test1;
84         friend struct ::pull_fonts_test2;
85         friend struct ::pull_fonts_test3;
86
87         std::map<std::string, std::string> _values;
88 };
89
90 class Part
91 {
92 public:
93         Part (boost::shared_ptr<Part> parent_)
94                 : parent (parent_)
95         {}
96
97         Part (boost::shared_ptr<Part> parent_, Font font_)
98                 : parent (parent_)
99                 , font (font_)
100         {}
101
102         virtual ~Part () {}
103
104         virtual xmlpp::Element* as_xml (xmlpp::Element* parent, Context &) const;
105         void write_xml (xmlpp::Element* parent, order::Context& context) const;
106
107         boost::shared_ptr<Part> parent;
108         Font font;
109         std::list<boost::shared_ptr<Part> > children;
110 };
111
112 class String : public Part
113 {
114 public:
115         String (boost::shared_ptr<Part> parent, Font font, std::string text_)
116                 : Part (parent, font)
117                 , text (text_)
118         {}
119
120         virtual xmlpp::Element* as_xml (xmlpp::Element* parent, Context &) const;
121
122         std::string text;
123 };
124
125 class Text : public Part
126 {
127 public:
128         Text (boost::shared_ptr<Part> parent, HAlign h_align, float h_position, VAlign v_align, float v_position, Direction direction)
129                 : Part (parent)
130                 , _h_align (h_align)
131                 , _h_position (h_position)
132                 , _v_align (v_align)
133                 , _v_position (v_position)
134                 , _direction (direction)
135         {}
136
137         xmlpp::Element* as_xml (xmlpp::Element* parent, Context& context) const;
138
139 private:
140         HAlign _h_align;
141         float _h_position;
142         VAlign _v_align;
143         float _v_position;
144         Direction _direction;
145 };
146
147 class Subtitle : public Part
148 {
149 public:
150         Subtitle (boost::shared_ptr<Part> parent, Time in, Time out, Time fade_up, Time fade_down)
151                 : Part (parent)
152                 , _in (in)
153                 , _out (out)
154                 , _fade_up (fade_up)
155                 , _fade_down (fade_down)
156         {}
157
158         xmlpp::Element* as_xml (xmlpp::Element* parent, Context& context) const;
159
160 private:
161         Time _in;
162         Time _out;
163         Time _fade_up;
164         Time _fade_down;
165 };
166
167 class Image : public Part
168 {
169 public:
170         Image (boost::shared_ptr<Part> parent, std::string id, Data png_data, HAlign h_align, float h_position, VAlign v_align, float v_position)
171                 : Part (parent)
172                 , _png_data (png_data)
173                 , _id (id)
174                 , _h_align (h_align)
175                 , _h_position (h_position)
176                 , _v_align (v_align)
177                 , _v_position (v_position)
178         {}
179
180         xmlpp::Element* as_xml (xmlpp::Element* parent, Context& context) const;
181
182 private:
183         Data _png_data;
184         std::string _id; ///< the ID of this image (index for Interop, UUID for SMPTE)
185         HAlign _h_align;
186         float _h_position;
187         VAlign _v_align;
188         float _v_position;
189 };
190
191 }
192
193 }
194
195 #endif