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