Add OpenSSL licence exception.
[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                 Colour colour,
59                 int size,
60                 float aspect_adjust,
61                 Time in,
62                 Time out,
63                 float h_position,
64                 HAlign h_align,
65                 float v_position,
66                 VAlign v_align,
67                 Direction direction,
68                 std::string text,
69                 Effect effect,
70                 Colour effect_colour,
71                 Time fade_up_time,
72                 Time fade_down_time
73                 );
74
75         /** @return font ID */
76         boost::optional<std::string> font () const {
77                 return _font;
78         }
79
80         bool italic () const {
81                 return _italic;
82         }
83
84         bool bold () const {
85                 return _bold;
86         }
87
88         Colour colour () const {
89                 return _colour;
90         }
91
92         Time in () const {
93                 return _in;
94         }
95
96         Time out () const {
97                 return _out;
98         }
99
100         std::string text () const {
101                 return _text;
102         }
103
104         float h_position () const {
105                 return _h_position;
106         }
107
108         HAlign h_align () const {
109                 return _h_align;
110         }
111
112         /** @return vertical position as a proportion of the screen height from the
113          *  vertical alignment point.
114          *  (between 0 and 1)
115          */
116         float v_position () const {
117                 return _v_position;
118         }
119
120         VAlign v_align () const {
121                 return _v_align;
122         }
123
124         Direction direction () const {
125                 return _direction;
126         }
127
128         Effect effect () const {
129                 return _effect;
130         }
131
132         Colour effect_colour () const {
133                 return _effect_colour;
134         }
135
136         Time fade_up_time () const {
137                 return _fade_up_time;
138         }
139
140         Time fade_down_time () const {
141                 return _fade_down_time;
142         }
143
144         int size () const {
145                 return _size;
146         }
147
148         int size_in_pixels (int screen_height) const;
149
150         /** @return Aspect ratio `adjustment' of the font size.
151          *  Values greater than 1 widen each character, values less than 1 narrow each character,
152          *  and the value must be between 0.25 and 4.
153          */
154         float aspect_adjust () const {
155                 return _aspect_adjust;
156         }
157
158         void set_in (Time i) {
159                 _in = i;
160         }
161
162         void set_out (Time o) {
163                 _out = o;
164         }
165
166         void set_h_position (float p) {
167                 _h_position = p;
168         }
169
170         /** @param p New vertical position as a proportion of the screen height
171          *  from the top (between 0 and 1)
172          */
173         void set_v_position (float p) {
174                 _v_position = p;
175         }
176
177         void set_size (int s) {
178                 _size = s;
179         }
180
181         void set_aspect_adjust (float a) {
182                 _aspect_adjust = a;
183         }
184
185 private:
186         /** font ID */
187         boost::optional<std::string> _font;
188         /** true if the text is italic */
189         bool _italic;
190         /** true if the weight is bold, false for normal */
191         bool _bold;
192         /** text colour */
193         Colour _colour;
194         /** Size in points as if the screen height is 11 inches, so a 72pt font
195          *  would be 1/11th of the screen height.
196          */
197         int _size;
198         float _aspect_adjust;
199         Time _in;
200         Time _out;
201         /** Horizontal position as a proportion of the screen width from the _h_align
202          *  (between 0 and 1)
203          */
204         float _h_position;
205         HAlign _h_align;
206         /** Vertical position as a proportion of the screen height from the _v_align
207          *  (between 0 and 1)
208          */
209         float _v_position;
210         VAlign _v_align;
211         Direction _direction;
212         std::string _text;
213         Effect _effect;
214         Colour _effect_colour;
215         Time _fade_up_time;
216         Time _fade_down_time;
217 };
218
219 bool operator== (SubtitleString const & a, SubtitleString const & b);
220 std::ostream& operator<< (std::ostream& s, SubtitleString const & sub);
221
222 }
223
224 #endif