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