Rename Subtitle -> Text
[dcpomatic.git] / src / lib / text_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 TextContentProperty
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 };
50
51 /** @class TextContent
52  *  @brief Description of how some subtitle content should be presented.
53  *
54  *  There are `image' subtitles (bitmaps) and `text' subtitles (plain text),
55  *  and not all of the settings in this class correspond to both types.
56  */
57 class TextContent : public ContentPart
58 {
59 public:
60         explicit TextContent (Content* parent);
61         TextContent (Content* parent, std::vector<boost::shared_ptr<Content> >);
62
63         void as_xml (xmlpp::Node *) const;
64         std::string identifier () const;
65         void take_settings_from (boost::shared_ptr<const TextContent> 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
89         bool use () const {
90                 boost::mutex::scoped_lock lm (_mutex);
91                 return _use;
92         }
93
94         bool burn () const {
95                 boost::mutex::scoped_lock lm (_mutex);
96                 return _burn;
97         }
98
99         double x_offset () const {
100                 boost::mutex::scoped_lock lm (_mutex);
101                 return _x_offset;
102         }
103
104         double y_offset () const {
105                 boost::mutex::scoped_lock lm (_mutex);
106                 return _y_offset;
107         }
108
109         double x_scale () const {
110                 boost::mutex::scoped_lock lm (_mutex);
111                 return _x_scale;
112         }
113
114         double y_scale () const {
115                 boost::mutex::scoped_lock lm (_mutex);
116                 return _y_scale;
117         }
118
119         std::list<boost::shared_ptr<Font> > fonts () const {
120                 boost::mutex::scoped_lock lm (_mutex);
121                 return _fonts;
122         }
123
124         std::string language () const {
125                 boost::mutex::scoped_lock lm (_mutex);
126                 return _language;
127         }
128
129         boost::optional<dcp::Colour> colour () const {
130                 boost::mutex::scoped_lock lm (_mutex);
131                 return _colour;
132         }
133
134         boost::optional<dcp::Effect> effect () const {
135                 boost::mutex::scoped_lock lm (_mutex);
136                 return _effect;
137         }
138
139         boost::optional<dcp::Colour> effect_colour () const {
140                 boost::mutex::scoped_lock lm (_mutex);
141                 return _effect_colour;
142         }
143
144         double line_spacing () const {
145                 boost::mutex::scoped_lock lm (_mutex);
146                 return _line_spacing;
147         }
148
149         boost::optional<ContentTime> fade_in () const {
150                 boost::mutex::scoped_lock lm (_mutex);
151                 return _fade_in;
152         }
153
154         boost::optional<ContentTime> fade_out () const {
155                 boost::mutex::scoped_lock lm (_mutex);
156                 return _fade_out;
157         }
158
159         int outline_width () const {
160                 boost::mutex::scoped_lock lm (_mutex);
161                 return _outline_width;
162         }
163
164         static boost::shared_ptr<TextContent> from_xml (Content* parent, cxml::ConstNodePtr, int version);
165
166 protected:
167         /** subtitle language (e.g. "German") or empty if it is not known */
168         std::string _language;
169
170 private:
171         friend struct ffmpeg_pts_offset_test;
172
173         TextContent (Content* parent, cxml::ConstNodePtr, int version);
174         void font_changed ();
175         void connect_to_fonts ();
176
177         std::list<boost::signals2::connection> _font_connections;
178
179         bool _use;
180         bool _burn;
181         /** x offset for placing subtitles, as a proportion of the container width;
182          * +ve is further right, -ve is further left.
183          */
184         double _x_offset;
185         /** y offset for placing subtitles, as a proportion of the container height;
186          *  +ve is further down the frame, -ve is further up.
187          */
188         double _y_offset;
189         /** x scale factor to apply to subtitles */
190         double _x_scale;
191         /** y scale factor to apply to subtitles */
192         double _y_scale;
193         std::list<boost::shared_ptr<Font> > _fonts;
194         boost::optional<dcp::Colour> _colour;
195         boost::optional<dcp::Effect> _effect;
196         boost::optional<dcp::Colour> _effect_colour;
197         /** scaling factor for line spacing; 1 is "standard", < 1 is closer together, > 1 is further apart */
198         double _line_spacing;
199         boost::optional<ContentTime> _fade_in;
200         boost::optional<ContentTime> _fade_out;
201         int _outline_width;
202 };
203
204 #endif