Better subtitle comparisons in tests.
[libdcp.git] / src / subtitle.cc
1 /*
2     Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     libdcp is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
18
19     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34
35 /** @file  src/subtitle.cc
36  *  @brief Subtitle class
37  */
38
39
40 #include "subtitle.h"
41 #include "dcp_time.h"
42
43
44 using std::shared_ptr;
45 using namespace dcp;
46
47
48 /** @param v_position Vertical position as a fraction of the screen height (between 0 and 1) from v_align */
49 Subtitle::Subtitle (
50         Time in,
51         Time out,
52         float h_position,
53         HAlign h_align,
54         float v_position,
55         VAlign v_align,
56         Time fade_up_time,
57         Time fade_down_time
58         )
59         : _in (in)
60         , _out (out)
61         , _h_position (h_position)
62         , _h_align (h_align)
63         , _v_position (v_position)
64         , _v_align (v_align)
65         , _fade_up_time (fade_up_time)
66         , _fade_down_time (fade_down_time)
67 {
68
69 }
70
71
72 bool
73 Subtitle::equals(shared_ptr<const Subtitle> other, EqualityOptions, NoteHandler note) const
74 {
75         bool same = true;
76
77         if (in() != other->in()) {
78                 note(NoteType::ERROR, "subtitle in times differ");
79                 same = false;
80         }
81
82         if (out() != other->out()) {
83                 note(NoteType::ERROR, "subtitle out times differ");
84                 same = false;
85         }
86
87         if (h_position() != other->h_position()) {
88                 note(NoteType::ERROR, "subtitle horizontal positions differ");
89                 same = false;
90         }
91
92         if (h_align() != other->h_align()) {
93                 note(NoteType::ERROR, "subtitle horizontal alignments differ");
94                 same = false;
95         }
96
97         if (v_position() != other->v_position()) {
98                 note(NoteType::ERROR, "subtitle vertical positions differ");
99                 same = false;
100         }
101
102         if (v_align() != other->v_align()) {
103                 note(NoteType::ERROR, "subtitle vertical alignments differ");
104                 same = false;
105         }
106
107         if (fade_up_time() != other->fade_up_time()) {
108                 note(NoteType::ERROR, "subtitle fade-up times differ");
109                 same = false;
110         }
111
112         if (fade_down_time() != other->fade_down_time()) {
113                 note(NoteType::ERROR, "subtitle fade-down times differ");
114                 same = false;
115         }
116
117         return same;
118 }