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