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