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