5eda8764ffeaa91ea5c20758fb46c2cad71e1844
[dcpomatic.git] / src / lib / text_content.h
1 /*
2     Copyright (C) 2013-2019 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic 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     DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #ifndef DCPOMATIC_CAPTION_CONTENT_H
22 #define DCPOMATIC_CAPTION_CONTENT_H
23
24 #include "content_part.h"
25 #include "dcp_text_track.h"
26 #include <libcxml/cxml.h>
27 #include <dcp/types.h>
28 #include <boost/signals2.hpp>
29
30 namespace dcpomatic {
31         class Font;
32 }
33
34 class TextContentProperty
35 {
36 public:
37         static int const X_OFFSET;
38         static int const Y_OFFSET;
39         static int const X_SCALE;
40         static int const Y_SCALE;
41         static int const USE;
42         static int const BURN;
43         static int const LANGUAGE;
44         static int const FONTS;
45         static int const COLOUR;
46         static int const EFFECT;
47         static int const EFFECT_COLOUR;
48         static int const LINE_SPACING;
49         static int const FADE_IN;
50         static int const FADE_OUT;
51         static int const OUTLINE_WIDTH;
52         static int const TYPE;
53         static int const DCP_TRACK;
54 };
55
56 /** @class TextContent
57  *  @brief Description of how some text content should be presented.
58  *
59  *  There are `bitmap' subtitles and `plain' subtitles (plain text),
60  *  and not all of the settings in this class correspond to both types.
61  */
62 class TextContent : public ContentPart
63 {
64 public:
65         TextContent (Content* parent, TextType type, TextType original_type);
66         TextContent (Content* parent, std::vector<boost::shared_ptr<Content> >);
67
68         void as_xml (xmlpp::Node *) const;
69         std::string identifier () const;
70         void take_settings_from (boost::shared_ptr<const TextContent> c);
71
72         void add_font (boost::shared_ptr<dcpomatic::Font> font);
73
74         void set_use (bool);
75         void set_burn (bool);
76         void set_x_offset (double);
77         void set_y_offset (double);
78         void set_x_scale (double);
79         void set_y_scale (double);
80         void set_language (std::string language);
81         void set_colour (dcp::Colour);
82         void unset_colour ();
83         void set_effect (dcp::Effect);
84         void unset_effect ();
85         void set_effect_colour (dcp::Colour);
86         void unset_effect_colour ();
87         void set_line_spacing (double s);
88         void set_fade_in (dcpomatic::ContentTime);
89         void unset_fade_in ();
90         void set_fade_out (dcpomatic::ContentTime);
91         void set_outline_width (int);
92         void unset_fade_out ();
93         void set_type (TextType type);
94         void set_dcp_track (DCPTextTrack track);
95         void unset_dcp_track ();
96
97         bool use () const {
98                 boost::mutex::scoped_lock lm (_mutex);
99                 return _use;
100         }
101
102         bool burn () const {
103                 boost::mutex::scoped_lock lm (_mutex);
104                 return _burn;
105         }
106
107         double x_offset () const {
108                 boost::mutex::scoped_lock lm (_mutex);
109                 return _x_offset;
110         }
111
112         double y_offset () const {
113                 boost::mutex::scoped_lock lm (_mutex);
114                 return _y_offset;
115         }
116
117         double x_scale () const {
118                 boost::mutex::scoped_lock lm (_mutex);
119                 return _x_scale;
120         }
121
122         double y_scale () const {
123                 boost::mutex::scoped_lock lm (_mutex);
124                 return _y_scale;
125         }
126
127         std::list<boost::shared_ptr<dcpomatic::Font> > fonts () const {
128                 boost::mutex::scoped_lock lm (_mutex);
129                 return _fonts;
130         }
131
132         std::string language () const {
133                 boost::mutex::scoped_lock lm (_mutex);
134                 return _language;
135         }
136
137         boost::optional<dcp::Colour> colour () const {
138                 boost::mutex::scoped_lock lm (_mutex);
139                 return _colour;
140         }
141
142         boost::optional<dcp::Effect> effect () const {
143                 boost::mutex::scoped_lock lm (_mutex);
144                 return _effect;
145         }
146
147         boost::optional<dcp::Colour> effect_colour () const {
148                 boost::mutex::scoped_lock lm (_mutex);
149                 return _effect_colour;
150         }
151
152         double line_spacing () const {
153                 boost::mutex::scoped_lock lm (_mutex);
154                 return _line_spacing;
155         }
156
157         boost::optional<dcpomatic::ContentTime> fade_in () const {
158                 boost::mutex::scoped_lock lm (_mutex);
159                 return _fade_in;
160         }
161
162         boost::optional<dcpomatic::ContentTime> fade_out () const {
163                 boost::mutex::scoped_lock lm (_mutex);
164                 return _fade_out;
165         }
166
167         int outline_width () const {
168                 boost::mutex::scoped_lock lm (_mutex);
169                 return _outline_width;
170         }
171
172         TextType type () const {
173                 boost::mutex::scoped_lock lm (_mutex);
174                 return _type;
175         }
176
177         TextType original_type () const {
178                 boost::mutex::scoped_lock lm (_mutex);
179                 return _original_type;
180         }
181
182         boost::optional<DCPTextTrack> dcp_track () const {
183                 boost::mutex::scoped_lock lm (_mutex);
184                 return _dcp_track;
185         }
186
187         static std::list<boost::shared_ptr<TextContent> > from_xml (Content* parent, cxml::ConstNodePtr, int version);
188
189 protected:
190         /** subtitle language (e.g. "German") or empty if it is not known */
191         std::string _language;
192
193 private:
194         friend struct ffmpeg_pts_offset_test;
195
196         TextContent (Content* parent, cxml::ConstNodePtr, int version);
197         void font_changed ();
198         void connect_to_fonts ();
199
200         std::list<boost::signals2::connection> _font_connections;
201
202         bool _use;
203         bool _burn;
204         /** x offset for placing subtitles, as a proportion of the container width;
205          * +ve is further right, -ve is further left.
206          */
207         double _x_offset;
208         /** y offset for placing subtitles, as a proportion of the container height;
209          *  +ve is further down the frame, -ve is further up.
210          */
211         double _y_offset;
212         /** x scale factor to apply to subtitles */
213         double _x_scale;
214         /** y scale factor to apply to subtitles */
215         double _y_scale;
216         std::list<boost::shared_ptr<dcpomatic::Font> > _fonts;
217         boost::optional<dcp::Colour> _colour;
218         boost::optional<dcp::Effect> _effect;
219         boost::optional<dcp::Colour> _effect_colour;
220         /** scaling factor for line spacing; 1 is "standard", < 1 is closer together, > 1 is further apart */
221         double _line_spacing;
222         boost::optional<dcpomatic::ContentTime> _fade_in;
223         boost::optional<dcpomatic::ContentTime> _fade_out;
224         int _outline_width;
225         /** what these captions will be used for in the output DCP (not necessarily what
226          *  they were originally).
227          */
228         TextType _type;
229         /** the original type of these captions in their content */
230         TextType _original_type;
231         /** the track of closed captions that this content should be put in, or empty to put in the default (only) track */
232         boost::optional<DCPTextTrack> _dcp_track;
233 };
234
235 #endif