Rename ReelMXF -> ReelFileAsset.
[libdcp.git] / src / subtitle_string.h
1 /*
2     Copyright (C) 2012-2021 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
35 /** @file  src/subtitle_string.h
36  *  @brief SubtitleString class
37  */
38
39
40 #ifndef LIBDCP_SUBTITLE_STRING_H
41 #define LIBDCP_SUBTITLE_STRING_H
42
43
44 #include "types.h"
45 #include "subtitle.h"
46 #include "dcp_time.h"
47 #include <boost/optional.hpp>
48 #include <string>
49
50
51 namespace dcp {
52
53
54 /** @class SubtitleString
55  *  @brief A single line of subtitle text with all the associated attributes.
56  */
57 class SubtitleString : public Subtitle
58 {
59 public:
60         /** @param font Font ID, or empty to use the default
61          *  @param italic true for italic text
62          *  @param bold true for bold text
63          *  @param underline true for underlined text
64          *  @param colour Colour of the text
65          *  @param size Size in points as if the screen height is 11 inches, so a 72pt font would be 1/11th of the screen height
66          *  @param aspect_adjust greater than 1 to stretch text to be wider, less than 1 to shrink text to be narrower (must be between 0.25 and 4)
67          *  @param in start time
68          *  @param out finish time
69          *  @param h_position Horizontal position as a fraction of the screen width (between 0 and 1) from h_align
70          *  @param h_align Horizontal alignment point
71          *  @param v_position Vertical position as a fraction of the screen height (between 0 and 1) from v_align
72          *  @param v_align Vertical alignment point
73          *  @param direction Direction of text
74          *  @param text The text to display
75          *  @param effect Effect to use
76          *  @param effect_colour Colour of the effect
77          *  @param fade_up_time Time to fade the text in
78          *  @param fade_down_time Time to fade the text out
79          */
80         SubtitleString (
81                 boost::optional<std::string> font,
82                 bool italic,
83                 bool bold,
84                 bool underline,
85                 Colour colour,
86                 int size,
87                 float aspect_adjust,
88                 Time in,
89                 Time out,
90                 float h_position,
91                 HAlign h_align,
92                 float v_position,
93                 VAlign v_align,
94                 Direction direction,
95                 std::string text,
96                 Effect effect,
97                 Colour effect_colour,
98                 Time fade_up_time,
99                 Time fade_down_time
100                 );
101
102         /** @return font ID */
103         boost::optional<std::string> font () const {
104                 return _font;
105         }
106
107         bool italic () const {
108                 return _italic;
109         }
110
111         bool bold () const {
112                 return _bold;
113         }
114
115         bool underline () const {
116                 return _underline;
117         }
118
119         Colour colour () const {
120                 return _colour;
121         }
122
123         std::string text () const {
124                 return _text;
125         }
126
127         Direction direction () const {
128                 return _direction;
129         }
130
131         Effect effect () const {
132                 return _effect;
133         }
134
135         Colour effect_colour () const {
136                 return _effect_colour;
137         }
138
139         int size () const {
140                 return _size;
141         }
142
143         int size_in_pixels (int screen_height) const;
144
145         /** @return Aspect ratio `adjustment' of the font size.
146          *  Values greater than 1 widen each character, values less than 1 narrow each character,
147          *  and the value must be between 0.25 and 4.
148          */
149         float aspect_adjust () const {
150                 return _aspect_adjust;
151         }
152
153         void set_font (std::string id) {
154                 _font = id;
155         }
156
157         void unset_font () {
158                 _font = boost::optional<std::string>();
159         }
160
161         void set_size (int s) {
162                 _size = s;
163         }
164
165         void set_aspect_adjust (float a) {
166                 _aspect_adjust = a;
167         }
168
169         void set_text (std::string t) {
170                 _text = t;
171         }
172
173         void set_colour (Colour c) {
174                 _colour = c;
175         }
176
177         void set_effect (Effect e) {
178                 _effect = e;
179         }
180
181         void set_effect_colour (Colour c) {
182                 _effect_colour = c;
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         /** true to enable underlining, false otherwise */
193         bool _underline;
194         /** text colour */
195         Colour _colour;
196         /** Size in points as if the screen height is 11 inches, so a 72pt font
197          *  would be 1/11th of the screen height.
198          */
199         int _size;
200         float _aspect_adjust;
201         Direction _direction;
202         std::string _text;
203         Effect _effect;
204         Colour _effect_colour;
205 };
206
207 bool operator== (SubtitleString const & a, SubtitleString const & b);
208 bool operator!= (SubtitleString const & a, SubtitleString const & b);
209 std::ostream& operator<< (std::ostream& s, SubtitleString const & sub);
210
211
212 }
213
214
215 #endif