libdcp
subtitle_asset_internal.h
Go to the documentation of this file.
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 
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, float space_before)
131  : Part (parent, font)
132  , _text (text)
133  , _space_before (space_before)
134  {}
135 
136  virtual xmlpp::Element* as_xml (xmlpp::Element* parent, Context &) const override;
137 
138 private:
139  std::string _text;
140  float _space_before;
141 };
142 
143 
144 class Text : public Part
145 {
146 public:
147  Text (std::shared_ptr<Part> parent, HAlign h_align, float h_position, VAlign v_align, float v_position, Direction direction)
148  : Part (parent)
149  , _h_align (h_align)
150  , _h_position (h_position)
151  , _v_align (v_align)
152  , _v_position (v_position)
153  , _direction (direction)
154  {}
155 
156  xmlpp::Element* as_xml (xmlpp::Element* parent, Context& context) const override;
157 
158 private:
159  HAlign _h_align;
160  float _h_position;
161  VAlign _v_align;
162  float _v_position;
163  Direction _direction;
164 };
165 
166 
167 class Subtitle : public Part
168 {
169 public:
170  Subtitle (std::shared_ptr<Part> parent, Time in, Time out, Time fade_up, Time fade_down)
171  : Part (parent)
172  , _in (in)
173  , _out (out)
174  , _fade_up (fade_up)
175  , _fade_down (fade_down)
176  {}
177 
178  xmlpp::Element* as_xml (xmlpp::Element* parent, Context& context) const override;
179 
180 private:
181  Time _in;
182  Time _out;
183  Time _fade_up;
184  Time _fade_down;
185 };
186 
187 
188 class Image : public Part
189 {
190 public:
191  Image (std::shared_ptr<Part> parent, std::string id, ArrayData png_data, HAlign h_align, float h_position, VAlign v_align, float v_position)
192  : Part (parent)
193  , _png_data (png_data)
194  , _id (id)
195  , _h_align (h_align)
196  , _h_position (h_position)
197  , _v_align (v_align)
198  , _v_position (v_position)
199  {}
200 
201  xmlpp::Element* as_xml (xmlpp::Element* parent, Context& context) const override;
202 
203 private:
204  ArrayData _png_data;
205  std::string _id;
206  HAlign _h_align;
207  float _h_position;
208  VAlign _v_align;
209  float _v_position;
210 };
211 
212 
213 }
214 }
215 
216 
217 #endif
ArrayData class.
Class to hold an arbitrary block of data.
Definition: array_data.h:55
A representation of time within a DCP.
Definition: dcp_time.h:73
void take_difference(Font other)
void take_intersection(Font other)
std::string _id
the ID of this image
Time class.
Namespace for everything in libdcp.
Definition: array_data.h:50
Direction
Definition: types.h:191
HAlign
Definition: types.h:166
VAlign
Definition: types.h:178
Methods for conversion to/from string.
Miscellaneous types.