Add set_size to SubtitleString.
[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 <string>
30
31 namespace dcp {
32
33 /** @class SubtitleString
34  *  @brief A single line of subtitle text with all the associated attributes.
35  */
36 class SubtitleString
37 {
38 public:
39         SubtitleString (
40                 std::string font,
41                 bool italic,
42                 Color color,
43                 int size,
44                 Time in,
45                 Time out,
46                 float v_position,
47                 VAlign v_align,
48                 std::string text,
49                 Effect effect,
50                 Color effect_color,
51                 Time fade_up_time,
52                 Time fade_down_time
53                 );
54
55         std::string font () const {
56                 return _font;
57         }
58
59         bool italic () const {
60                 return _italic;
61         }
62
63         Color color () const {
64                 return _color;
65         }
66
67         Time in () const {
68                 return _in;
69         }
70
71         Time out () const {
72                 return _out;
73         }
74
75         std::string text () const {
76                 return _text;
77         }
78
79         /** @return vertical position as a proportion of the screen height from the top
80          *  (between 0 and 1)
81          */
82         float v_position () const {
83                 return _v_position;
84         }
85
86         VAlign v_align () const {
87                 return _v_align;
88         }
89
90         Effect effect () const {
91                 return _effect;
92         }
93
94         Color effect_color () const {
95                 return _effect_color;
96         }
97
98         Time fade_up_time () const {
99                 return _fade_up_time;
100         }
101
102         Time fade_down_time () const {
103                 return _fade_down_time;
104         }
105
106         int size () const {
107                 return _size;
108         }
109         
110         int size_in_pixels (int screen_height) const;
111
112         /** @param p New vertical position as a proportion of the screen height
113          *  from the top (between 0 and 1)
114          */
115         void set_v_position (float p) {
116                 _v_position = p;
117         }
118
119         void set_size (int s) {
120                 _size = s;
121         }
122
123 private:
124         /** font name */
125         std::string _font;
126         /** true if the text is italic */
127         bool _italic;
128         /** text colour */
129         Color _color;
130         /** Size in points as if the screen height is 11 inches, so a 72pt font
131          *  would be 1/11th of the screen height.
132          */ 
133         int _size;
134         Time _in;
135         Time _out;
136         /** Vertical position as a proportion of the screen height from the top
137          *  (between 0 and 1)
138          */
139         float _v_position;
140         VAlign _v_align;
141         std::string _text;
142         Effect _effect;
143         Color _effect_color;
144         Time _fade_up_time;
145         Time _fade_down_time;
146 };
147
148 bool operator== (SubtitleString const & a, SubtitleString const & b);
149 std::ostream& operator<< (std::ostream& s, SubtitleString const & sub);
150
151 }
152
153 #endif