Note whether subtitle colour is forced or not.
[dcpomatic.git] / src / lib / subtitle_content.h
1 /*
2     Copyright (C) 2013-2018 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_SUBTITLE_CONTENT_H
22 #define DCPOMATIC_SUBTITLE_CONTENT_H
23
24 #include "content_part.h"
25 #include <libcxml/cxml.h>
26 #include <dcp/types.h>
27 #include <boost/signals2.hpp>
28
29 class Font;
30
31 class SubtitleContentProperty
32 {
33 public:
34         static int const X_OFFSET;
35         static int const Y_OFFSET;
36         static int const X_SCALE;
37         static int const Y_SCALE;
38         static int const USE;
39         static int const BURN;
40         static int const LANGUAGE;
41         static int const FONTS;
42         static int const COLOUR;
43         static int const OUTLINE;
44         static int const SHADOW;
45         static int const EFFECT_COLOUR;
46         static int const LINE_SPACING;
47         static int const FADE_IN;
48         static int const FADE_OUT;
49         static int const OUTLINE_WIDTH;
50 };
51
52 /** @class SubtitleContent
53  *  @brief Description of how some subtitle content should be presented.
54  *
55  *  There are `image' subtitles (bitmaps) and `text' subtitles (plain text),
56  *  and not all of the settings in this class correspond to both types.
57  */
58 class SubtitleContent : public ContentPart
59 {
60 public:
61         SubtitleContent (Content* parent);
62         SubtitleContent (Content* parent, std::vector<boost::shared_ptr<Content> >);
63
64         void as_xml (xmlpp::Node *) const;
65         std::string identifier () const;
66         void take_settings_from (boost::shared_ptr<const SubtitleContent> c);
67
68         void add_font (boost::shared_ptr<Font> font);
69
70         void set_use (bool);
71         void set_burn (bool);
72         void set_x_offset (double);
73         void set_y_offset (double);
74         void set_x_scale (double);
75         void set_y_scale (double);
76         void set_language (std::string language);
77         void set_colour (dcp::Colour);
78         void unset_colour ();
79         void set_outline (bool);
80         void set_shadow (bool);
81         void set_effect_colour (dcp::Colour);
82         void set_line_spacing (double s);
83         void set_fade_in (ContentTime);
84         void set_fade_out (ContentTime);
85         void set_outline_width (int);
86
87         bool use () const {
88                 boost::mutex::scoped_lock lm (_mutex);
89                 return _use;
90         }
91
92         bool burn () const {
93                 boost::mutex::scoped_lock lm (_mutex);
94                 return _burn;
95         }
96
97         double x_offset () const {
98                 boost::mutex::scoped_lock lm (_mutex);
99                 return _x_offset;
100         }
101
102         double y_offset () const {
103                 boost::mutex::scoped_lock lm (_mutex);
104                 return _y_offset;
105         }
106
107         double x_scale () const {
108                 boost::mutex::scoped_lock lm (_mutex);
109                 return _x_scale;
110         }
111
112         double y_scale () const {
113                 boost::mutex::scoped_lock lm (_mutex);
114                 return _y_scale;
115         }
116
117         std::list<boost::shared_ptr<Font> > fonts () const {
118                 boost::mutex::scoped_lock lm (_mutex);
119                 return _fonts;
120         }
121
122         std::string language () const {
123                 boost::mutex::scoped_lock lm (_mutex);
124                 return _language;
125         }
126
127         boost::optional<dcp::Colour> colour () const {
128                 boost::mutex::scoped_lock lm (_mutex);
129                 return _colour;
130         }
131
132         bool outline () const {
133                 boost::mutex::scoped_lock lm (_mutex);
134                 return _outline;
135         }
136
137         bool shadow () const {
138                 boost::mutex::scoped_lock lm (_mutex);
139                 return _shadow;
140         }
141
142         dcp::Colour effect_colour () const {
143                 boost::mutex::scoped_lock lm (_mutex);
144                 return _effect_colour;
145         }
146
147         double line_spacing () const {
148                 boost::mutex::scoped_lock lm (_mutex);
149                 return _line_spacing;
150         }
151
152         ContentTime fade_in () const {
153                 boost::mutex::scoped_lock lm (_mutex);
154                 return _fade_in;
155         }
156
157         ContentTime fade_out () const {
158                 boost::mutex::scoped_lock lm (_mutex);
159                 return _fade_out;
160         }
161
162         int outline_width () const {
163                 boost::mutex::scoped_lock lm (_mutex);
164                 return _outline_width;
165         }
166
167         static boost::shared_ptr<SubtitleContent> from_xml (Content* parent, cxml::ConstNodePtr, int version);
168
169 protected:
170         /** subtitle language (e.g. "German") or empty if it is not known */
171         std::string _language;
172
173 private:
174         friend struct ffmpeg_pts_offset_test;
175
176         SubtitleContent (Content* parent, cxml::ConstNodePtr, int version);
177         void font_changed ();
178         void connect_to_fonts ();
179
180         std::list<boost::signals2::connection> _font_connections;
181
182         bool _use;
183         bool _burn;
184         /** x offset for placing subtitles, as a proportion of the container width;
185          * +ve is further right, -ve is further left.
186          */
187         double _x_offset;
188         /** y offset for placing subtitles, as a proportion of the container height;
189          *  +ve is further down the frame, -ve is further up.
190          */
191         double _y_offset;
192         /** x scale factor to apply to subtitles */
193         double _x_scale;
194         /** y scale factor to apply to subtitles */
195         double _y_scale;
196         std::list<boost::shared_ptr<Font> > _fonts;
197         boost::optional<dcp::Colour> _colour;
198         bool _outline;
199         bool _shadow;
200         dcp::Colour _effect_colour;
201         /** scaling factor for line spacing; 1 is "standard", < 1 is closer together, > 1 is further apart */
202         double _line_spacing;
203         ContentTime _fade_in;
204         ContentTime _fade_out;
205         int _outline_width;
206 };
207
208 #endif