Add direction support for SMPTE subtitles; fix pragma warnings with non-openmp builds.
[libdcp.git] / src / subtitle_string.h
1 /*
2     Copyright (C) 2012-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 /** @file  src/subtitle_string.h
21  *  @brief SubtitleString class.
22  */
23
24 #ifndef LIBDCP_SUBTITLE_STRING_H
25 #define LIBDCP_SUBTITLE_STRING_H
26
27 #include "types.h"
28 #include "dcp_time.h"
29 #include <boost/optional.hpp>
30 #include <string>
31
32 namespace dcp {
33
34 /** @class SubtitleString
35  *  @brief A single line of subtitle text with all the associated attributes.
36  */
37 class SubtitleString
38 {
39 public:
40         SubtitleString (
41                 boost::optional<std::string> font,
42                 bool italic,
43                 bool bold,
44                 Colour colour,
45                 int size,
46                 float aspect_adjust,
47                 Time in,
48                 Time out,
49                 float h_position,
50                 HAlign h_align,
51                 float v_position,
52                 VAlign v_align,
53                 Direction direction,
54                 std::string text,
55                 Effect effect,
56                 Colour effect_colour,
57                 Time fade_up_time,
58                 Time fade_down_time
59                 );
60
61         /** @return font ID */
62         boost::optional<std::string> font () const {
63                 return _font;
64         }
65
66         bool italic () const {
67                 return _italic;
68         }
69
70         bool bold () const {
71                 return _bold;
72         }
73
74         Colour colour () const {
75                 return _colour;
76         }
77
78         Time in () const {
79                 return _in;
80         }
81
82         Time out () const {
83                 return _out;
84         }
85
86         std::string text () const {
87                 return _text;
88         }
89
90         float h_position () const {
91                 return _h_position;
92         }
93
94         HAlign h_align () const {
95                 return _h_align;
96         }
97
98         /** @return vertical position as a proportion of the screen height from the
99          *  vertical alignment point.
100          *  (between 0 and 1)
101          */
102         float v_position () const {
103                 return _v_position;
104         }
105
106         VAlign v_align () const {
107                 return _v_align;
108         }
109
110         Direction direction () const {
111                 return _direction;
112         }
113
114         Effect effect () const {
115                 return _effect;
116         }
117
118         Colour effect_colour () const {
119                 return _effect_colour;
120         }
121
122         Time fade_up_time () const {
123                 return _fade_up_time;
124         }
125
126         Time fade_down_time () const {
127                 return _fade_down_time;
128         }
129
130         int size () const {
131                 return _size;
132         }
133
134         int size_in_pixels (int screen_height) const;
135
136         /** @return Aspect ratio `adjustment' of the font size.
137          *  Values greater than 1 widen each character, values less than 1 narrow each character,
138          *  and the value must be between 0.25 and 4.
139          */
140         float aspect_adjust () const {
141                 return _aspect_adjust;
142         }
143
144         void set_in (Time i) {
145                 _in = i;
146         }
147
148         void set_out (Time o) {
149                 _out = o;
150         }
151
152         void set_h_position (float p) {
153                 _h_position = p;
154         }
155
156         /** @param p New vertical position as a proportion of the screen height
157          *  from the top (between 0 and 1)
158          */
159         void set_v_position (float p) {
160                 _v_position = p;
161         }
162
163         void set_size (int s) {
164                 _size = s;
165         }
166
167         void set_aspect_adjust (float a) {
168                 _aspect_adjust = a;
169         }
170
171 private:
172         /** font ID */
173         boost::optional<std::string> _font;
174         /** true if the text is italic */
175         bool _italic;
176         /** true if the weight is bold, false for normal */
177         bool _bold;
178         /** text colour */
179         Colour _colour;
180         /** Size in points as if the screen height is 11 inches, so a 72pt font
181          *  would be 1/11th of the screen height.
182          */
183         int _size;
184         float _aspect_adjust;
185         Time _in;
186         Time _out;
187         /** Horizontal position as a proportion of the screen width from the _h_align
188          *  (between 0 and 1)
189          */
190         float _h_position;
191         HAlign _h_align;
192         /** Vertical position as a proportion of the screen height from the _v_align
193          *  (between 0 and 1)
194          */
195         float _v_position;
196         VAlign _v_align;
197         Direction _direction;
198         std::string _text;
199         Effect _effect;
200         Colour _effect_colour;
201         Time _fade_up_time;
202         Time _fade_down_time;
203 };
204
205 bool operator== (SubtitleString const & a, SubtitleString const & b);
206 std::ostream& operator<< (std::ostream& s, SubtitleString const & sub);
207
208 }
209
210 #endif