47e4fed15593880473817fa6d5c1d25af51a6124
[libdcp.git] / src / subtitle_string.h
1 /*
2     Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp 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     libdcp 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 libdcp.  If not, see <http://www.gnu.org/licenses/>.
18
19     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34 /** @file  src/subtitle_string.h
35  *  @brief SubtitleString class.
36  */
37
38 #ifndef LIBDCP_SUBTITLE_STRING_H
39 #define LIBDCP_SUBTITLE_STRING_H
40
41 #include "types.h"
42 #include "dcp_time.h"
43 #include <boost/optional.hpp>
44 #include <string>
45
46 namespace dcp {
47
48 /** @class SubtitleString
49  *  @brief A single line of subtitle text with all the associated attributes.
50  */
51 class SubtitleString
52 {
53 public:
54         SubtitleString (
55                 boost::optional<std::string> font,
56                 bool italic,
57                 bool bold,
58                 bool underline,
59                 Colour colour,
60                 int size,
61                 float aspect_adjust,
62                 Time in,
63                 Time out,
64                 float h_position,
65                 HAlign h_align,
66                 float v_position,
67                 VAlign v_align,
68                 Direction direction,
69                 std::string text,
70                 Effect effect,
71                 Colour effect_colour,
72                 Time fade_up_time,
73                 Time fade_down_time
74                 );
75
76         /** @return font ID */
77         boost::optional<std::string> font () const {
78                 return _font;
79         }
80
81         bool italic () const {
82                 return _italic;
83         }
84
85         bool bold () const {
86                 return _bold;
87         }
88
89         bool underline () const {
90                 return _underline;
91         }
92
93         Colour colour () const {
94                 return _colour;
95         }
96
97         Time in () const {
98                 return _in;
99         }
100
101         Time out () const {
102                 return _out;
103         }
104
105         std::string text () const {
106                 return _text;
107         }
108
109         float h_position () const {
110                 return _h_position;
111         }
112
113         HAlign h_align () const {
114                 return _h_align;
115         }
116
117         /** @return vertical position as a proportion of the screen height from the
118          *  vertical alignment point.
119          *  (between 0 and 1)
120          */
121         float v_position () const {
122                 return _v_position;
123         }
124
125         VAlign v_align () const {
126                 return _v_align;
127         }
128
129         Direction direction () const {
130                 return _direction;
131         }
132
133         Effect effect () const {
134                 return _effect;
135         }
136
137         Colour effect_colour () const {
138                 return _effect_colour;
139         }
140
141         Time fade_up_time () const {
142                 return _fade_up_time;
143         }
144
145         Time fade_down_time () const {
146                 return _fade_down_time;
147         }
148
149         int size () const {
150                 return _size;
151         }
152
153         int size_in_pixels (int screen_height) const;
154
155         /** @return Aspect ratio `adjustment' of the font size.
156          *  Values greater than 1 widen each character, values less than 1 narrow each character,
157          *  and the value must be between 0.25 and 4.
158          */
159         float aspect_adjust () const {
160                 return _aspect_adjust;
161         }
162
163         void set_in (Time i) {
164                 _in = i;
165         }
166
167         void set_out (Time o) {
168                 _out = o;
169         }
170
171         void set_h_position (float p) {
172                 _h_position = p;
173         }
174
175         /** @param p New vertical position as a proportion of the screen height
176          *  from the top (between 0 and 1)
177          */
178         void set_v_position (float p) {
179                 _v_position = p;
180         }
181
182         void set_size (int s) {
183                 _size = s;
184         }
185
186         void set_aspect_adjust (float a) {
187                 _aspect_adjust = a;
188         }
189
190         void set_text (std::string t) {
191                 _text = t;
192         }
193
194         void set_colour (dcp::Colour c) {
195                 _colour = c;
196         }
197
198         void set_effect (Effect e) {
199                 _effect = e;
200         }
201
202         void set_effect_colour (dcp::Colour c) {
203                 _effect_colour = c;
204         }
205
206         void set_fade_up_time (dcp::Time t) {
207                 _fade_up_time = t;
208         }
209
210         void set_fade_down_time (dcp::Time t) {
211                 _fade_down_time = t;
212         }
213
214 private:
215         /** font ID */
216         boost::optional<std::string> _font;
217         /** true if the text is italic */
218         bool _italic;
219         /** true if the weight is bold, false for normal */
220         bool _bold;
221         /** true to enable underlining, false otherwise */
222         bool _underline;
223         /** text colour */
224         Colour _colour;
225         /** Size in points as if the screen height is 11 inches, so a 72pt font
226          *  would be 1/11th of the screen height.
227          */
228         int _size;
229         float _aspect_adjust;
230         Time _in;
231         Time _out;
232         /** Horizontal position as a proportion of the screen width from the _h_align
233          *  (between 0 and 1)
234          */
235         float _h_position;
236         HAlign _h_align;
237         /** Vertical position as a proportion of the screen height from the _v_align
238          *  (between 0 and 1)
239          */
240         float _v_position;
241         VAlign _v_align;
242         Direction _direction;
243         std::string _text;
244         Effect _effect;
245         Colour _effect_colour;
246         Time _fade_up_time;
247         Time _fade_down_time;
248 };
249
250 bool operator== (SubtitleString const & a, SubtitleString const & b);
251 std::ostream& operator<< (std::ostream& s, SubtitleString const & sub);
252
253 }
254
255 #endif