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