Subtitle rearrangements.
[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 SUBTITLE_X_OFFSET;
34         static int const SUBTITLE_Y_OFFSET;
35         static int const SUBTITLE_X_SCALE;
36         static int const SUBTITLE_Y_SCALE;
37         static int const USE_SUBTITLES;
38         static int const BURN_SUBTITLES;
39         static int const SUBTITLE_LANGUAGE;
40         static int const FONTS;
41         static int const SUBTITLE_VIDEO_FRAME_RATE;
42         static int const SUBTITLE_COLOUR;
43         static int const SUBTITLE_OUTLINE;
44         static int const SUBTITLE_OUTLINE_COLOUR;
45 };
46
47 class SubtitleContent : public ContentPart
48 {
49 public:
50         SubtitleContent (Content* parent, boost::shared_ptr<const Film>);
51         SubtitleContent (Content* parent, boost::shared_ptr<const Film>, cxml::ConstNodePtr, int version);
52         SubtitleContent (Content* parent, boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
53
54         void as_xml (xmlpp::Node *) const;
55         std::string identifier () const;
56
57         bool has_image_subtitles () const {
58                 /* XXX */
59                 return true;
60         }
61
62         void add_font (boost::shared_ptr<Font> font);
63
64         void set_use_subtitles (bool);
65         void set_burn_subtitles (bool);
66         void set_subtitle_x_offset (double);
67         void set_subtitle_y_offset (double);
68         void set_subtitle_x_scale (double);
69         void set_subtitle_y_scale (double);
70         void set_subtitle_language (std::string language);
71
72         bool use_subtitles () const {
73                 boost::mutex::scoped_lock lm (_mutex);
74                 return _use_subtitles;
75         }
76
77         bool burn_subtitles () const {
78                 boost::mutex::scoped_lock lm (_mutex);
79                 return _burn_subtitles;
80         }
81
82         double subtitle_x_offset () const {
83                 boost::mutex::scoped_lock lm (_mutex);
84                 return _subtitle_x_offset;
85         }
86
87         double subtitle_y_offset () const {
88                 boost::mutex::scoped_lock lm (_mutex);
89                 return _subtitle_y_offset;
90         }
91
92         double subtitle_x_scale () const {
93                 boost::mutex::scoped_lock lm (_mutex);
94                 return _subtitle_x_scale;
95         }
96
97         double subtitle_y_scale () const {
98                 boost::mutex::scoped_lock lm (_mutex);
99                 return _subtitle_y_scale;
100         }
101
102         std::list<boost::shared_ptr<Font> > fonts () const {
103                 boost::mutex::scoped_lock lm (_mutex);
104                 return _fonts;
105         }
106
107         std::string subtitle_language () const {
108                 boost::mutex::scoped_lock lm (_mutex);
109                 return _subtitle_language;
110         }
111
112         void set_colour (dcp::Colour);
113
114         dcp::Colour colour () const {
115                 boost::mutex::scoped_lock lm (_mutex);
116                 return _colour;
117         }
118
119         void set_outline (bool);
120
121         bool outline () const {
122                 boost::mutex::scoped_lock lm (_mutex);
123                 return _outline;
124         }
125
126         void set_outline_colour (dcp::Colour);
127
128         dcp::Colour outline_colour () const {
129                 boost::mutex::scoped_lock lm (_mutex);
130                 return _outline_colour;
131         }
132
133 protected:
134         /** subtitle language (e.g. "German") or empty if it is not known */
135         std::string _subtitle_language;
136
137 private:
138         friend struct ffmpeg_pts_offset_test;
139         void font_changed ();
140         void connect_to_fonts ();
141
142         bool _use_subtitles;
143         bool _burn_subtitles;
144         /** x offset for placing subtitles, as a proportion of the container width;
145          * +ve is further right, -ve is further left.
146          */
147         double _subtitle_x_offset;
148         /** y offset for placing subtitles, as a proportion of the container height;
149          *  +ve is further down the frame, -ve is further up.
150          */
151         double _subtitle_y_offset;
152         /** x scale factor to apply to subtitles */
153         double _subtitle_x_scale;
154         /** y scale factor to apply to subtitles */
155         double _subtitle_y_scale;
156         std::list<boost::shared_ptr<Font> > _fonts;
157         dcp::Colour _colour;
158         bool _outline;
159         dcp::Colour _outline_colour;
160         std::list<boost::signals2::connection> _font_connections;
161 };
162
163 #endif