Use an enum class for Marker.
[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 "subtitle.h"
43 #include "dcp_time.h"
44 #include <boost/optional.hpp>
45 #include <string>
46
47 namespace dcp {
48
49 /** @class SubtitleString
50  *  @brief A single line of subtitle text with all the associated attributes.
51  */
52 class SubtitleString : public Subtitle
53 {
54 public:
55         SubtitleString (
56                 boost::optional<std::string> font,
57                 bool italic,
58                 bool bold,
59                 bool underline,
60                 Colour colour,
61                 int size,
62                 float aspect_adjust,
63                 Time in,
64                 Time out,
65                 float h_position,
66                 HAlign h_align,
67                 float v_position,
68                 VAlign v_align,
69                 Direction direction,
70                 std::string text,
71                 Effect effect,
72                 Colour effect_colour,
73                 Time fade_up_time,
74                 Time fade_down_time
75                 );
76
77         /** @return font ID */
78         boost::optional<std::string> font () const {
79                 return _font;
80         }
81
82         bool italic () const {
83                 return _italic;
84         }
85
86         bool bold () const {
87                 return _bold;
88         }
89
90         bool underline () const {
91                 return _underline;
92         }
93
94         Colour colour () const {
95                 return _colour;
96         }
97
98         std::string text () const {
99                 return _text;
100         }
101
102         Direction direction () const {
103                 return _direction;
104         }
105
106         Effect effect () const {
107                 return _effect;
108         }
109
110         Colour effect_colour () const {
111                 return _effect_colour;
112         }
113
114         int size () const {
115                 return _size;
116         }
117
118         int size_in_pixels (int screen_height) const;
119
120         /** @return Aspect ratio `adjustment' of the font size.
121          *  Values greater than 1 widen each character, values less than 1 narrow each character,
122          *  and the value must be between 0.25 and 4.
123          */
124         float aspect_adjust () const {
125                 return _aspect_adjust;
126         }
127
128         void set_font (std::string id) {
129                 _font = id;
130         }
131
132         void unset_font () {
133                 _font = boost::optional<std::string>();
134         }
135
136         void set_size (int s) {
137                 _size = s;
138         }
139
140         void set_aspect_adjust (float a) {
141                 _aspect_adjust = a;
142         }
143
144         void set_text (std::string t) {
145                 _text = t;
146         }
147
148         void set_colour (Colour c) {
149                 _colour = c;
150         }
151
152         void set_effect (Effect e) {
153                 _effect = e;
154         }
155
156         void set_effect_colour (Colour c) {
157                 _effect_colour = c;
158         }
159
160 private:
161         /** font ID */
162         boost::optional<std::string> _font;
163         /** true if the text is italic */
164         bool _italic;
165         /** true if the weight is bold, false for normal */
166         bool _bold;
167         /** true to enable underlining, false otherwise */
168         bool _underline;
169         /** text colour */
170         Colour _colour;
171         /** Size in points as if the screen height is 11 inches, so a 72pt font
172          *  would be 1/11th of the screen height.
173          */
174         int _size;
175         float _aspect_adjust;
176         Direction _direction;
177         std::string _text;
178         Effect _effect;
179         Colour _effect_colour;
180 };
181
182 bool operator== (SubtitleString const & a, SubtitleString const & b);
183 bool operator!= (SubtitleString const & a, SubtitleString const & b);
184 std::ostream& operator<< (std::ostream& s, SubtitleString const & sub);
185
186 }
187
188 #endif