Make EqualityOptions into a class.
[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 "compose.hpp"
41 #include "subtitle.h"
42 #include "dcp_time.h"
43
44
45 using std::shared_ptr;
46 using namespace dcp;
47
48
49 /** @param v_position Vertical position as a fraction of the screen height (between 0 and 1) from v_align */
50 Subtitle::Subtitle (
51         Time in,
52         Time out,
53         float h_position,
54         HAlign h_align,
55         float v_position,
56         VAlign v_align,
57         float z_position,
58         Time fade_up_time,
59         Time fade_down_time
60         )
61         : _in (in)
62         , _out (out)
63         , _h_position (h_position)
64         , _h_align (h_align)
65         , _v_position (v_position)
66         , _v_align (v_align)
67         , _z_position(z_position)
68         , _fade_up_time (fade_up_time)
69         , _fade_down_time (fade_down_time)
70 {
71
72 }
73
74
75 bool
76 Subtitle::equals(shared_ptr<const Subtitle> other, EqualityOptions options, NoteHandler note) const
77 {
78         bool same = true;
79
80         if (in() != other->in()) {
81                 note(NoteType::ERROR, "subtitle in times differ");
82                 same = false;
83         }
84
85         if (out() != other->out()) {
86                 note(NoteType::ERROR, "subtitle out times differ");
87                 same = false;
88         }
89
90         if (h_position() != other->h_position()) {
91                 note(NoteType::ERROR, "subtitle horizontal positions differ");
92                 same = false;
93         }
94
95         if (h_align() != other->h_align()) {
96                 note(NoteType::ERROR, "subtitle horizontal alignments differ");
97                 same = false;
98         }
99
100         auto const vpos = std::abs(v_position() - other->v_position());
101         if (vpos > options.max_subtitle_vertical_position_error)  {
102                 note(
103                         NoteType::ERROR,
104                         String::compose("subtitle vertical positions differ by %1 (more than the allowed difference of %2)", vpos, options.max_subtitle_vertical_position_error)
105                     );
106                 same = false;
107         }
108
109         if (v_align() != other->v_align()) {
110                 note(NoteType::ERROR, "subtitle vertical alignments differ");
111                 same = false;
112         }
113
114         if (z_position() != other->z_position()) {
115                 note(NoteType::ERROR, "subtitle Z positions differ");
116                 same = false;
117         }
118
119         if (fade_up_time() != other->fade_up_time()) {
120                 note(NoteType::ERROR, "subtitle fade-up times differ");
121                 same = false;
122         }
123
124         if (fade_down_time() != other->fade_down_time()) {
125                 note(NoteType::ERROR, "subtitle fade-down times differ");
126                 same = false;
127         }
128
129         return same;
130 }