Merge branch '1.0' of git.carlh.net:git/libdcp into 1.0
[libdcp.git] / src / subtitle_string.h
1 /*
2     Copyright (C) 2012-2014 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                 Time in,
46                 Time out,
47                 float v_position,
48                 VAlign v_align,
49                 std::string text,
50                 Effect effect,
51                 Colour effect_colour,
52                 Time fade_up_time,
53                 Time fade_down_time
54                 );
55
56         /** @return font ID */
57         boost::optional<std::string> font () const {
58                 return _font;
59         }
60
61         bool italic () const {
62                 return _italic;
63         }
64
65         Colour colour () const {
66                 return _colour;
67         }
68
69         Time in () const {
70                 return _in;
71         }
72
73         Time out () const {
74                 return _out;
75         }
76
77         std::string text () const {
78                 return _text;
79         }
80
81         /** @return vertical position as a proportion of the screen height from the top
82          *  (between 0 and 1)
83          */
84         float v_position () const {
85                 return _v_position;
86         }
87
88         VAlign v_align () const {
89                 return _v_align;
90         }
91
92         Effect effect () const {
93                 return _effect;
94         }
95
96         Colour effect_colour () const {
97                 return _effect_colour;
98         }
99
100         Time fade_up_time () const {
101                 return _fade_up_time;
102         }
103
104         Time fade_down_time () const {
105                 return _fade_down_time;
106         }
107
108         int size () const {
109                 return _size;
110         }
111         
112         int size_in_pixels (int screen_height) const;
113
114         /** @param p New vertical position as a proportion of the screen height
115          *  from the top (between 0 and 1)
116          */
117         void set_v_position (float p) {
118                 _v_position = p;
119         }
120
121         void set_size (int s) {
122                 _size = s;
123         }
124
125 private:
126         /** font ID */
127         boost::optional<std::string> _font;
128         /** true if the text is italic */
129         bool _italic;
130         /** text colour */
131         Colour _colour;
132         /** Size in points as if the screen height is 11 inches, so a 72pt font
133          *  would be 1/11th of the screen height.
134          */ 
135         int _size;
136         Time _in;
137         Time _out;
138         /** Vertical position as a proportion of the screen height from the top
139          *  (between 0 and 1)
140          */
141         float _v_position;
142         VAlign _v_align;
143         std::string _text;
144         Effect _effect;
145         Colour _effect_colour;
146         Time _fade_up_time;
147         Time _fade_down_time;
148 };
149
150 bool operator== (SubtitleString const & a, SubtitleString const & b);
151 std::ostream& operator<< (std::ostream& s, SubtitleString const & sub);
152
153 }
154
155 #endif