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