5b8f9fc7169ed4f11300a37b0fe6e065d46c87df
[dcpomatic.git] / src / lib / subtitle_content.h
1 /*
2     Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef DCPOMATIC_SUBTITLE_CONTENT_H
21 #define DCPOMATIC_SUBTITLE_CONTENT_H
22
23 #include "content_part.h"
24 #include <libcxml/cxml.h>
25 #include <dcp/types.h>
26 #include <boost/signals2.hpp>
27
28 class Font;
29
30 class SubtitleContentProperty
31 {
32 public:
33         static int const X_OFFSET;
34         static int const Y_OFFSET;
35         static int const X_SCALE;
36         static int const Y_SCALE;
37         static int const USE;
38         static int const BURN;
39         static int const LANGUAGE;
40         static int const FONTS;
41         static int const COLOUR;
42         static int const OUTLINE;
43         static int const OUTLINE_COLOUR;
44 };
45
46 class SubtitleContent : public ContentPart
47 {
48 public:
49         SubtitleContent (Content* parent);
50         SubtitleContent (Content* parent, std::vector<boost::shared_ptr<Content> >);
51
52         void as_xml (xmlpp::Node *) const;
53         std::string identifier () const;
54
55         bool has_image_subtitles () const {
56                 /* XXX */
57                 return true;
58         }
59
60         void add_font (boost::shared_ptr<Font> font);
61
62         void set_use (bool);
63         void set_burn (bool);
64         void set_x_offset (double);
65         void set_y_offset (double);
66         void set_x_scale (double);
67         void set_y_scale (double);
68         void set_language (std::string language);
69
70         bool use () const {
71                 boost::mutex::scoped_lock lm (_mutex);
72                 return _use;
73         }
74
75         bool burn () const {
76                 boost::mutex::scoped_lock lm (_mutex);
77                 return _burn;
78         }
79
80         double x_offset () const {
81                 boost::mutex::scoped_lock lm (_mutex);
82                 return _x_offset;
83         }
84
85         double y_offset () const {
86                 boost::mutex::scoped_lock lm (_mutex);
87                 return _y_offset;
88         }
89
90         double x_scale () const {
91                 boost::mutex::scoped_lock lm (_mutex);
92                 return _x_scale;
93         }
94
95         double y_scale () const {
96                 boost::mutex::scoped_lock lm (_mutex);
97                 return _y_scale;
98         }
99
100         std::list<boost::shared_ptr<Font> > fonts () const {
101                 boost::mutex::scoped_lock lm (_mutex);
102                 return _fonts;
103         }
104
105         std::string language () const {
106                 boost::mutex::scoped_lock lm (_mutex);
107                 return _language;
108         }
109
110         void set_colour (dcp::Colour);
111
112         dcp::Colour colour () const {
113                 boost::mutex::scoped_lock lm (_mutex);
114                 return _colour;
115         }
116
117         void set_outline (bool);
118
119         bool outline () const {
120                 boost::mutex::scoped_lock lm (_mutex);
121                 return _outline;
122         }
123
124         void set_outline_colour (dcp::Colour);
125
126         dcp::Colour outline_colour () const {
127                 boost::mutex::scoped_lock lm (_mutex);
128                 return _outline_colour;
129         }
130
131         static boost::shared_ptr<SubtitleContent> from_xml (Content* parent, cxml::ConstNodePtr, int version);
132
133 protected:
134         /** subtitle language (e.g. "German") or empty if it is not known */
135         std::string _language;
136
137 private:
138         friend struct ffmpeg_pts_offset_test;
139
140         SubtitleContent (Content* parent, cxml::ConstNodePtr, int version);
141         void font_changed ();
142         void connect_to_fonts ();
143
144         bool _use;
145         bool _burn;
146         /** x offset for placing subtitles, as a proportion of the container width;
147          * +ve is further right, -ve is further left.
148          */
149         double _x_offset;
150         /** y offset for placing subtitles, as a proportion of the container height;
151          *  +ve is further down the frame, -ve is further up.
152          */
153         double _y_offset;
154         /** x scale factor to apply to subtitles */
155         double _x_scale;
156         /** y scale factor to apply to subtitles */
157         double _y_scale;
158         std::list<boost::shared_ptr<Font> > _fonts;
159         dcp::Colour _colour;
160         bool _outline;
161         dcp::Colour _outline_colour;
162         std::list<boost::signals2::connection> _font_connections;
163 };
164
165 #endif