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