Add line-spacing property to SubtitleContent.
[dcpomatic.git] / src / lib / subtitle_content.h
1 /*
2     Copyright (C) 2013-2016 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 OUTLINE_COLOUR;
45         static int const LINE_SPACING;
46 };
47
48 /** @class SubtitleContent
49  *  @brief Description of how some subtitle content should be presented.
50  *
51  *  There are `image' subtitles (bitmaps) and `text' subtitles (plain text),
52  *  and not all of the settings in this class correspond to both types.
53  */
54 class SubtitleContent : public ContentPart
55 {
56 public:
57         SubtitleContent (Content* parent);
58         SubtitleContent (Content* parent, std::vector<boost::shared_ptr<Content> >);
59
60         void as_xml (xmlpp::Node *) const;
61         std::string identifier () const;
62
63         void add_font (boost::shared_ptr<Font> font);
64
65         void set_use (bool);
66         void set_burn (bool);
67         void set_x_offset (double);
68         void set_y_offset (double);
69         void set_x_scale (double);
70         void set_y_scale (double);
71         void set_language (std::string language);
72
73         bool use () const {
74                 boost::mutex::scoped_lock lm (_mutex);
75                 return _use;
76         }
77
78         bool burn () const {
79                 boost::mutex::scoped_lock lm (_mutex);
80                 return _burn;
81         }
82
83         double x_offset () const {
84                 boost::mutex::scoped_lock lm (_mutex);
85                 return _x_offset;
86         }
87
88         double y_offset () const {
89                 boost::mutex::scoped_lock lm (_mutex);
90                 return _y_offset;
91         }
92
93         double x_scale () const {
94                 boost::mutex::scoped_lock lm (_mutex);
95                 return _x_scale;
96         }
97
98         double y_scale () const {
99                 boost::mutex::scoped_lock lm (_mutex);
100                 return _y_scale;
101         }
102
103         std::list<boost::shared_ptr<Font> > fonts () const {
104                 boost::mutex::scoped_lock lm (_mutex);
105                 return _fonts;
106         }
107
108         std::string language () const {
109                 boost::mutex::scoped_lock lm (_mutex);
110                 return _language;
111         }
112
113         void set_colour (dcp::Colour);
114
115         dcp::Colour colour () const {
116                 boost::mutex::scoped_lock lm (_mutex);
117                 return _colour;
118         }
119
120         void set_outline (bool);
121
122         bool outline () const {
123                 boost::mutex::scoped_lock lm (_mutex);
124                 return _outline;
125         }
126
127         void set_outline_colour (dcp::Colour);
128
129         dcp::Colour outline_colour () const {
130                 boost::mutex::scoped_lock lm (_mutex);
131                 return _outline_colour;
132         }
133
134         void set_line_spacing (double s);
135
136         double line_spacing () const {
137                 boost::mutex::scoped_lock lm (_mutex);
138                 return _line_spacing;
139         }
140
141         static boost::shared_ptr<SubtitleContent> from_xml (Content* parent, cxml::ConstNodePtr, int version);
142
143 protected:
144         /** subtitle language (e.g. "German") or empty if it is not known */
145         std::string _language;
146
147 private:
148         friend struct ffmpeg_pts_offset_test;
149
150         SubtitleContent (Content* parent, cxml::ConstNodePtr, int version);
151         void font_changed ();
152         void connect_to_fonts ();
153
154         bool _use;
155         bool _burn;
156         /** x offset for placing subtitles, as a proportion of the container width;
157          * +ve is further right, -ve is further left.
158          */
159         double _x_offset;
160         /** y offset for placing subtitles, as a proportion of the container height;
161          *  +ve is further down the frame, -ve is further up.
162          */
163         double _y_offset;
164         /** x scale factor to apply to subtitles */
165         double _x_scale;
166         /** y scale factor to apply to subtitles */
167         double _y_scale;
168         std::list<boost::shared_ptr<Font> > _fonts;
169         dcp::Colour _colour;
170         bool _outline;
171         dcp::Colour _outline_colour;
172         std::list<boost::signals2::connection> _font_connections;
173         /** scaling factor for line spacing; 1 is "standard", < 1 is closer together, > 1 is further apart */
174         double _line_spacing;
175 };
176
177 #endif