Rename color -> colour.
[libdcp.git] / src / subtitle_string.cc
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 #include "subtitle_string.h"
21 #include "xml.h"
22
23 using std::string;
24 using std::ostream;
25 using boost::optional;
26 using namespace dcp;
27
28 SubtitleString::SubtitleString (
29         optional<string> font,
30         bool italic,
31         Colour colour,
32         int size,
33         Time in,
34         Time out,
35         float v_position,
36         VAlign v_align,
37         string text,
38         Effect effect,
39         Colour effect_colour,
40         Time fade_up_time,
41         Time fade_down_time
42         )
43         : _font (font)
44         , _italic (italic)
45         , _colour (colour)
46         , _size (size)
47         , _in (in)
48         , _out (out)
49         , _v_position (v_position)
50         , _v_align (v_align)
51         , _text (text)
52         , _effect (effect)
53         , _effect_colour (effect_colour)
54         , _fade_up_time (fade_up_time)
55         , _fade_down_time (fade_down_time)
56 {
57
58 }
59
60 int
61 SubtitleString::size_in_pixels (int screen_height) const
62 {
63         /* Size in the subtitle file is given in points as if the screen
64            height is 11 inches, so a 72pt font would be 1/11th of the screen
65            height.
66         */
67         
68         return _size * screen_height / (11 * 72);
69 }
70
71 bool
72 dcp::operator== (SubtitleString const & a, SubtitleString const & b)
73 {
74         return (
75                 a.font() == b.font() &&
76                 a.italic() == b.italic() &&
77                 a.colour() == b.colour() &&
78                 a.size() == b.size() &&
79                 a.in() == b.in() &&
80                 a.out() == b.out() &&
81                 a.v_position() == b.v_position() &&
82                 a.v_align() == b.v_align() &&
83                 a.text() == b.text() &&
84                 a.effect() == b.effect() &&
85                 a.effect_colour() == b.effect_colour() &&
86                 a.fade_up_time() == b.fade_up_time() &&
87                 a.fade_down_time() == b.fade_down_time()
88                 );
89 }
90
91 ostream&
92 dcp::operator<< (ostream& s, SubtitleString const & sub)
93 {
94         s << "\n`" << sub.text() << "' from " << sub.in() << " to " << sub.out() << ";\n"
95           << "fade up " << sub.fade_up_time() << ", fade down " << sub.fade_down_time() << ";\n"
96           << "font " << sub.font().get_value_or ("[default]") << ", ";
97
98         if (sub.italic()) {
99                 s << "italic";
100         } else {
101                 s << "non-italic";
102         }
103         
104         s << ", size " << sub.size() << ", colour " << sub.colour() << ", vpos " << sub.v_position() << ", valign " << ((int) sub.v_align()) << ";\n"
105           << "effect " << ((int) sub.effect()) << ", effect colour " << sub.effect_colour();
106
107         return s;
108 }