2 Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 #ifndef DCPOMATIC_CAPTION_CONTENT_H
23 #define DCPOMATIC_CAPTION_CONTENT_H
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>
38 class TextContentProperty
41 static int const X_OFFSET;
42 static int const Y_OFFSET;
43 static int const X_SCALE;
44 static int const Y_SCALE;
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;
62 /** @class TextContent
63 * @brief Description of how some text content should be presented.
65 * There are `bitmap' subtitles and `plain' subtitles (plain text),
66 * and not all of the settings in this class correspond to both types.
68 class TextContent : public ContentPart
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);
75 void as_xml (xmlpp::Node *) const;
76 std::string identifier () const;
77 void take_settings_from (std::shared_ptr<const TextContent> c);
80 void add_font (std::shared_ptr<dcpomatic::Font> font);
81 std::shared_ptr<dcpomatic::Font> get_font(std::string id) const;
85 void set_x_offset (double);
86 void set_y_offset (double);
87 void set_x_scale (double);
88 void set_y_scale (double);
89 void set_colour (dcp::Colour);
91 void set_effect (dcp::Effect);
93 void set_effect_colour (dcp::Colour);
94 void unset_effect_colour ();
95 void set_line_spacing (double s);
96 void set_fade_in (dcpomatic::ContentTime);
97 void unset_fade_in ();
98 void set_fade_out (dcpomatic::ContentTime);
99 void set_outline_width (int);
100 void unset_fade_out ();
101 void set_type (TextType type);
102 void set_dcp_track (DCPTextTrack track);
103 void unset_dcp_track ();
104 void set_language (boost::optional<dcp::LanguageTag> language = boost::none);
105 void set_language_is_additional (bool additional);
108 boost::mutex::scoped_lock lm (_mutex);
113 boost::mutex::scoped_lock lm (_mutex);
117 double x_offset () const {
118 boost::mutex::scoped_lock lm (_mutex);
122 double y_offset () const {
123 boost::mutex::scoped_lock lm (_mutex);
127 double x_scale () const {
128 boost::mutex::scoped_lock lm (_mutex);
132 double y_scale () const {
133 boost::mutex::scoped_lock lm (_mutex);
137 std::list<std::shared_ptr<dcpomatic::Font>> fonts () const {
138 boost::mutex::scoped_lock lm (_mutex);
142 boost::optional<dcp::Colour> colour () const {
143 boost::mutex::scoped_lock lm (_mutex);
147 boost::optional<dcp::Effect> effect () const {
148 boost::mutex::scoped_lock lm (_mutex);
152 boost::optional<dcp::Colour> effect_colour () const {
153 boost::mutex::scoped_lock lm (_mutex);
154 return _effect_colour;
157 double line_spacing () const {
158 boost::mutex::scoped_lock lm (_mutex);
159 return _line_spacing;
162 boost::optional<dcpomatic::ContentTime> fade_in () const {
163 boost::mutex::scoped_lock lm (_mutex);
167 boost::optional<dcpomatic::ContentTime> fade_out () const {
168 boost::mutex::scoped_lock lm (_mutex);
172 int outline_width () const {
173 boost::mutex::scoped_lock lm (_mutex);
174 return _outline_width;
177 TextType type () const {
178 boost::mutex::scoped_lock lm (_mutex);
182 TextType original_type () const {
183 boost::mutex::scoped_lock lm (_mutex);
184 return _original_type;
187 boost::optional<DCPTextTrack> dcp_track () const {
188 boost::mutex::scoped_lock lm (_mutex);
192 boost::optional<dcp::LanguageTag> language () const {
193 boost::mutex::scoped_lock lm (_mutex);
197 bool language_is_additional () const {
198 boost::mutex::scoped_lock lm (_mutex);
199 return _language_is_additional;
202 static std::list<std::shared_ptr<TextContent>> from_xml (Content* parent, cxml::ConstNodePtr, int version, std::list<std::string>& notes);
205 friend struct ffmpeg_pts_offset_test;
207 void font_changed ();
208 void connect_to_fonts ();
209 std::shared_ptr<dcpomatic::Font> get_font_unlocked(std::string id) const;
211 std::list<boost::signals2::connection> _font_connections;
215 /** x offset for placing subtitles, as a proportion of the container width;
216 * +ve is further right, -ve is further left.
219 /** y offset for placing subtitles, as a proportion of the container height;
220 * +ve is further down the frame, -ve is further up.
223 /** x scale factor to apply to subtitles */
225 /** y scale factor to apply to subtitles */
227 std::list<std::shared_ptr<dcpomatic::Font>> _fonts;
228 boost::optional<dcp::Colour> _colour;
229 boost::optional<dcp::Effect> _effect;
230 boost::optional<dcp::Colour> _effect_colour;
231 /** scaling factor for line spacing; 1 is "standard", < 1 is closer together, > 1 is further apart */
232 double _line_spacing;
233 boost::optional<dcpomatic::ContentTime> _fade_in;
234 boost::optional<dcpomatic::ContentTime> _fade_out;
236 /** what these captions will be used for in the output DCP (not necessarily what
237 * they were originally).
240 /** the original type of these captions in their content */
241 TextType _original_type;
242 /** the track of closed captions that this content should be put in, or empty to put in the default (only) track */
243 boost::optional<DCPTextTrack> _dcp_track;
244 boost::optional<dcp::LanguageTag> _language;
245 bool _language_is_additional = false;