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