bb76839787f1d99ee75c748f84952f606a096112
[libdcp.git] / src / subtitle_string.h
1 /*
2     Copyright (C) 2012-2015 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                 Colour colour,
44                 int size,
45                 float aspect_adjust,
46                 Time in,
47                 Time out,
48                 float h_position,
49                 HAlign h_align,
50                 float v_position,
51                 VAlign v_align,
52                 std::string text,
53                 Effect effect,
54                 Colour effect_colour,
55                 Time fade_up_time,
56                 Time fade_down_time
57                 );
58
59         /** @return font ID */
60         boost::optional<std::string> font () const {
61                 return _font;
62         }
63
64         bool italic () const {
65                 return _italic;
66         }
67
68         Colour colour () const {
69                 return _colour;
70         }
71
72         Time in () const {
73                 return _in;
74         }
75
76         Time out () const {
77                 return _out;
78         }
79
80         std::string text () const {
81                 return _text;
82         }
83
84         float h_position () const {
85                 return _h_position;
86         }
87
88         HAlign h_align () const {
89                 return _h_align;
90         }
91
92         /** @return vertical position as a proportion of the screen height from the top
93          *  (between 0 and 1)
94          */
95         float v_position () const {
96                 return _v_position;
97         }
98
99         VAlign v_align () const {
100                 return _v_align;
101         }
102
103         Effect effect () const {
104                 return _effect;
105         }
106
107         Colour effect_colour () const {
108                 return _effect_colour;
109         }
110
111         Time fade_up_time () const {
112                 return _fade_up_time;
113         }
114
115         Time fade_down_time () const {
116                 return _fade_down_time;
117         }
118
119         int size () const {
120                 return _size;
121         }
122
123         int size_in_pixels (int screen_height) const;
124
125         /** @return Aspect ratio `adjustment' of the font size.
126          *  Values greater than 1 widen each character, values less than 1 narrow each character,
127          *  and the value must be between 0.25 and 4.
128          */
129         float aspect_adjust () const {
130                 return _aspect_adjust;
131         }
132
133         /** @param p New vertical position as a proportion of the screen height
134          *  from the top (between 0 and 1)
135          */
136         void set_v_position (float p) {
137                 _v_position = p;
138         }
139
140         void set_size (int s) {
141                 _size = s;
142         }
143
144         void set_aspect_adjust (float a) {
145                 _aspect_adjust = a;
146         }
147
148 private:
149         /** font ID */
150         boost::optional<std::string> _font;
151         /** true if the text is italic */
152         bool _italic;
153         /** text colour */
154         Colour _colour;
155         /** Size in points as if the screen height is 11 inches, so a 72pt font
156          *  would be 1/11th of the screen height.
157          */ 
158         int _size;
159         float _aspect_adjust;
160         Time _in;
161         Time _out;
162         /** Horizontal position as a proportion of the screen width from the _h_align
163          *  (between 0 and 1)
164          */
165         float _h_position;
166         HAlign _h_align;
167         /** Vertical position as a proportion of the screen height from the _v_align
168          *  (between 0 and 1)
169          */
170         float _v_position;
171         VAlign _v_align;
172         std::string _text;
173         Effect _effect;
174         Colour _effect_colour;
175         Time _fade_up_time;
176         Time _fade_down_time;
177 };
178
179 bool operator== (SubtitleString const & a, SubtitleString const & b);
180 std::ostream& operator<< (std::ostream& s, SubtitleString const & sub);
181
182 }
183
184 #endif