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