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