Fix truncated subtitle output.
[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         float v_position () const {
80                 return _v_position;
81         }
82
83         VAlign v_align () const {
84                 return _v_align;
85         }
86
87         Effect effect () const {
88                 return _effect;
89         }
90
91         Color effect_color () const {
92                 return _effect_color;
93         }
94
95         Time fade_up_time () const {
96                 return _fade_up_time;
97         }
98
99         Time fade_down_time () const {
100                 return _fade_down_time;
101         }
102
103         int size () const {
104                 return _size;
105         }
106         
107         int size_in_pixels (int screen_height) const;
108
109 private:
110         /** font name */
111         std::string _font;
112         /** true if the text is italic */
113         bool _italic;
114         /** text colour */
115         Color _color;
116         /** Size in points as if the screen height is 11 inches, so a 72pt font
117          *  would be 1/11th of the screen height.
118          */ 
119         int _size;
120         Time _in;
121         Time _out;
122         /** Vertical position as a proportion of the screen height from the top
123          *  (between 0 and 1)
124          */
125         float _v_position;
126         VAlign _v_align;
127         std::string _text;
128         Effect _effect;
129         Color _effect_color;
130         Time _fade_up_time;
131         Time _fade_down_time;
132 };
133
134 bool operator== (SubtitleString const & a, SubtitleString const & b);
135 std::ostream& operator<< (std::ostream& s, SubtitleString const & sub);
136
137 }
138
139 #endif